Skip to content

[fix][client] Fix incorrect topic in OTel spans for partitioned producers#25896

Open
void-ptr974 wants to merge 1 commit into
apache:masterfrom
void-ptr974:fix-otel-producer-topic
Open

[fix][client] Fix incorrect topic in OTel spans for partitioned producers#25896
void-ptr974 wants to merge 1 commit into
apache:masterfrom
void-ptr974:fix-otel-producer-topic

Conversation

@void-ptr974
Copy link
Copy Markdown
Contributor

@void-ptr974 void-ptr974 commented May 30, 2026

Fixes #25897

Motivation

The OTel producer interceptor cached the topic from the first producer it processed.

For partitioned producers, the same interceptor can be used by multiple internal partition producers. For example, if the first message is sent to:

persistent://public/default/my-topic-partition-0

the interceptor caches that topic. If a later message is sent to:

persistent://public/default/my-topic-partition-1

the producer span could still be created as:

send persistent://public/default/my-topic-partition-0

and messaging.destination.name could also be reported as:

persistent://public/default/my-topic-partition-0

This makes OTel producer spans report an incorrect topic for messages sent to other partitions.

Modifications

Use the current producer topic when creating each OTel producer span instead of caching the first topic.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • Added an integration test that sends messages with a partitioned producer and verifies producer spans use the correct partition topics.
  • Ran ./gradlew :pulsar-client-original:compileJava
  • Ran ./gradlew :pulsar-broker:test --tests org.apache.pulsar.broker.service.OpenTelemetryTracingIntegrationTest.testPartitionedProducerSpanUsesCurrentProducerTopic

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

  • 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.

[Bug] OTel producer spans can report incorrect topic for partitioned producers

1 participant