GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Propagate inbound W3C baggage through gRPC server handlers by sy-lee · Pull Request #12721 · DataDog/dd-trace-java

Conversation

@sy-lee

@sy-lee sy-lee commented Oct 1, 2026

Copy link
Copy Markdown

What Does This Do

Makes the full extracted context, including W3C baggage, current for the whole gRPC server call in both grpc-1.5 and armeria-grpc-0.84. Also makes the grpc-1.5 client inject the full current context.

  • Server (grpc-1.5, armeria-grpc-0.84): TracingServerInterceptor extracts with Propagators.defaultPropagator().extract(root(), headers, GETTER) in place of the deprecated AgentPropagation.extractContextAndGetSpanContext. It starts the grpc.server span from the extracted span context as before, then runs startCall, ServerCall.close and every listener callback (onMessage, onHalfClose, onCancel, onComplete, onReady) under parentContext.with(span).attach() instead of the span-only activateSpan(span). onMessage attaches context.with(msgSpan), so the grpc.message span stays the active span. Scopes are still closed by the same try-with-resources blocks.
  • Client (grpc-1.5): StartContextPropagationAdvice injects currentContext() instead of only the active span. It keeps the existing "no active span, no injection" guard. This matches what the armeria-grpc client already does.

Motivation

Solves #12654.

Today both server instrumentations extract inbound baggage (it shows up as baggage.* tags on the server span) but make only the span current. As a result:

  • Baggage is missing from the current context in the service implementation (empty Baggage.current() through the OTel bridge).
  • Calls made from the handler don't re-inject baggage.

HTTP server instrumentations have used full-context extraction since #8820 (HttpServerDecorator.extract / startSpan returns parentContext.with(span)), so this follows that pattern.

The grpc-1.5 client change is needed for the "outbound calls carry baggage" 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, but ClientCallImplInstrumentation injects only activeSpan(), so the baggage header is still dropped.

Additional Notes

Tests: each module's GrpcTest / ArmeriaGrpcTest gets a new case. A client sends baggage: user.id=abc123,jtbd=checkout. The test asserts that the handler sees those items in Baggage.fromContext(Context.current()), and that a downstream gRPC call made from the handler (to an inbound-ignored method, whose raw headers are captured by a ServerInterceptor) carries the same baggage header.

Local results (JDK 21, macOS arm64):

armeria-grpc-0.84  test 61/61, forkedTest 50/50, latestDepTest 61/61, latestDepForkedTest 50/50
grpc-1.5           test 121/121, forkedTest 71/71, latestDepTest 121/121

With the server change reverted, the new test fails in both modules at the handler assertion (Baggage is null). With the grpc-1.5 client change reverted, the grpc-1.5 test fails at the downstream-header assertion.

Behaviour note: Context.attach() replaces the current context, whereas activateSpan(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

  • Format the title according to the contribution guidelines
  • Assign the type: and (comp: or inst:) labels in addition to any other useful labels
  • Avoid using close, fix, or any linking keywords when referencing an issue
    Use solves instead, and assign the PR milestone to the issue
  • Update the CODEOWNERS file on source file addition, migration, or deletion
  • Update public documentation with any new configuration flags or behaviors
  • Once approved, use merge queue to merge the PR

Jira ticket: [PROJ-IDENT]

🤖 Generated with Claude Code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

datadog-prod-us1-4[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction
sy-lee and others added 2 commits October 1, 2026 15:53
@sy-lee @claude
Make extracted gRPC server context, including baggage, current in the…
2ba4dba
… 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 <[email protected]>
@sy-lee @claude
Inject the full current context from the grpc-1.5 client
c0b0544
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 <[email protected]>
@PerfectSlayer PerfectSlayer added type: feature Enhancements and improvements tag: community Community contribution inst: grpc gRPC instrumentation labels Oct 6, 2026
@sy-lee sy-lee closed this Oct 9, 2026
@sy-lee sy-lee reopened this Oct 13, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

inst: grpc gRPC instrumentation tag: community Community contribution type: feature Enhancements and improvements

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@sy-lee @PerfectSlayer
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.