This is an automated email from the ASF dual-hosted git repository.
Croway pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new a0e8eb9ca995 CAMEL-27131: camel-ai-observability - opt-in again (not
in camel-observability-services), and do not make the GenAI spans current
(#30339)
a0e8eb9ca995 is described below
commit a0e8eb9ca995cd3338723f5979aac66759ad8e23
Author: Federico Mariani <[email protected]>
AuthorDate: Wed Nov 18 13:36:21 2026 +0100
CAMEL-27131: camel-ai-observability - opt-in again (not in
camel-observability-services), and do not make the GenAI spans current (#30339)
* CAMEL-27131: camel-ai-observability - do not make the GenAI spans current
The tracing design (design/tracing.adoc, CAMEL-23380) keeps the
OpenTelemetry context current only
while a processor runs. Remove Span.openScope() (camel-telemetry) with its
camel-opentelemetry2
implementation, and GenAiObservation.makeCurrent() with the calls around
the model, agent and tool
calls. Both were added by the previous CAMEL-27131 commit and are not
released.
The spans that an AI framework records for its own model calls are now
children of the route span,
next to Camel's invoke_agent span; the ai-observability page says so.
* CAMEL-27131: camel-observability-services - do not include
camel-ai-observability
GenAI observability stays opt-in: an application adds
camel-ai-observability when it wants the GenAI
spans and metrics of the Camel AI components. camel-observability-services
no longer brings it, and the
ai-observability and observability-services pages say that it has to be
added.
---
.../camel/catalog/docs/ai-observability.adoc | 20 +++++++++++++++++---
.../camel/catalog/docs/observability-services.adoc | 4 +++-
.../ai/observability/GenAiObservation.java | 22 ----------------------
.../src/main/docs/ai-observability.adoc | 20 +++++++++++++++++---
.../ai/observability/GenAiObservabilityImpl.java | 12 ------------
.../camel/component/ai/tool/AiToolExecutor.java | 5 +----
.../agent/LangChain4jAgentProducer.java | 14 ++++----------
.../langchain4j/chat/LangChain4jChatProducer.java | 10 ++--------
.../component/openai/McpToolCallExecutor.java | 9 +--------
.../camel/component/openai/OpenAIProducer.java | 9 ++-------
components/camel-observability-services/pom.xml | 4 ----
.../src/main/docs/observability-services.adoc | 4 +++-
.../opentelemetry2/OpenTelemetrySpanAdapter.java | 12 ------------
.../main/java/org/apache/camel/telemetry/Span.java | 22 ----------------------
14 files changed, 50 insertions(+), 117 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/ai-observability.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/ai-observability.adoc
index 85435892a291..82d5cec29d35 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/ai-observability.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/ai-observability.adoc
@@ -12,8 +12,20 @@
The `camel-ai-observability` module provides GenAI observability for Camel AI
components following the
OpenTelemetry semantic conventions for GenAI (stable subset aligned with
Spring AI).
-AI producers depend on the lightweight `camel-ai-observability-api` module.
Add `camel-ai-observability` to your
-application classpath together with a tracing or metrics backend to enable
span and metric emission.
+AI producers depend on the lightweight `camel-ai-observability-api` module,
which records nothing by itself. GenAI
+observability is opt-in: add `camel-ai-observability` to the application,
together with a tracing or metrics backend
+such as `camel-opentelemetry2` or `camel-micrometer`, to enable span and
metric emission. It is not part of
+`camel-observability-services`, so add it also when the application uses that
module.
+
+[source,xml]
+----
+<dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-ai-observability</artifactId>
+ <version>x.x.x</version>
+ <!-- use the same version as your Camel core version -->
+</dependency>
+----
When `camel-opentelemetry2` and/or `camel-micrometer` is on the classpath,
langchain4j, OpenAI, and Spring AI chat
producers emit child spans and metrics per LLM call with attributes such as
`gen_ai.operation.name`, `gen_ai.system`,
@@ -99,7 +111,9 @@ it does not record its own span and metrics for the calls
the framework records,
* `spring-ai-chat`: the model calls are left to Spring AI, and so are the
Camel route tools when the tool calling
manager of the model traces them (Spring AI gives some models a default
manager without a registry).
* `langchain4j-chat` and `langchain4j-agent`: the model calls are left to the
framework. At level `detailed` and above,
-the agent run and the Camel route tools are still recorded by Camel, and the
framework's spans nest under the agent run.
+the agent run and the Camel route tools are still recorded by Camel. The
framework's spans are children of the span
+that is current when the endpoint is called, which is the route span: they
appear next to the agent run, not under it,
+because Camel makes its spans current only while a processor runs.
* `openai`: the `openai-java` instrumentation of OpenTelemetry (in the
OpenTelemetry Java agent) wraps the OpenAI client
used by `camel-openai` and traces its chat completions and embeddings. When
the client is wrapped, those calls are left
to it, except at level `full`: the instrumentation records the messages as log
events, not as span attributes, so Camel
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/observability-services.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/observability-services.adoc
index 60c73e007aa4..bd292f13f863 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/observability-services.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/observability-services.adoc
@@ -47,7 +47,9 @@ The presence of this dependency will provide the following
components:
* camel-management
* camel-micrometer-prometheus
* camel-opentelemetry2
-* camel-ai-observability (GenAI spans and metrics of the Camel AI components,
see xref:others:ai-observability.adoc[AI Observability])
+
+NOTE: the GenAI spans and metrics of the Camel AI components are not included.
Add `camel-ai-observability` to the
+application when you want them, see xref:others:ai-observability.adoc[AI
Observability].
NOTE: mind that we're using the `camel-opentelemetry2` implementation which
has slight differences from `camel-opentelemetry`.
diff --git
a/components/camel-ai/camel-ai-observability-api/src/main/java/org/apache/camel/component/ai/observability/GenAiObservation.java
b/components/camel-ai/camel-ai-observability-api/src/main/java/org/apache/camel/component/ai/observability/GenAiObservation.java
index 2266ce1f76a8..736fc0fb602a 100644
---
a/components/camel-ai/camel-ai-observability-api/src/main/java/org/apache/camel/component/ai/observability/GenAiObservation.java
+++
b/components/camel-ai/camel-ai-observability-api/src/main/java/org/apache/camel/component/ai/observability/GenAiObservation.java
@@ -102,28 +102,6 @@ public interface GenAiObservation extends AutoCloseable {
// noop
}
- /**
- * Makes the observation current on the calling thread for a synchronous
call, so that spans started inside it (by
- * the HTTP client or the AI framework) nest under it. Close the scope on
the same thread, before {@link #close()}.
- *
- * @since 4.24
- */
- default Scope makeCurrent() {
- return () -> {
- // noop
- };
- }
-
@Override
void close();
-
- /**
- * A scope opened by {@link #makeCurrent()}.
- *
- * @since 4.24
- */
- interface Scope extends AutoCloseable {
- @Override
- void close();
- }
}
diff --git
a/components/camel-ai/camel-ai-observability/src/main/docs/ai-observability.adoc
b/components/camel-ai/camel-ai-observability/src/main/docs/ai-observability.adoc
index 85435892a291..82d5cec29d35 100644
---
a/components/camel-ai/camel-ai-observability/src/main/docs/ai-observability.adoc
+++
b/components/camel-ai/camel-ai-observability/src/main/docs/ai-observability.adoc
@@ -12,8 +12,20 @@
The `camel-ai-observability` module provides GenAI observability for Camel AI
components following the
OpenTelemetry semantic conventions for GenAI (stable subset aligned with
Spring AI).
-AI producers depend on the lightweight `camel-ai-observability-api` module.
Add `camel-ai-observability` to your
-application classpath together with a tracing or metrics backend to enable
span and metric emission.
+AI producers depend on the lightweight `camel-ai-observability-api` module,
which records nothing by itself. GenAI
+observability is opt-in: add `camel-ai-observability` to the application,
together with a tracing or metrics backend
+such as `camel-opentelemetry2` or `camel-micrometer`, to enable span and
metric emission. It is not part of
+`camel-observability-services`, so add it also when the application uses that
module.
+
+[source,xml]
+----
+<dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-ai-observability</artifactId>
+ <version>x.x.x</version>
+ <!-- use the same version as your Camel core version -->
+</dependency>
+----
When `camel-opentelemetry2` and/or `camel-micrometer` is on the classpath,
langchain4j, OpenAI, and Spring AI chat
producers emit child spans and metrics per LLM call with attributes such as
`gen_ai.operation.name`, `gen_ai.system`,
@@ -99,7 +111,9 @@ it does not record its own span and metrics for the calls
the framework records,
* `spring-ai-chat`: the model calls are left to Spring AI, and so are the
Camel route tools when the tool calling
manager of the model traces them (Spring AI gives some models a default
manager without a registry).
* `langchain4j-chat` and `langchain4j-agent`: the model calls are left to the
framework. At level `detailed` and above,
-the agent run and the Camel route tools are still recorded by Camel, and the
framework's spans nest under the agent run.
+the agent run and the Camel route tools are still recorded by Camel. The
framework's spans are children of the span
+that is current when the endpoint is called, which is the route span: they
appear next to the agent run, not under it,
+because Camel makes its spans current only while a processor runs.
* `openai`: the `openai-java` instrumentation of OpenTelemetry (in the
OpenTelemetry Java agent) wraps the OpenAI client
used by `camel-openai` and traces its chat completions and embeddings. When
the client is wrapped, those calls are left
to it, except at level `full`: the instrumentation records the messages as log
events, not as span attributes, so Camel
diff --git
a/components/camel-ai/camel-ai-observability/src/main/java/org/apache/camel/component/ai/observability/GenAiObservabilityImpl.java
b/components/camel-ai/camel-ai-observability/src/main/java/org/apache/camel/component/ai/observability/GenAiObservabilityImpl.java
index 85eaea7a83c7..54a6a7b0602d 100644
---
a/components/camel-ai/camel-ai-observability/src/main/java/org/apache/camel/component/ai/observability/GenAiObservabilityImpl.java
+++
b/components/camel-ai/camel-ai-observability/src/main/java/org/apache/camel/component/ai/observability/GenAiObservabilityImpl.java
@@ -283,18 +283,6 @@ public final class GenAiObservabilityImpl implements
GenAiObservationFactory {
recordContent(GenAiAttributes.TOOL_CALL_RESULT, () ->
GenAiMessages.truncate(result.get(), contentMaxLength));
}
- @Override
- public Scope makeCurrent() {
- // the Micrometer Observation path opens its scope when the
observation starts
- if (span == null || closed) {
- return () -> {
- // noop
- };
- }
- Span.Scope scope = span.openScope();
- return scope::close;
- }
-
private void recordMessages(String key, Supplier<GenAiMessages>
messages) {
recordContent(key, () -> {
GenAiMessages value = messages.get();
diff --git
a/components/camel-ai/camel-ai-tool/src/main/java/org/apache/camel/component/ai/tool/AiToolExecutor.java
b/components/camel-ai/camel-ai-tool/src/main/java/org/apache/camel/component/ai/tool/AiToolExecutor.java
index 6d9ed88cc455..fb3eb0030bdc 100644
---
a/components/camel-ai/camel-ai-tool/src/main/java/org/apache/camel/component/ai/tool/AiToolExecutor.java
+++
b/components/camel-ai/camel-ai-tool/src/main/java/org/apache/camel/component/ai/tool/AiToolExecutor.java
@@ -133,10 +133,7 @@ public final class AiToolExecutor {
.build());
try {
observation.recordToolArguments(() -> Jsoner.serialize(arguments
!= null ? arguments : Map.of()));
- AiToolResult result;
- try (GenAiObservation.Scope ignored = observation.makeCurrent()) {
- result = doExecute(spec, arguments, exchange, toolCallId,
conversationId);
- }
+ AiToolResult result = doExecute(spec, arguments, exchange,
toolCallId, conversationId);
recordResult(observation, result);
return result;
} catch (RuntimeException e) {
diff --git
a/components/camel-ai/camel-langchain4j-agent/src/main/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentProducer.java
b/components/camel-ai/camel-langchain4j-agent/src/main/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentProducer.java
index 83298a0b181b..c5fc883c56bf 100644
---
a/components/camel-ai/camel-langchain4j-agent/src/main/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentProducer.java
+++
b/components/camel-ai/camel-langchain4j-agent/src/main/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentProducer.java
@@ -208,10 +208,7 @@ public class LangChain4jAgentProducer extends
DefaultProducer {
.build();
GenAiObservation observation = GenAiObservability.start(exchange,
observationContext);
try {
- Result<String> result;
- try (GenAiObservation.Scope ignored = observation.makeCurrent()) {
- result = agent.chat(aiAgentBody, toolProvider);
- }
+ Result<String> result = agent.chat(aiAgentBody, toolProvider);
exchange.getMessage().setBody(result.content());
populateResultHeaders(result, exchange,
observationContext.requestModel());
observation.recordSuccess(GenAiUsage.of(
@@ -253,12 +250,9 @@ public class LangChain4jAgentProducer extends
DefaultProducer {
agentRun.recordSystemInstructions(aiAgentBody::getSystemMessage);
agentRun.recordInputMessages(() -> new
GenAiMessages().text(GenAiMessages.USER, aiAgentBody.getUserMessage()));
try {
- Result<String> result;
- try (GenAiObservation.Scope ignored = agentRun.makeCurrent()) {
- result = AgentInvocationListeners.invoke(
- modelCallsTracedByFramework ? List.of() :
observer.listeners(),
- () -> agent.chat(aiAgentBody, toolProvider));
- }
+ Result<String> result = AgentInvocationListeners.invoke(
+ modelCallsTracedByFramework ? List.of() :
observer.listeners(),
+ () -> agent.chat(aiAgentBody, toolProvider));
exchange.getMessage().setBody(result.content());
populateResultHeaders(result, exchange, requestModel);
// the model calls carry the token usage; repeating it on the run
would count it twice
diff --git
a/components/camel-ai/camel-langchain4j-chat/src/main/java/org/apache/camel/component/langchain4j/chat/LangChain4jChatProducer.java
b/components/camel-ai/camel-langchain4j-chat/src/main/java/org/apache/camel/component/langchain4j/chat/LangChain4jChatProducer.java
index 8ee4c2acb832..3ad568a4ba5e 100644
---
a/components/camel-ai/camel-langchain4j-chat/src/main/java/org/apache/camel/component/langchain4j/chat/LangChain4jChatProducer.java
+++
b/components/camel-ai/camel-langchain4j-chat/src/main/java/org/apache/camel/component/langchain4j/chat/LangChain4jChatProducer.java
@@ -153,10 +153,7 @@ public class LangChain4jChatProducer extends
DefaultProducer {
GenAiObservationContext observationContext = buildObservationContext();
GenAiObservation observation = GenAiObservability.start(exchange,
observationContext);
try {
- ChatResponse chatResponse;
- try (GenAiObservation.Scope ignored = observation.makeCurrent()) {
- chatResponse = this.chatModel.chat(augmentedChatMessage);
- }
+ ChatResponse chatResponse =
this.chatModel.chat(augmentedChatMessage);
populateTokenUsageHeaders(chatResponse, exchange,
observationContext.requestModel());
observation.recordSuccess(GenAiUsage.of(
chatResponse.tokenUsage() != null ?
chatResponse.tokenUsage().inputTokenCount() : null,
@@ -219,10 +216,7 @@ public class LangChain4jChatProducer extends
DefaultProducer {
GenAiObservationContext observationContext = buildObservationContext();
GenAiObservation observation = GenAiObservability.start(exchange,
observationContext);
try {
- ChatResponse chatResponse;
- try (GenAiObservation.Scope ignored = observation.makeCurrent()) {
- chatResponse = this.chatModel.chat(chatMessages);
- }
+ ChatResponse chatResponse = this.chatModel.chat(chatMessages);
populateTokenUsageHeaders(chatResponse, exchange,
observationContext.requestModel());
observation.recordSuccess(GenAiUsage.of(
chatResponse.tokenUsage() != null ?
chatResponse.tokenUsage().inputTokenCount() : null,
diff --git
a/components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/McpToolCallExecutor.java
b/components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/McpToolCallExecutor.java
index 121f28db6e17..d2c7eac58c3f 100644
---
a/components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/McpToolCallExecutor.java
+++
b/components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/McpToolCallExecutor.java
@@ -311,14 +311,7 @@ class McpToolCallExecutor extends ServiceSupport {
throws Exception {
try {
Map<String, Object> argsMap = OBJECT_MAPPER.readValue(argsJson,
Map.class);
- McpSchema.CallToolResult toolResult;
- if (observation != null) {
- try (GenAiObservation.Scope ignored =
observation.makeCurrent()) {
- toolResult = endpoint.callTool(mcpClient, toolName,
argsMap);
- }
- } else {
- toolResult = endpoint.callTool(mcpClient, toolName, argsMap);
- }
+ McpSchema.CallToolResult toolResult = endpoint.callTool(mcpClient,
toolName, argsMap);
if (Boolean.TRUE.equals(toolResult.isError())) {
String content = "Error: " +
extractTextContent(toolResult.content());
diff --git
a/components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIProducer.java
b/components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIProducer.java
index 0c9c35943466..46f22c9f0076 100644
---
a/components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIProducer.java
+++
b/components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIProducer.java
@@ -383,9 +383,7 @@ public class OpenAIProducer extends DefaultAsyncProducer {
.build());
agentRun.recordInputMessages(() -> OpenAIGenAiMessages.input(params));
try {
- try (GenAiObservation.Scope ignored = agentRun.makeCurrent()) {
- processNonStreamingAgentic(exchange, params, config);
- }
+ processNonStreamingAgentic(exchange, params, config);
// the model calls carry the token usage; repeating it on the run
would count it twice
agentRun.recordSuccess(GenAiUsage.of((Long) null, null,
exchange.getMessage().getHeader(OpenAIConstants.FINISH_REASON, String.class),
null));
@@ -714,10 +712,7 @@ public class OpenAIProducer extends DefaultAsyncProducer {
observation.recordInputMessages(() ->
OpenAIGenAiMessages.input(params));
observation.recordToolDefinitions(() ->
OpenAIGenAiMessages.toolDefinitions(params));
try {
- ChatCompletion response;
- try (GenAiObservation.Scope ignored = observation.makeCurrent()) {
- response =
getEndpoint().getClient().chat().completions().create(params);
- }
+ ChatCompletion response =
getEndpoint().getClient().chat().completions().create(params);
CompletionUsage usage = response.usage().orElse(null);
String finishReason = response.choices().isEmpty() ? null :
getFinishReasonString(response.choices().get(0));
observation.recordSuccess(GenAiUsage.of(
diff --git a/components/camel-observability-services/pom.xml
b/components/camel-observability-services/pom.xml
index d6e4e4d91bd1..36362b8916a1 100644
--- a/components/camel-observability-services/pom.xml
+++ b/components/camel-observability-services/pom.xml
@@ -46,10 +46,6 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-opentelemetry2</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-ai-observability</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-health</artifactId>
diff --git
a/components/camel-observability-services/src/main/docs/observability-services.adoc
b/components/camel-observability-services/src/main/docs/observability-services.adoc
index 60c73e007aa4..bd292f13f863 100644
---
a/components/camel-observability-services/src/main/docs/observability-services.adoc
+++
b/components/camel-observability-services/src/main/docs/observability-services.adoc
@@ -47,7 +47,9 @@ The presence of this dependency will provide the following
components:
* camel-management
* camel-micrometer-prometheus
* camel-opentelemetry2
-* camel-ai-observability (GenAI spans and metrics of the Camel AI components,
see xref:others:ai-observability.adoc[AI Observability])
+
+NOTE: the GenAI spans and metrics of the Camel AI components are not included.
Add `camel-ai-observability` to the
+application when you want them, see xref:others:ai-observability.adoc[AI
Observability].
NOTE: mind that we're using the `camel-opentelemetry2` implementation which
has slight differences from `camel-opentelemetry`.
diff --git
a/components/camel-opentelemetry2/src/main/java/org/apache/camel/opentelemetry2/OpenTelemetrySpanAdapter.java
b/components/camel-opentelemetry2/src/main/java/org/apache/camel/opentelemetry2/OpenTelemetrySpanAdapter.java
index 177163f03afe..121bbaaf3228 100644
---
a/components/camel-opentelemetry2/src/main/java/org/apache/camel/opentelemetry2/OpenTelemetrySpanAdapter.java
+++
b/components/camel-opentelemetry2/src/main/java/org/apache/camel/opentelemetry2/OpenTelemetrySpanAdapter.java
@@ -23,7 +23,6 @@ import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.StatusCode;
-import io.opentelemetry.context.Context;
import org.apache.camel.telemetry.TagConstants;
public class OpenTelemetrySpanAdapter implements
org.apache.camel.telemetry.Span {
@@ -80,17 +79,6 @@ public class OpenTelemetrySpanAdapter implements
org.apache.camel.telemetry.Span
this.otelSpan.setAttribute(key, value);
}
- @Override
- public org.apache.camel.telemetry.Span.Scope openScope() {
- Context context = Context.current().with(otelSpan);
- if (baggage != null) {
- context = context.with(baggage);
- }
- // qualified: the Scope inherited from the Camel Span interface
shadows an import of the OpenTelemetry one
- io.opentelemetry.context.Scope scope = context.makeCurrent();
- return scope::close;
- }
-
@Override
public void setComponent(String component) {
this.setTag(TagConstants.COMPONENT, component);
diff --git
a/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/Span.java
b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/Span.java
index 6d0d25d61807..084e38985db2 100644
---
a/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/Span.java
+++
b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/Span.java
@@ -50,26 +50,4 @@ public interface Span {
void setError(boolean isError);
- /**
- * Makes this span the current one on the calling thread, so that spans
started by libraries during a synchronous
- * call (an HTTP client, an AI framework) become its children. The
returned scope must be closed on the same thread.
- * The default does nothing.
- *
- * @since 4.24
- */
- default Scope openScope() {
- return () -> {
- };
- }
-
- /**
- * The scope opened by {@link #openScope()}.
- *
- * @since 4.24
- */
- interface Scope extends AutoCloseable {
- @Override
- void close();
- }
-
}