pulsar icon indicating copy to clipboard operation
pulsar copied to clipboard

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

Open void-ptr974 opened this issue 6 months ago • 0 comments

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

  • [x] 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

void-ptr974 avatar May 30 '26 05:05 void-ptr974