gnodet-bot commented on code in PR #30326:
URL: https://github.com/apache/camel/pull/30326#discussion_r4625503700
##########
components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIResponsesProducer.java:
##########
@@ -247,6 +255,42 @@ config, getEndpoint().getMcpToolState(), session)) {
}
}
+ /**
+ * Wraps the tool loop in an {@code invoke_agent} span at observability
level {@code detailed} or higher. The model
+ * calls and tool calls started inside nest under it, giving tracing
backends one agent run per user turn.
+ */
+ private void processObservedToolLoop(
+ Exchange exchange, OpenAIConfiguration config,
ResponseCreateParams params, List<ResponseInputItem> input,
+ String model, String conversationId)
+ throws Exception {
+ String routeId = ExchangeHelper.getAtRouteId(exchange);
+ GenAiObservation agentRun = GenAiObservability.start(exchange,
GenAiObservationContext.builder()
+ .operationName(GenAiOperationName.INVOKE_AGENT)
+ .agentName(routeId != null ? routeId : "openai")
+ .system("openai")
+ .requestModel(model)
+ .conversationId(ObjectHelper.isNotEmpty(conversationId) ?
conversationId : null)
+ .componentScheme("openai")
+ .build());
+ agentRun.recordInputMessages(() ->
OpenAIResponsesGenAiMessages.input(params));
+ try {
+ try (GenAiObservation.Scope ignored = agentRun.makeCurrent()) {
Review Comment:
🚫 `GenAiObservation.makeCurrent()` and `GenAiObservation.Scope` were removed
from main by #30339. This `try`-with-resources will fail to compile after a
rebase. Drop the scope wrapper and call `processToolLoop` directly:
```suggestion
processToolLoop(exchange, config, params, input, model,
ObjectHelper.isNotEmpty(conversationId) ? conversationId
: null);
```
##########
components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIResponsesProducer.java:
##########
@@ -393,21 +437,50 @@ private void processToolLoop(
}
private Response createResponse(Exchange exchange, String model,
ResponseCreateParams params) throws Exception {
- return observedCall(exchange, model, () ->
getEndpoint().getClient().responses().create(params));
+ return observedCall(exchange, model, params, () ->
getEndpoint().getClient().responses().create(params));
}
- private Response observedCall(Exchange exchange, String model,
ThrowingSupplier<Response, Exception> call)
+ private Response observedCall(
+ Exchange exchange, String model, ResponseCreateParams params,
ThrowingSupplier<Response, Exception> call)
throws Exception {
GenAiObservationContext observationContext =
GenAiObservationContext.builder()
.operationName(GenAiOperationName.CHAT)
.system("openai")
.requestModel(model)
.componentScheme("openai")
+
.conversationId(params.conversation().map(Object::toString).orElse(null))
+ .requestParameter("temperature",
params.temperature().orElse(null))
+ .requestParameter("top_p", params.topP().orElse(null))
+ .requestParameter("max_tokens",
params.maxOutputTokens().orElse(null))
+
.tracedByFramework(OpenAIClientTracing.tracedByOpenTelemetry(exchange.getContext(),
getEndpoint().getClient()))
.build();
GenAiObservation observation = GenAiObservability.start(exchange,
observationContext);
+ observation.recordInputMessages(() ->
OpenAIResponsesGenAiMessages.input(params));
+ observation.recordSystemInstructions(() ->
params.instructions().orElse(null));
+ observation.recordToolDefinitions(() ->
OpenAIResponsesGenAiMessages.toolDefinitions(params));
try {
- Response response = call.get();
- recordResponseSuccess(observation, response);
+ Response response;
+ try (GenAiObservation.Scope ignored = observation.makeCurrent()) {
Review Comment:
🚫 Same issue — `observation.makeCurrent()` no longer exists after #30339.
Remove the scope wrapper and call `call.get()` directly:
```suggestion
Response response = call.get();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]