Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(otel): map tools from claude managed agents to output (#18720)

Nimar7f09fc127e10
diff --git a/packages/shared/src/server/otel/OtelIngestionProcessor.ts b/packages/shared/src/server/otel/OtelIngestionProcessor.ts
index 7d4879c79d..f31579ffd4 100644
--- a/packages/shared/src/server/otel/OtelIngestionProcessor.ts
+++ b/packages/shared/src/server/otel/OtelIngestionProcessor.ts
@@ -1913,6 +1913,8 @@ export class OtelIngestionProcessor {
"gen_ai.output.messages",
"gen_ai.tool.call.arguments",
"gen_ai.tool.call.result",
+ // Claude Managed Agents
+ "anthropic.tool_result.content",
// Genkit
"genkit:input",
"genkit:output",
@@ -2422,7 +2424,9 @@ export class OtelIngestionProcessor {
// OpenTelemetry tools (https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans)
input = attributes["gen_ai.tool.call.arguments"];
- output = attributes["gen_ai.tool.call.result"];
+ output =
+ attributes["gen_ai.tool.call.result"] ??
+ attributes["anthropic.tool_result.content"];
if (input || output) {
return { input, output };
diff --git a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts b/web/src/__tests__/server/api/otel/otelMapping.servertest.ts
index 198155bb40..7423417e92 100644
--- a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts
+++ b/web/src/__tests__/server/api/otel/otelMapping.servertest.ts
@@ -5708,6 +5708,78 @@ describe("OTel Resource Span Mapping", () => {
);
});
+ it("should map Claude Managed Agents tool results to output in both ingestion paths", async () => {
+ const input = JSON.stringify({ path: "/workspace/example.txt" });
+ const output = JSON.stringify([
+ { type: "text", text: "Example file contents." },
+ { type: "text", text: "Second content block." },
+ ]);
+ const resourceSpan: ResourceSpan = {
+ resource: {
+ attributes: [
+ {
+ key: "service.name",
+ value: { stringValue: "claude-platform" },
+ },
+ ],
+ },
+ scopeSpans: [
+ {
+ scope: { name: "com.anthropic.claude-platform" },
+ spans: [
+ {
+ ...defaultSpanProps,
+ traceId: Buffer.from(defaultSpanProps.traceId.data),
+ spanId: Buffer.from(defaultSpanProps.spanId.data),
+ name: "read",
+ attributes: [
+ {
+ key: "gen_ai.provider.name",
+ value: { stringValue: "anthropic" },
+ },
+ {
+ key: "gen_ai.operation.name",
+ value: { stringValue: "execute_tool" },
+ },
+ {
+ key: "gen_ai.tool.name",
+ value: { stringValue: "read" },
+ },
+ {
+ key: "gen_ai.tool.call.arguments",
+ value: { stringValue: input },
+ },
+ {
+ key: "anthropic.tool_result.content",
+ value: { stringValue: output },
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ };
+
+ const events = await convertOtelSpanToIngestionEvent(
+ resourceSpan,
+ new Set(),
+ );
+ const tool = events.find((event) => event.type === "tool-create");
+ expect(tool?.body).toMatchObject({ input, output });
+ expect(
+ tool?.body.metadata.attributes?.["anthropic.tool_result.content"],
+ ).toBeUndefined();
+
+ const eventInputs = createTestOtelProcessor().processToEvent([
+ resourceSpan,
+ ]);
+ expect(eventInputs).toHaveLength(1);
+ expect(eventInputs[0]).toMatchObject({ type: "TOOL", input, output });
+ expect(
+ eventInputs[0].metadata.attributes["anthropic.tool_result.content"],
+ ).toBeUndefined();
+ });
+
it("should filter all input/output attribute patterns from metadata.attributes while preserving custom attributes", async () => {
// This test verifies that extractInputAndOutput's filteredAttributes correctly removes
// all known input/output attribute patterns from multiple frameworks