helidon-io / helidon

Java libraries for writing microservices
https://helidon.io
Apache License 2.0
3.52k stars 564 forks source link

SpanListener do not get invoked when native OTel tracer is used via Inject or unwrap #9079

Open vasanth-bhat opened 3 months ago

vasanth-bhat commented 3 months ago

Environment Details

Problem Description

Helidon 4.x supports the direct use of direct native OpenTelemetry Tracer ( io.opentelemetry.api.trace.Tracer) by services code in addition to use of Helidon's wrapper API's ( io.helidon.tracing.Tracer ) .

There are multiple ways the native Otel tracer can be used. For. such use cases since he wrapper is not involved the SpanListener do not get invoked. This will break the solutions ( RIC telemetry-jar) that are implemented based on Span Listener life cycle events.

  1. By injecting native OTel tracer and use that create Spans.

private io.opentelemetry.api.trace.Tracer tracer;

@Inject
 CustomResource(Tracer tracer) {        
    this.tracer = tracer; 
     Span span = tracer.spanBuilder("custom").startSpan();
}. 
  1. By unwrapping the Helidon Tracer

    var tracer = io.helidon.tracing.Tracer.global(); io.opentelemetry.api.trace.Tracer unwrapped = tracer.unwrap(io.opentelemetry.api.trace.Tracer.class); Span span = unwrapped.spanBuilder("custom").startSpan();

The ask here is to explore the options, on SpanListeners invoked.

For example , For. usecase #1 above, where native OTel tracer is injected. would it make sense to have a separate wrapped Tracer ( that actually implements io.opentelemetry.api.trace.Tracer and adds the SpanListener feature ) injected instead of the injecting the instance of “io.opentelemetry.sdk.trace.SdkTracer”

For #2, Similarly, Can the unwrap() of. Helidon Tracer unwrap to new wrapped Tracer that implements io.opentelemetry.api.trace.Tracer instead of “io.opentelemetry.sdk.trace.SdkTracer” ?

vasanth-bhat commented 1 day ago

Hi @m0mus Any update on this JIRA. When is this going to be considered for implementation?

m0mus commented 1 day ago

The task has been categorized as a normal priority item. We do not currently have an estimated completion date, but considering the number of high priority tasks in the queue, it is unlikely to be completed in the immediate future. Is there a specific urgency associated with this task that we should be aware of?

vasanth-bhat commented 1 day ago

it's required for spectra module