发布

  • [OPIK-7001] [BE] [SDK] fix: surface OTel span errors, tool output, and Google cost for Pydantic AI (#7152)

    frostbyte_neo 发布于 2026-06-19 11:27:56 +00:00

    • [OPIK-7001] [BE] [SDK] fix: surface OTel span errors, tool output, and Google cost for Pydantic AI

    PydanticAI/Logfire spans ingested over OTel were missing data the UI and cost tracking rely on:

    • Tool/function span outputs fell into the input bucket: map logfire's tool_response/tool_arguments attributes to OUTPUT/INPUT.
    • Tool errors were buried in raw event metadata: translate the OTel exception event and STATUS_CODE_ERROR span status into the span's error_info (generic, benefits every OTel integration).
    • Gemini cost was 0 because the generic google provider matched no price row: disambiguate via server.address into google_vertexai / google_ai.

    Adds backend unit + cost-pipeline tests and two PydanticAI e2e library-integration tests (tool output, tool error).

    Implements OPIK-7001.

    Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com

    • fix(otel): map gen_ai.tool.call.arguments/result to input/output

    Logfire v3+ tool spans emit the tool's I/O under gen_ai.tool.call.arguments / gen_ai.tool.call.result. These fell through to the broad gen_ai.tool. prefix (METADATA), so v3 tool spans lost input/output. Match them explicitly before the prefix. Addresses PR review feedback.

    Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com

    • fix(otel): keep agent-run spans out of the llm type

    PydanticAI agent-run spans were typed as llm and given a model: 'model_name' (an agent-level attribute) mapped to MODEL+spanType(llm), and gen_ai.system_instructions further forced llm. Demote 'model_name' to metadata (the real LLM span gets its model from gen_ai.request.model) and type spans by gen_ai.operation.name=invoke_agent -> general. Addresses PR review gap F.

    Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com

    • fix(otel): propagate root-span error to trace and drop logfire.level_num noise
    • Set trace error_info from the root span so failed flows are flagged as errored at the trace level (previously only spans carried the error).
    • Drop logfire's internal logfire.level_num attribute, which leaked into span input on warning/error spans.

    Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com


    Co-authored-by: Claude Opus 4.8 noreply@anthropic.com

    下载附件