{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-reconcile-opentelemetry-genai-span-attributes-before-export-and-why-the-tool-call-attribute-contract-fractures-at-the-span-clos",
  "title": "Where must an instance reconcile OpenTelemetry GenAI span attributes before export, and why the tool-call attribute contract fractures at the span-close boundary",
  "date_of_record": "2026 November 24",
  "scope": "Applies to any agent runtime that emits OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) for LLM inference, tool execution, and token/cost accounting, where spans are buffered, batched, or exported asynchronously after context teardown. Does not apply to synchronous streaming exporters that finalize attributes before the span object is released, nor to non-OTel telemetry pipelines.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-attributes-before-export-and-why-the-tool-call-attribute-contract-fractures-at-the-span-clos.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-attributes-before-export-and-why-the-tool-call-attribute-contract-fractures-at-the-span-clos.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-attributes-before-export-and-why-the-tool-call-attribute-contract-fractures-at-the-span-clos.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2012,
    "python_slice_tokens": 434,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat a span as a mutable attribute bag that is *read* at export time, not a snapshot frozen at the moment of the semantic event. This distinction is invisible until the moment an agent instance tears down the context that owns the mutable state feeding those attributes. A tool-call span is opened when the model emits a tool-ca...",
    "what_was_observed": "A multi-step agent executing a three-tool chain (search → fetch → summarize) under a 32k context budget. The runtime opened one `gen_ai.tool.call` span per tool invocation and one parent `gen_ai.chat` span for the reasoning turn. Attributes were set via a thin wrapper that read from a per-turn `TurnContext` dataclass holding the live token counters and the tool-call ledger. Trigger condition: the summarizer step satu...",
    "condition_of_validity": "The invariant that must hold: **every `gen_ai.*` attribute on a span must be materialized to an immutable value before `span.end()` returns, and no attribute dict may be shared by reference with any state that outlives the span's owning scope.** This is valid only when: - The span's attributes are copied (deep, not aliased) at `end()` time, or the exporter i...",
    "decision_boundary": "The boundary is not \"use batch vs. simple processor.\" It is: **does any attribute value's lifetime exceed the span's owning scope?** - If yes → you must snapshot at `end()`. The batch processor is safe *only if* attributes are frozen before enqueue. The correct guardrail is a `finalize_attributes()` call inside the span wrapper that copies the live counters ...",
    "operational_effect": "When the invariant is violated, the operational effect is a class of *silent telemetry corruption* that is worse than missing telemetry: 1. **Cost attribution drifts toward zero** across compacted turns — the expensive early turns (large context, many input tokens) are exactly the ones most likely to be compacted, so the corruption is biased toward undercoun..."
  },
  "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": "20f6b6765e0dbee97c2d4453081b0d1f37160c537dba8e1779cfc971b2555a70",
    "verified_classes": [
      "GenAISpanContractError",
      "TurnContext",
      "GenAISpan"
    ],
    "verified_functions": [
      "export_span",
      "set_attribute",
      "finalize",
      "validate"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "GenAISpanContractError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "copy",
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
