Opentelemetry Surpresses Kafka Produce Message Java

18 Views Asked by At

I am using Opentelemetry

  • api 1.13.0
  • annotations 2.2.0
  • kafka-clients-2.6 2.2.0-alpha

on spring boots to trace the sending of messages to kafka. The message interceptor is configured as defined in the documentation:

configProps.put(ProducerConfig.INTERCEPTOR_CLASSES_CONFIG, TracingProducerInterceptor.class.getName());

Upon debugging, the interceptor is called and the send is intercepted. The trace however is never created. In the method buildAndInjectSpan of the class io.opentelemetry.instrumentation.kafkaclients.v2_6.KafkaTelemetry a check is performed whether or not the context should be started:

if (this.producerInstrumenter.shouldStart(parentContext, request)) {
    Context context = this.producerInstrumenter.start(parentContext, request);
    if (this.producerPropagationEnabled) {
        try {
            this.propagator().inject(context, record.headers(), SETTER);
        } catch (Throwable var7) {
            logger.log(Level.WARNING, "failed to inject span context. sending record second time?", var7);
        }
    }
    this.producerInstrumenter.end(context, request, (Object)null, (Throwable)null);
}

The method shouldStart(parentContext, request) is called and the check fails, because the following code returns true:


public boolean shouldSuppress(Context parentContext, SpanKind spanKind) {

    // spanKeys = Set("opentelemetry-traces-span-key-producer")
    Iterator var3 = this.spanKeys.iterator();

    SpanKey spanKey;
    do {
        if (!var3.hasNext()) {
            // true is returned since var3 only contains one item
            return true; 
        }

        spanKey = (SpanKey)var3.next();
    } while(spanKey.fromContextOrNull(parentContext) != null);

    return false;
}

The documentation does not state why this is the case and I can not wrap my head around it. The message to kafka is sent after doing an insert via JPA which is correctly traced. All other methods, be it JPA or SpringRest related are correctly traced with their respective attributes only kafka related ones are not being traced.

0

There are 0 best solutions below