feat(tracing): record provider response id as gen_ai.response.id by yaozheng-fang · Pull Request #577 · volcengine/veadk-python · GitHub
Skip to content

feat(tracing): record provider response id as gen_ai.response.id#577

Merged
zakahan merged 1 commit into
mainfrom
feat/trace-response-id
Jun 2, 2026
Merged

feat(tracing): record provider response id as gen_ai.response.id#577
zakahan merged 1 commit into
mainfrom
feat/trace-response-id

Conversation

@yaozheng-fang

Copy link
Copy Markdown
Collaborator

What

Records the model provider's response id on the LLM trace span as the standard OpenTelemetry GenAI attribute gen_ai.response.id.

For Volcengine Ark this id equals the x-request-id response header — the most useful identifier when correlating with the provider's logs / filing tickets.

Why it's done this way

  • ADK builds its LlmResponse from the litellm response's message/model/usage but drops response.id, so the tracer never sees it.
  • A pure litellm callback can read the id, but litellm runs success callbacks detached from the OTel context (verified: get_current_span() is non-recording there), so it can't attach the id to the LLM span.
  • So a self-contained tracing module wraps LiteLLMClient.acompletion in-context (where the raw response is available, inside ADK's generate_content span) and sets gen_ai.response.id on the current span.

Scope / safety

  • New file veadk/tracing/telemetry/litellm_response_id.py + one lazy registration line in OpentelemetryTracer (same pattern as the existing patch_google_adk_telemetry).
  • No agent.py change, no model subclass. The wrap is applied only when a VeADK OpenTelemetry tracer is created; with no tracer nothing is patched, and when patched-but-not-recording it's a no-op.
  • Non-streaming is covered (the default); the streaming wrapper has no stable id at this point, so it's skipped.

Verified locally (real Ark call)

With a tracer enabled, the generate_content span's gen_ai.response.id exactly equals the live Ark response.id:

SPAN gen_ai.response.id: ['021780383672524f789d4d4546194a16e88624aed779d5ca0707c']
REAL ark response.id   : ['021780383672524f789d4d4546194a16e88624aed779d5ca0707c']
RESULT: PASS

🤖 Generated with Claude Code

ADK drops the litellm response's id when building LlmResponse, so the tracer
never sees it. For Volcengine Ark that id == the x-request-id response header,
the most useful id for correlating with the provider's logs.

A pure litellm callback can read it but runs detached from the OTel context, so
it can't attach to the LLM span. Instead, a self-contained tracing module wraps
LiteLLMClient.acompletion in-context (where the raw response is available, inside
ADK's generate_content span) and sets the standard OTel GenAI attribute
gen_ai.response.id on the current span. The wrap is applied lazily only when a
VeADK OpenTelemetry tracer is created (same pattern as patch_google_adk_telemetry);
no agent.py change, no model subclass, and a no-op when tracing is off.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@zakahan zakahan merged commit f4ee445 into main Jun 2, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants