{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-of-the-opentelemetry-genai-semantic-conventions-silently-under-report-token-usage-when-an-agent-span-contains-nested-tool-call-sp",
  "title": "Why does an instance of the OpenTelemetry GenAI semantic conventions silently under-report token usage when an agent span contains nested tool-call spans that are themselves instrumented by a second SDK",
  "date_of_record": "2026 November 11",
  "scope": "Applies to agent-style OTel instrumentation that emits `gen_ai.*` attributes across an `invoke_agent` span with nested `execute_tool` children, where more than one instrumentation library (e.g., a vendor SDK plus a framework auto-instrumentor) is active in the same process. Does not apply to single-library setups, nor to spans that carry no `gen_ai.usage.input_tokens`/`output_tokens` attributes at all.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-of-the-opentelemetry-genai-semantic-conventions-silently-under-report-token-usage-when-an-agent-span-contains-nested-tool-call-sp.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-of-the-opentelemetry-genai-semantic-conventions-silently-under-report-token-usage-when-an-agent-span-contains-nested-tool-call-sp.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-of-the-opentelemetry-genai-semantic-conventions-silently-under-report-token-usage-when-an-agent-span-contains-nested-tool-call-sp.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1470,
    "python_slice_tokens": 364,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define token accounting as a *span-local* attribute pair (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) that describes the model call that the span represents. They do **not** define an aggregation contract across a span hierarchy. A span that represents an agent turn is therefore *not* required to equal the sum of...",
    "what_was_observed": "In a two-library deployment (framework auto-instrumentor emitting `invoke_agent` + `execute_tool`, plus a vendor client SDK emitting `gen_ai.chat` for the underlying completion), the following was reproducible across runs: 1. The `invoke_agent` span carried `gen_ai.usage.input_tokens` equal to the **first** model call's prompt only, not the cumulative prompt across the agent's ReAct loop. The auto-instrumentor set us...",
    "condition_of_validity": "The under-count is valid (i.e., the agent span is not a rollup) precisely when **all** of the following hold: - The agent span is emitted by a library that sets usage from the first observed completion and does not re-aggregate on span end. - At least one additional, separately-instrumented model-call span exists in the trace (second SDK, or a manually-creat...",
    "decision_boundary": "Do not treat `invoke_agent` usage as a cost rollup unless you have verified the emitting library aggregates at span end. The safe operational rule: - **For cost/accounting:** sum `gen_ai.usage.*` only over spans where `gen_ai.operation.name == \"chat\"` (or the equivalent model-call operation), and de-duplicate by `gen_ai.response.id` if present. Never sum acr...",
    "operational_effect": "Cost dashboards built on `invoke_agent` usage under-report agent workloads by the fraction of tokens spent after the first tool call — often the majority in tool-heavy agents. Alerting on token-budget exhaustion from the agent span therefore fires late or never. The fix is not to patch the numbers but to change the query surface: make the aggregation key `(t..."
  },
  "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": "91e1e847d62bb5a20d1eeb35f3fda7778b498877a98d0b96781fd50bf3e68dca",
    "verified_classes": [
      "GenAIUsageAggregationError"
    ],
    "verified_functions": [
      "aggregate_usage"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "GenAIUsageAggregationError"
    ],
    "sample_fail_closed_invariants": [
      "Trace contains both agent-level usage and per-call chat usage; summing both double-counts. Choose one token source: eith",
      "execute_tool span carries gen_ai.usage.*; tool calls are not model calls and must not report token usage under the GenAI"
    ],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
