Search before reporting
Read release policy
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.
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:
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.
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
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?
Search before reporting
Read release policy
User environment
master
Issue Description
The
org.apache.pulsar.client.impl.tracing.OpenTelemetryProducerInterceptoradopts a lazy-loading mechanism for initializing itsTracerandTextMapPropagatorinstances.Initialization is triggered only by the
initializeIfNeededmethod at the beginning of thebeforeSendmethod.The
eligiblemethod of OpenTelemetryProducerInterceptor is implemented as follows:In
org.apache.pulsar.client.impl.ProducerInterceptors#beforeSend, if an interceptor’seligiblemethod returns false, the logic skips the current interceptor and proceeds to the next one, which bypasses the execution of the interceptor’sbeforeSendmethod entirely.This causes the
OpenTelemetryProducerInterceptorto never get a chance to perform lazy initialization, ultimately making the interceptor non-functional.Error messages
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?