Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #3402]"getExtension()" can return null.[Trace] #3632

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

Expand Down Expand Up @@ -111,7 +112,17 @@ public Span addTraceInfoToSpan(ChannelHandlerContext ctx, CloudEvent cloudEvent)
}
Context context = ctx.channel().attr(AttributeKeys.SERVER_CONTEXT).get();
Span span = context != null ? context.get(SpanKey.SERVER_KEY) : null;
return addTraceInfoToSpan(span, cloudEvent);

if (span == null) {
log.warn("span is null when finishSpan");
return null;
}

//add trace info
for (String entry : cloudEvent.getExtensionNames()) {
span.setAttribute(entry, cloudEvent.getExtension(entry) == null ? "" : Objects.requireNonNull(cloudEvent.getExtension(entry)).toString());
}
return span;
Comment on lines 114 to +125
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to inline the addTraceInfoToSpan method here? I think it is enough to add a requireNonNull method in the "add trace info" step of addTraceInfoToSpan method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is enough to add a requireNonNull method in the "add trace info" step of addTraceInfoToSpan method.

I found that your current suggestion contradicts your previous one (#3632 (comment)). So, why you now think it's needed to add an extra requireNonNull to addTraceInfoToSpan method?

Copy link
Member

@Pil0tXia Pil0tXia Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pandaapo Excuse me for overlooking some folded context earlier. I initially intended to point out that the addTraceInfoToSpan method should not be inlined here. However, it appears that further review is unnecessary as the issue corresponding to this PR is invalid. I will close the issue and label this PR as invalid.

@harshithasudhakar Thank you very much for your contribution. Please feel free to select other valuable issues to work on.

}

public Span addTraceInfoToSpan(Span span, CloudEvent cloudEvent) {
Expand All @@ -130,7 +141,7 @@ public Span addTraceInfoToSpan(Span span, CloudEvent cloudEvent) {

// add trace info
for (String entry : cloudEvent.getExtensionNames()) {
span.setAttribute(entry, cloudEvent.getExtension(entry) == null ? "" : cloudEvent.getExtension(entry).toString());
span.setAttribute(entry, cloudEvent.getExtension(entry) != null ? cloudEvent.getExtension(entry).toString() : "");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now you see there is no problem with the original code here. The other one is in the same situation.
In conclusion, this issue should not be posted. So let's wait the maintainer to make the final decision.

return span;
}
Expand Down
Loading