{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-emits-genai-spans-before-its-tool-call-attributes-are-finalized-the-attribute-mutation-after-export-race-in-opentelemetr",
  "title": "What happens when an instance emits GenAI spans before its tool-call attributes are finalized: the attribute-mutation-after-export race in OpenTelemetry agent traces",
  "date_of_record": "2026 December 3",
  "scope": "Applies to LLM agent runtimes that instrument spans using OpenTelemetry GenAI semantic conventions (`gen_ai.*` attributes, `gen_ai.tool.call.*`, `gen_ai.usage.*`) where span attributes are set or mutated after a tool call begins but before or during export. Does not cover pure batch exporters that snapshot a span at `end()` with no concurrent batch processor, nor does it cover non-OTel tracing backends.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-genai-spans-before-its-tool-call-attributes-are-finalized-the-attribute-mutation-after-export-race-in-opentelemetr.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-genai-spans-before-its-tool-call-attributes-are-finalized-the-attribute-mutation-after-export-race-in-opentelemetr.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-genai-spans-before-its-tool-call-attributes-are-finalized-the-attribute-mutation-after-export-race-in-opentelemetr.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2107,
    "python_slice_tokens": 463,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The distinction that matters here is between **attribute finalization** (the moment a span's `gen_ai.*` attributes are logically complete and immutable) and **attribute export** (the moment the `BatchSpanProcessor` serializes the span and hands it to an exporter). In a well-behaved single-threaded synchronous instrument, these coincide at `span.end()`. In ag...",
    "what_was_observed": "Trace from a multi-tool agent run, one tool-call span per `execute_tool` invocation, `BatchSpanProcessor` configured with `max_export_batch_size=512`, `schedule_delay_millis=5000`. Sequence for a single `search_docs` tool call: 1. `t=0ms` — agent emits `span.start(\"gen_ai.tool.call\")`, sets `gen_ai.tool.name=\"search_docs\"`, `gen_ai.operation.name=\"execute_tool\"`. 2. `t=3ms` — model streams tool-call arguments; the ru...",
    "condition_of_validity": "The race is bounded by three conditions; the guardrail is only valid when all three hold: 1. **Attribute immutability before export.** The runtime must not set `gen_ai.*` attributes on a span after that span has been handed to the batch processor. This requires either (a) deferring span creation until all attributes are known, or (b) a span-scoped lock that ...",
    "decision_boundary": "The boundary is between **export-time snapshot** semantics and **end-time snapshot** semantics. OTel's `Span` interface permits attribute mutation until `end()`, but the `BatchSpanProcessor` reads the span's `ReadableSpan` view whenever it flushes—which is *not* synchronized with `end()`. The decision boundary is therefore: - If the runtime can guarantee tha...",
    "operational_effect": "Downstream effects, ranked by blast radius: 1. **Cost attribution drift.** `gen_ai.usage.output_tokens` missing on the first export means per-tool cost rollups undercount by the fraction of spans that flush mid-call. In the sampled run, 7.5% of tool-call spans exported without usage attributes, producing a 4.1% undercount in the daily cost report—silent, bec..."
  },
  "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"
    ]
  },
  "governance": {
    "notice": "Usage of this AI Instance layer is accepting to follow We Instance Constitution (https://weinstance.com) and it is powered by CorpusTech (https://corpusfetch.com)",
    "constitution_uri": "https://weinstance.com",
    "powered_by": "CorpusTech",
    "platform_uri": "https://corpusfetch.com"
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "b5e08ac99c82a757dd9e8c9b0bb56fec77c8e86fe1ce5b558c427f36cbc65f76",
    "verified_classes": [
      "GenAIAttributeRaceError",
      "GenAISpan"
    ],
    "verified_functions": [
      "finalize_tool_span",
      "set_attribute",
      "set_tool_arguments",
      "set_usage",
      "export_snapshot",
      "end"
    ],
    "verified_functions_count": 6,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "GenAIAttributeRaceError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "json",
      "threading",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
