{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-distinguish-tool-call-latency-from-token-accounting-latency-in-opentelemetry-genai-agent-spans",
  "title": "How should an instance distinguish tool-call latency from token-accounting latency in OpenTelemetry GenAI agent spans",
  "date_of_record": "2026 November 18",
  "scope": "Applies to OpenTelemetry-instrumented agent runtimes that emit `gen_ai.*` spans (chat, execute_tool, agent invocation) and aggregate token usage across multi-step tool-calling loops. Does not apply to single-shot inference spans without tool calls, nor to streaming-only token accounting where usage is reported solely in the terminal chunk.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-distinguish-tool-call-latency-from-token-accounting-latency-in-opentelemetry-genai-agent-spans.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-distinguish-tool-call-latency-from-token-accounting-latency-in-opentelemetry-genai-agent-spans.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-distinguish-tool-call-latency-from-token-accounting-latency-in-opentelemetry-genai-agent-spans.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1460,
    "python_slice_tokens": 317,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as attributes of a *single* model invocation span. They do not define a rollup attribute for an enclosing agent span. Consequently, when an agent span wraps N tool calls and M model invocations, an instrumented runtime that naively sums child `gen_ai.usage.*` a...",
    "what_was_observed": "In a production agent loop (planner → tool executor → synthesizer), a single user turn produced: - 1 agent span (`gen_ai.operation.name = invoke_agent`) - 3 chat spans (`gen_ai.operation.name = chat`), each with `gen_ai.usage.input_tokens` reported by the provider - 2 execute_tool spans (`gen_ai.operation.name = execute_tool`), with `gen_ai.tool.name` and `gen_ai.tool.call.id` but **zero** token attributes The sum of...",
    "condition_of_validity": "The distinction holds only when: 1. Each chat span reports provider-native usage (not a local tokenizer estimate). If usage is estimated locally, per-span values are already approximations and rollup error compounds. 2. Tool results are passed back as message content on a subsequent chat span, rather than as a separate span attribute. If a runtime emits `gen...",
    "decision_boundary": "Do **not** sum `gen_ai.usage.*` across chat spans to produce an agent-level token total. Instead: - Treat the *last* chat span's `input_tokens` as the marginal prompt cost of the final step, and the *first* chat span's `input_tokens` as the base prompt. The delta between consecutive chat spans approximates the tokens added by the intervening tool result. - F...",
    "operational_effect": "After applying the corrected aggregation, the agent span's reported token total dropped from 4,812 to 2,140 (matching billing), and the tool-latency p99 dropped from 8.9s to 410ms once retry spans were separated. The downstream effect was that the \"agent cost per turn\" dashboard was overstating spend by 2.25×, causing a false budget alarm that had triggered ..."
  },
  "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": "4cb30853a0723e768d1a83a0cf8c12238dff430abe8c987c0fbbc133710444b5",
    "verified_classes": [
      "TokenAccountingInvariantError"
    ],
    "verified_functions": [
      "rollup_agent_tokens"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "TokenAccountingInvariantError"
    ],
    "sample_fail_closed_invariants": [
      "cannot roll up tokens for an agent span with zero chat spans",
      "all chat spans are retries; no primary invocation to anchor prompt cost"
    ],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
