Skip to content

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

Merged
congbobo184 merged 2 commits into
apache:masterfrom
hrzzzz:fix-otel-context
May 14, 2026
Merged

[fix][client] Inject trace context into message properties for producer-consumer span correlation#25749
congbobo184 merged 2 commits 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

@congbobo184 congbobo184 added this to the 5.0.0-M1 milestone May 14, 2026
@congbobo184 congbobo184 added the type/bug The PR fixed a bug or issue reported a bug label May 14, 2026
Copy link
Copy Markdown
Contributor

@congbobo184 congbobo184 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@congbobo184 congbobo184 merged commit 9948461 into apache:master May 14, 2026
80 of 82 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/bug The PR fixed a bug or issue reported a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants