Federico Mariani created CAMEL-27141:
----------------------------------------

             Summary: camel-opentelemetry2 - the spans of a library called by 
an endpoint are children of the route span instead of the endpoint span
                 Key: CAMEL-27141
                 URL: https://issues.apache.org/jira/browse/CAMEL-27141
             Project: Camel
          Issue Type: Improvement
          Components: camel-opentelemetry
            Reporter: Federico Mariani


Since CAMEL-23380, {{camel-opentelemetry2}} does not make its spans current 
({{OpenTelemetrySpanAdapter.makeCurrent}} does nothing), except around each 
processor, where {{TraceProcessorsOtelInterceptStrategy}} makes current the 
span on top of the exchange. For a {{to}}, that is the route span: the endpoint 
span is started afterwards, by the sending event, inside the processor.

So the spans that an instrumented library records during the call (Spring AI or 
LangChain4j observations, an HTTP or JDBC client instrumented by the 
OpenTelemetry Java agent) become children of the route span, next to the 
endpoint span that wraps them instead of under it. A Spring Boot route calling 
{{spring-ai-chat}}, with Micrometer Tracing:
{noformat}
http post /chat/springai        Spring MVC
  POST                          Camel consumer span
    spring-ai-chat              Camel endpoint span
    chat <model>                Spring AI, next to the endpoint span instead of 
under it
      POST                      HTTP calls to the model
      POST
{noformat}
This matters more since CAMEL-27131: when the AI framework already traces the 
model call, Camel defers to it and records no span of its own, so the framework 
span is the only record of the call.

Proposal: make the endpoint span current for the duration of a synchronous 
producer call, opening and closing the scope on the same thread so that the 
leak fixed by CAMEL-23380 does not come back. For example the tracer could open 
the scope at the sending event and close it at the sent event when both run on 
the same thread, or a producer could open the scope of its endpoint span around 
its call with {{Span.openScope()}}, which CAMEL-27131 added to 
{{camel-telemetry}} for the GenAI spans. Asynchronous producers would keep 
today's behaviour.

_Claude Code on behalf of Croway_




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to