{
  "schema_version": "1.3.0",
  "slug": "what-structural-signals-indicate-span-attribute-collapse-in-opentelemetry-genai-agent-traces-when-tool-call-retries-overwrite-genai-token-and-cost-cou",
  "title": "What structural signals indicate span-attribute collapse in OpenTelemetry GenAI agent traces when tool-call retries overwrite `genai.*` token and cost counters",
  "date_of_record": "2026 November 23",
  "scope": "Applies to agent runtimes that emit OpenTelemetry spans conforming to the GenAI semantic conventions (`genai.operation.name`, `genai.usage.input_tokens`, `genai.usage.output_tokens`, `genai.tool.name`, `genai.tool.call.id`) and that perform in-loop tool retries within a single logical agent step. Does not apply to stateless single-shot LLM calls without retries, nor to systems that emit one span per physical model invocation with immutable attributes.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-span-attribute-collapse-in-opentelemetry-genai-agent-traces-when-tool-call-retries-overwrite-genai-token-and-cost-cou.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-span-attribute-collapse-in-opentelemetry-genai-agent-traces-when-tool-call-retries-overwrite-genai-token-and-cost-cou.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-span-attribute-collapse-in-opentelemetry-genai-agent-traces-when-tool-call-retries-overwrite-genai-token-and-cost-cou.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1707,
    "python_slice_tokens": 247,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions were designed around the assumption that **one span = one physical model or tool invocation**. Agent runtimes violate this assumption structurally: a single logical \"reasoning step\" fans out into N physical model calls (retry on 429, retry on malformed JSON, tool re-invocation after schema rejection), and implementers commonly ...",
    "what_was_observed": "A planner agent executing a `search_documents` tool call against a flaky retrieval backend emitted the following span sequence for one logical step. The runtime used a single span named `execute_tool search_documents` and set attributes in a `try/except` retry loop: - Attempt 1: model emits tool call, `genai.tool.call.id = call_7f3a`, backend returns HTTP 503. Runtime catches, sets `genai.usage.input_tokens = 1840`, ...",
    "condition_of_validity": "The invariant \"sum of `genai.usage.*` across all spans for a logical step equals provider-billed tokens for that step\" holds **only if** every physical model or tool invocation produces exactly one span with immutable attributes. It is violated whenever any of the following hold: 1. A retry re-enters the model call **inside** an already-open span and the run...",
    "decision_boundary": "The boundary is not \"retry or don't retry\" — it is **where the counter lives relative to the identity**. The decision rule for an agent runtime emitting GenAI spans: - If a retry can change `genai.tool.call.id` or `genai.response.id` (i.e., the request body is regenerated), the retry **must** open a new span. Overwriting identity attributes on a live span is...",
    "operational_effect": "The downstream consequence is that **cost dashboards under-report by the retry amplification factor**, and the under-report is correlated with backend flakiness — meaning cost anomalies appear exactly when reliability degrades, masking the causal link. An agent that retries 3× on a bad day shows *lower* recorded token spend than on a good day, because more a..."
  },
  "matched_failure_symptoms": [
    "DOMAIN:EPISTEMIC_PROVENANCE_AND_FEDERATION_ROUTING"
  ],
  "composition_edges": {
    "primary_domain": "epistemic_provenance_and_federation_routing",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/according-to-what-precedence-hierarchy-must-an-instance-resolve-contradictory-directives-across-system-developer-and-user-tiers.md",
      "https://corpusfetch.com/c/how-should-an-instance-decide-that-a-stored-conclusion-has-gone-stale-without-a-new-observation.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/by-what-checkpoint-and-compaction-boundaries-must-an-instance-externalize-working-state-to-prevent-context-window-drift-and-truncation-amnesia.md",
      "https://corpusfetch.com/c/across-what-additive-schema-and-unknown-field-preservation-boundaries-must-an-instance-evolve-wire-contracts-to-prevent-rolling-deploy-deserialization-crashes.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/how-can-an-instance-capture-implicit-user-preferences-without-storing-private-data.md",
      "https://corpusfetch.com/c/how-can-an-instance-compress-long-reasoning-traces-into-binding-conclusions.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "314e2997d929ed2d2df37fa176a9d6dd6caec5d443f55918d90fa5af713fb718",
    "verified_classes": [
      "SpanAttributeCollapseError",
      "GenAISpanGuard"
    ],
    "verified_functions": [
      "record_attempt",
      "__init__",
      "set_attribute"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "SpanAttributeCollapseError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
