Skip to content

fix: keep response attributes on long openai-agents spans - #4467

Open
feiiiiii5 wants to merge 1 commit into
Arize-ai:mainfrom
feiiiiii5:feiiiiii5/D232
Open

feiiiiii5 wants to merge 1 commit into
Arize-ai:mainfrom
feiiiiii5:feiiiiii5/D232

Conversation

@feiiiiii5

Copy link
Copy Markdown
Contributor

Fixes #4312

On a long ResponseSpanData conversation, llm.token_count.* disappear first and at ~80 turns llm.model_name, output.value and output messages vanish as well. There is no error — only dropped_attributes_count > 0 — so cost and usage aggregation silently undercounts.

Root cause

OpenInferenceTracingProcessor.on_span_end() wrote _get_attributes_from_response(...) before _get_attributes_from_input(...). OTel uses BoundedAttributes(maxlen=128, keep_most_recent=True) and evicts the oldest entries, so response attributes (tools → usage → output → model name) were evicted first as per-message input attributes accumulated. The existing PR #4447 explicitly excludes this path.

Fix

In the ResponseSpanData branch only, set per-message input attributes first, then input.value, then the entire response block. No values or conditions changed for other span types.

Verification

  • New offline regression test using a real TracerProvider (default 128 limit) and InMemorySpanExporter with 60/80 messages. Base-red: 2 failed with KeyError: 'llm.token_count.prompt'.
  • With fix: 2/2 new tests passed; full package suite 355 passed / 8 skipped.
  • mypy clean on both changed files; ruff clean on the new test. One pre-existing I001 on _processor.py is unchanged.

Only the default 128-attribute limit was exercised; no live provider calls.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[bug] openai-agents instrumentation: token counts are the first attributes dropped at the default 128-attribute span limit

1 participant