Skip to content

[fix][client] Inject trace context into message properties for producer-consumer span correlation#25749

Open
hrzzzz wants to merge 1 commit into
apache:masterfrom
hrzzzz:fix-otel-context
Open

[fix][client] Inject trace context into message properties for producer-consumer span correlation#25749
hrzzzz wants to merge 1 commit into
apache:masterfrom
hrzzzz:fix-otel-context

Conversation

@hrzzzz
Copy link
Copy Markdown
Contributor

@hrzzzz hrzzzz commented May 12, 2026

Motivation

The OpenTelemetry producer interceptor creates a send span but does not inject the trace context into message properties. On the consumer side, extractContext finds nothing in the properties and falls back to
Context.current(), so consumer spans always start a new trace instead of being children of the producer span. Producer and consumer spans are impossible to correlate.

Modifications

  • Added TracingContext.injectContext(Message, Context, TextMapPropagator) overload that writes trace context directly to the message's underlying MessageMetadata protobuf, handling both MessageImpl and TopicMessageImpl wrappers.
  • Called it from OpenTelemetryProducerInterceptor.beforeSend() after creating the producer span.

Verifying this change

  • Make sure that the change passes the CI checks.

Added test: org.apache.pulsar.broker.service.OpenTelemetryTracingIntegrationTest#testContextPropagationViaMessageProperties

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants