-
Notifications
You must be signed in to change notification settings - Fork 4k
baggage propagation #12389
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
baggage propagation #12389
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| import static com.google.common.base.Preconditions.checkNotNull; | ||
| import static io.grpc.ClientStreamTracer.NAME_RESOLUTION_DELAYED; | ||
| import static io.grpc.internal.GrpcUtil.IMPLEMENTATION_VERSION; | ||
| import static io.grpc.opentelemetry.internal.OpenTelemetryConstants.BAGGAGE_KEY; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import io.grpc.Attributes; | ||
|
|
@@ -60,10 +61,6 @@ final class OpenTelemetryTracingModule { | |
| @VisibleForTesting | ||
| final io.grpc.Context.Key<Span> otelSpan = io.grpc.Context.key("opentelemetry-span-key"); | ||
|
|
||
| @VisibleForTesting | ||
| final io.grpc.Context.Key<Baggage> baggageKey = | ||
| io.grpc.Context.key("opentelemetry-baggage-key"); | ||
|
|
||
| @Nullable | ||
| private static final AtomicIntegerFieldUpdater<CallAttemptsTracerFactory> callEndedUpdater; | ||
| @Nullable | ||
|
|
@@ -248,13 +245,15 @@ private final class ServerTracer extends ServerStreamTracer { | |
| private final Span span; | ||
| volatile int streamClosed; | ||
| private int seqNo; | ||
| private Baggage baggage; | ||
|
|
||
| ServerTracer(String fullMethodName, @Nullable Span remoteSpan) { | ||
| ServerTracer(String fullMethodName, @Nullable Span remoteSpan, Baggage baggage) { | ||
| checkNotNull(fullMethodName, "fullMethodName"); | ||
| this.span = | ||
| otelTracer.spanBuilder(generateTraceSpanName(true, fullMethodName)) | ||
| .setParent(remoteSpan == null ? null : Context.current().with(remoteSpan)) | ||
| .startSpan(); | ||
| this.baggage = baggage; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -280,7 +279,9 @@ public void streamClosed(io.grpc.Status status) { | |
|
|
||
| @Override | ||
| public io.grpc.Context filterContext(io.grpc.Context context) { | ||
| return context.withValue(otelSpan, span); | ||
| return context | ||
| .withValue(otelSpan, span) | ||
| .withValue(BAGGAGE_KEY, baggage); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -320,7 +321,8 @@ public ServerStreamTracer newServerStreamTracer(String fullMethodName, Metadata | |
| if (remoteSpan == Span.getInvalid()) { | ||
| remoteSpan = null; | ||
| } | ||
| return new ServerTracer(fullMethodName, remoteSpan); | ||
| Baggage baggage = Baggage.fromContext(context); | ||
| return new ServerTracer(fullMethodName, remoteSpan, baggage); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -335,9 +337,12 @@ public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, Re | |
| + "tracing must be set."); | ||
| return next.startCall(call, headers); | ||
| } | ||
| Context serverCallContext = Context.current().with(span); | ||
| Baggage baggage = baggageKey.get(io.grpc.Context.current()); | ||
| serverCallContext = serverCallContext.with(baggage); | ||
| Context serverCallContext = Context.current(); | ||
| serverCallContext = serverCallContext.with(span); | ||
| Baggage baggage = BAGGAGE_KEY.get(io.grpc.Context.current()); | ||
| if (baggage != null) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How can this be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it was never set...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How could it be never set?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not present in the header...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, so we are getting it from the grpc context which uses and can return null
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it is added unconditionally to the context earlier, so it shouldn't be missing. If it is missing, that seems like a bug, and something we'd want to know about. Seems we should do something, other than ignore it. |
||
| serverCallContext = serverCallContext.with(baggage); | ||
| } | ||
| try (Scope scope = serverCallContext.makeCurrent()) { | ||
| return new ContextServerCallListener<>(next.startCall(call, headers), serverCallContext); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.