🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(ui): map i/o to pydantic root span (#12068)
Jannik Maierhöfer53cb3349ac10
diff --git a/packages/shared/src/server/otel/OtelIngestionProcessor.ts b/packages/shared/src/server/otel/OtelIngestionProcessor.tsindex 16abfdf320..9c3e0b9ff2 100644--- a/packages/shared/src/server/otel/OtelIngestionProcessor.ts+++ b/packages/shared/src/server/otel/OtelIngestionProcessor.ts@@ -1217,6 +1217,9 @@ export class OtelIngestionProcessor {// SmolAgents"input.value","output.value",+ // Pydantic AI agent/root span+ "final_result",+ "pydantic_ai.all_messages",// Pydantic and Pipecat"input","output",@@ -1497,6 +1500,15 @@ export class OtelIngestionProcessor {return { input, output, filteredAttributes };}+ // Pydantic AI agent/root span: all_messages → input, final_result → output+ if (instrumentationScopeName === "pydantic-ai") {+ input = attributes["pydantic_ai.all_messages"] ?? null;+ output = attributes["final_result"] ?? null;+ if (input || output) {+ return { input, output, filteredAttributes };+ }+ }+// Pydantic-AI uses tool_arguments and tool_response for tool call input/outputinput = attributes["tool_arguments"];output = attributes["tool_response"];diff --git a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts b/web/src/__tests__/server/api/otel/otelMapping.servertest.tsindex 1cb8b0c548..b92403d59e 100644--- a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts+++ b/web/src/__tests__/server/api/otel/otelMapping.servertest.ts@@ -1380,6 +1380,186 @@ describe("OTel Resource Span Mapping", () => {expect(toolObservation?.body.name).toBe("correct_tool_name");});+ it("should map Pydantic AI agent root span with final_result as output and pydantic_ai.all_messages as input", async () => {+ const traceId = "abcdef1234567890abcdef1234567890";++ const allMessages = [+ {+ role: "system",+ parts: [+ {+ type: "text",+ content:+ "Use the `roulette_wheel` function to see if the customer has won based on the number they provide.",+ },+ ],+ },+ {+ role: "user",+ parts: [{ type: "text", content: "Put my money on square eighteen" }],+ },+ {+ role: "assistant",+ parts: [+ {+ type: "tool_call",+ id: "call_fXo9X5qrViUJgNdVh0bzyD31",+ name: "roulette_wheel",+ arguments: { square: 18 },+ },+ ],+ finish_reason: "tool_call",+ },+ {+ role: "user",+ parts: [+ {+ type: "tool_call_response",+ id: "call_fXo9X5qrViUJgNdVh0bzyD31",+ name: "roulette_wheel",+ result: "winner",+ },+ ],+ },+ {+ role: "assistant",+ parts: [+ {+ type: "text",+ content:+ "Congratulations! You've won by placing your bet on square eighteen. 🎉",+ },+ ],+ finish_reason: "stop",+ },+ ];++ const pydanticAiRootSpan = {+ resource: {+ attributes: [+ {+ key: "telemetry.sdk.language",+ value: { stringValue: "python" },+ },+ {+ key: "telemetry.sdk.name",+ value: { stringValue: "opentelemetry" },+ },+ {+ key: "telemetry.sdk.version",+ value: { stringValue: "1.39.1" },+ },+ {+ key: "service.name",+ value: { stringValue: "openclaw-gateway" },+ },+ ],+ },+ scopeSpans: [+ {+ scope: {+ name: "pydantic-ai",+ version: "1.60.0",+ attributes: [],+ },+ spans: [+ {+ traceId: Buffer.from(traceId, "hex"),+ spanId: Buffer.from("1234567890abcdef", "hex"),+ // No parentSpanId — this is a root span+ name: "roulette_agent run",+ kind: 1,+ startTimeUnixNano: {+ low: 1000000,+ high: 406528574,+ unsigned: true,+ },+ endTimeUnixNano: {+ low: 2000000,+ high: 406528574,+ unsigned: true,+ },+ attributes: [+ {+ key: "model_name",+ value: { stringValue: "gpt-4o" },+ },+ {+ key: "agent_name",+ value: { stringValue: "roulette_agent" },+ },+ {+ key: "gen_ai.agent.name",+ value: { stringValue: "roulette_agent" },+ },+ {+ key: "logfire.msg",+ value: { stringValue: "roulette_agent run" },+ },+ {+ key: "final_result",+ value: {+ stringValue:+ "Congratulations! You've won by placing your bet on square eighteen. 🎉",+ },+ },+ {+ key: "gen_ai.usage.input_tokens",+ value: { stringValue: "174" },+ },+ {+ key: "gen_ai.usage.output_tokens",+ value: { stringValue: "31" },+ },+ {+ key: "pydantic_ai.all_messages",+ value: {+ stringValue: JSON.stringify(allMessages),+ },+ },+ ],+ events: [],+ status: { code: 1 },+ },+ ],+ },+ ],+ };++ const events = await convertOtelSpanToIngestionEvent(+ pydanticAiRootSpan,+ new Set(),+ );++ // Root span should produce a trace-create and a span-create+ const traceEvent = events.find((e) => e.type === "trace-create");+ const observationEvent = events.find((e) => e.type === "span-create");++ expect(traceEvent).toBeDefined();+ expect(observationEvent).toBeDefined();++ // Trace should have input (all_messages as JSON string) and output (final_result)+ expect(traceEvent?.body.input).toBe(JSON.stringify(allMessages));+ expect(traceEvent?.body.output).toBe(+ "Congratulations! You've won by placing your bet on square eighteen. 🎉",+ );++ // Observation should also have input and output+ expect(observationEvent?.body.input).toBe(JSON.stringify(allMessages));+ expect(observationEvent?.body.output).toBe(+ "Congratulations! You've won by placing your bet on square eighteen. 🎉",+ );++ // Name should come from logfire.msg+ expect(observationEvent?.body.name).toBe("roulette_agent run");++ // Verify final_result and pydantic_ai.all_messages are NOT duplicated in metadata.attributes+ const metadataAttributes =+ observationEvent?.body.metadata?.attributes ?? {};+ expect(metadataAttributes).not.toHaveProperty("final_result");+ expect(metadataAttributes).not.toHaveProperty("pydantic_ai.all_messages");+ });+it("should prioritize OpenInference over OTel GenAI and model detection", async () => {const resourceSpan = {scopeSpans: [