Conversation
… handler TracingServerInterceptor in grpc-1.5 and armeria-grpc-0.84 used the deprecated AgentPropagation.extractContextAndGetSpanContext, which drops every extracted element except the span context, and then ran startCall, close and the listener callbacks under a span-only activateSpan(span). Inbound W3C baggage was tagged on the server span but was not current in the service implementation, so Baggage was missing from Context.current() and outbound calls did not re-inject it. Extract the full context with the default propagator and attach parentContext.with(span), mirroring HttpServerDecorator. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
StartContextPropagationAdvice injected only the active span, so W3C baggage in the current context never reached outbound grpc-java calls. Inject currentContext() instead, as the armeria-grpc client already does, keeping the existing guard that skips injection without an active span. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Does This Do
Makes the full extracted context, including W3C
baggage, current for the whole gRPC server call in bothgrpc-1.5andarmeria-grpc-0.84. Also makes thegrpc-1.5client inject the full current context.grpc-1.5,armeria-grpc-0.84):TracingServerInterceptorextracts withPropagators.defaultPropagator().extract(root(), headers, GETTER)in place of the deprecatedAgentPropagation.extractContextAndGetSpanContext. It starts thegrpc.serverspan from the extracted span context as before, then runsstartCall,ServerCall.closeand every listener callback (onMessage,onHalfClose,onCancel,onComplete,onReady) underparentContext.with(span).attach()instead of the span-onlyactivateSpan(span).onMessageattachescontext.with(msgSpan), so thegrpc.messagespan stays the active span. Scopes are still closed by the same try-with-resources blocks.grpc-1.5):StartContextPropagationAdviceinjectscurrentContext()instead of only the active span. It keeps the existing "no active span, no injection" guard. This matches what thearmeria-grpcclient already does.Motivation
Solves #12654.
Today both server instrumentations extract inbound
baggage(it shows up asbaggage.*tags on the server span) but make only the span current. As a result:Baggageis missing from the current context in the service implementation (emptyBaggage.current()through the OTel bridge).baggage.HTTP server instrumentations have used full-context extraction since #8820 (
HttpServerDecorator.extract/startSpanreturnsparentContext.with(span)), so this follows that pattern.The
grpc-1.5client change is needed for the "outbound calls carrybaggage" half of the issue when the downstream call is itself a grpc-java call. Without it, the server fix alone makes baggage current in the handler, butClientCallImplInstrumentationinjects onlyactiveSpan(), so thebaggageheader is still dropped.Additional Notes
Tests: each module's
GrpcTest/ArmeriaGrpcTestgets a new case. A client sendsbaggage: user.id=abc123,jtbd=checkout. The test asserts that the handler sees those items inBaggage.fromContext(Context.current()), and that a downstream gRPC call made from the handler (to an inbound-ignored method, whose raw headers are captured by aServerInterceptor) carries the samebaggageheader.Local results (JDK 21, macOS arm64):
With the server change reverted, the new test fails in both modules at the handler assertion (
Baggageisnull). With thegrpc-1.5client change reverted, thegrpc-1.5test fails at the downstream-header assertion.Behaviour note:
Context.attach()replaces the current context, whereasactivateSpan(span)merges the span into whatever context is already active on the thread. This is the same trade-off the HTTP server instrumentations already make. The extracted context is now the root for the call.Other callers of the deprecated helper listed in the issue (sofarpc, messaging consumers, API shims) are out of scope here.
Suggested labels for maintainers (as a fork contributor I can't set labels):
tag: ai generated,inst: grpc,type: bug fix,comp: context propagation.Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issueJira ticket: [PROJ-IDENT]
🤖 Generated with Claude Code