Add baggage tag fields to spans with OpenTelemetry and document gRPC baggage propagation - #51597
Open
o-shevchenko wants to merge 1 commit into
Open
Add baggage tag fields to spans with OpenTelemetry and document gRPC baggage propagation#51597o-shevchenko wants to merge 1 commit into
o-shevchenko wants to merge 1 commit into
Conversation
With OpenTelemetry, fields listed in management.tracing.baggage.tag-fields only became span tags when the application itself touched the baggage through the Tracer API. Baggage that arrived with a request was propagated correctly, but spans were not tagged with it (see micrometer-metrics/tracing#933). This commit registers Micrometer Tracing's BaggageTaggingSpanProcessor whenever baggage is enabled and at least one tag field is configured, so that spans are tagged with the baggage that is present in their parent context. A custom BaggageTaggingSpanProcessor bean backs off the auto-configured one. The gRPC reference documentation now describes that trace context and baggage are propagated over gRPC metadata by the auto-configured Micrometer observation interceptors, including the W3C baggage header and the individual metadata keys listed in management.tracing.baggage.remote-fields, and that this requires micrometer-core on the classpath. The baggage section of the tracing documentation now mentions tag fields and gRPC. See spring-projectsgh-49832 Signed-off-by: Oleksandr Shevchenko <oleksandr.shevchenko@datarobot.com>
o-shevchenko
force-pushed
the
gh-49832
branch
from
September 6, 2026 10:37
9ed5d13 to
035c4b5
Compare
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.
This PR replaces the original proposal (auto-configured gRPC baggage interceptors). While porting it from spring-projects/spring-grpc#369 I verified the behaviour end-to-end on
mainand on 4.1.1, and it turned out that Spring Boot already propagates baggage over gRPC out of the box — see the details below. What remained is a tagging gap that is not gRPC-specific, plus missing documentation. Related to #49832.What already works (no code change needed)
With
spring.grpc.{server,client}.observation.enabled(default) and Micrometer Tracing configured,ObservationGrpcServerInterceptor/ObservationGrpcClientInterceptorhand the gRPC metadata toPropagatingReceiver/SenderTracingObservationHandler, which run the samePropagatorchain as HTTP. A probe with the in-process transport, the OTel SDK and W3C propagation showed, for bothmainand 4.1.1:baggageheader and the individualmanagement.tracing.baggage.remote-fieldskeys are extracted and visible viaTracer#getBaggageinside unary and server-streaming methods, no leaks between callsbaggageheader and as individual remote-field keys, plustraceparentThe only prerequisite is
micrometer-coreon the classpath (the interceptors live there); without it, gRPC gets no observation and therefore no propagation, silently.What did not work: tag fields
management.tracing.baggage.tag-fieldswere not applied to the span of an incoming request unless the application itself calledtracer.getBaggage(...). That is micrometer-metrics/tracing#933 — the OTel bridge builds the span's parentContextfromContext.current()and drops the extracted baggage, soSpanProcessor#onStartnever sees it. I've proposed a fix for the bridge in micrometer-metrics/tracing#1548.Changes in this PR
OpenTelemetryPropagationConfigurations: register Micrometer'sBaggageTaggingSpanProcessorwhen baggage is enabled and at least one tag field is configured (@ConditionalOnMissingBean, so a custom bean backs off). Today this tags spans that start while baggage is current (client and internal spans); together with the bridge fix it also covers server spans of incoming requests.micrometer-coreprerequisite, and thespring.grpc.*.observation.enabledswitches.tag-fieldsand gRPC in the Baggage section.