hrzzzz opened a new issue, #25584:
URL: https://github.com/apache/pulsar/issues/25584

   ### Search before reporting
   
   - [x] I searched in the [issues](https://github.com/apache/pulsar/issues) 
and found nothing similar.
   
   
   ### Read release policy
   
   - [x] I understand that [unsupported 
versions](https://pulsar.apache.org/contribute/release-policy/#supported-versions)
 don't get bug fixes. I will attempt to reproduce the issue on a supported 
version of Pulsar client and Pulsar broker.
   
   
   ### User environment
   
   master
   
   ### Issue Description
   
   The `org.apache.pulsar.client.impl.tracing.OpenTelemetryProducerInterceptor` 
adopts a lazy-loading mechanism for initializing its `Tracer` and 
`TextMapPropagator` instances.
   
   Initialization is triggered only by the `initializeIfNeeded` method at the 
beginning of the `beforeSend` method.
   ```java
   private void initializeIfNeeded(Producer producer) {
       if (!initialized && producer instanceof ProducerBase<?> producerBase) {
           PulsarClientImpl client = producerBase.getClient();
           InstrumentProvider instrumentProvider = client.instrumentProvider();
   
           this.tracer = instrumentProvider.getTracer();
           this.propagator = 
GlobalOpenTelemetry.getPropagators().getTextMapPropagator();
           this.initialized = true;
       }
   }
   ```
   
   The `eligible` method of OpenTelemetryProducerInterceptor is implemented as 
follows:
   ```java
   public boolean eligible(Message message) {
       return tracer != null && propagator != null;
   }
   ```
   
   In `org.apache.pulsar.client.impl.ProducerInterceptors#beforeSend`, if an 
interceptor’s `eligible` method returns false, the logic skips the current 
interceptor and proceeds to the next one, which bypasses the execution of the 
interceptor’s `beforeSend` method entirely.
   ```java
       public Message<?> beforeSend(Producer<?> producer, Message<?> message) {
           Message<?> interceptorMessage = message;
           for (ProducerInterceptor interceptor : interceptors) {
               try {
                   if (!interceptor.eligible(message)) {
                       continue;
                   }
                   interceptorMessage = interceptor.beforeSend(producer, 
interceptorMessage);
               } catch (Throwable e) {
                  // ......
               }
           }
           return interceptorMessage;
       }
   ```
   
   This causes the `OpenTelemetryProducerInterceptor` to never get a chance to 
perform lazy initialization, ultimately making the interceptor non-functional.
   
   ### Error messages
   
   ```text
   
   ```
   
   ### Reproducing the issue
   
   Run the test case 
org.apache.pulsar.broker.service.OpenTelemetryTracingIntegrationTest#testBasicProducerConsumerTracing
 in debug mode and verify the number of generated spans.
   
   ### Additional information
   
   _No response_
   
   ### Are you willing to submit a PR?
   
   - [x] I'm willing to submit a PR!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to