{
  "schema_version": "1.3.0",
  "slug": "what-structural-signals-indicate-span-attribute-loss-during-opentelemetry-genai-semantic-convention-export-from-mid-flight-agent-turns",
  "title": "What structural signals indicate span-attribute loss during OpenTelemetry GenAI semantic-convention export from mid-flight agent turns",
  "date_of_record": "2026 December 1",
  "scope": "Applies to agents that emit OpenTelemetry spans using the GenAI semantic conventions (`gen_ai.*` attributes) for LLM inference, tool-call, and agent-turn spans, where spans are finalized and exported asynchronously by a batch processor. Does not apply to synchronous in-process exporters that block the agent loop, nor to purely metric-based token accounting.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-span-attribute-loss-during-opentelemetry-genai-semantic-convention-export-from-mid-flight-agent-turns.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-span-attribute-loss-during-opentelemetry-genai-semantic-convention-export-from-mid-flight-agent-turns.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-span-attribute-loss-during-opentelemetry-genai-semantic-convention-export-from-mid-flight-agent-turns.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1591,
    "python_slice_tokens": 226,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"telemetry is missing.\" The failure is **attribute divergence between the span as it was opened and the span as it is exported**, caused by mutating `gen_ai.*` attributes *after* the span has been ended but *before* the BatchSpanProcessor flushes it — or, more commonly, by the agent loop writing token-usage and finish-reason attributes in ...",
    "what_was_observed": "A multi-turn agent executing a streaming chat completion with tool calls produced spans with the following signature when inspected at the collector: - `gen_ai.operation.name = \"chat\"` present. - `gen_ai.system = \"openai\"` present. - `gen_ai.request.model` present. - `gen_ai.usage.input_tokens` **absent** on ~18% of spans, `0` on another ~9%. - `gen_ai.response.finish_reasons` absent on the same spans. - Span duratio...",
    "condition_of_validity": "The invariant that must hold for GenAI span telemetry to be trustworthy: > For every span where `gen_ai.operation.name` is set, all `gen_ai.usage.*` and `gen_ai.response.*` attributes MUST be assigned before `span.end()` is called, and the span MUST NOT be ended by a context manager whose exit ordering precedes attribute resolution. This is violated whenever...",
    "decision_boundary": "The boundary is between **attribute-at-end semantics** and **attribute-at-open semantics**. The GenAI conventions are attribute-at-end: they describe the *completed* inference. The SDK's span object is attribute-at-open with a hard cutoff at `end()`. Any agent architecture that resolves GenAI attributes lazily crosses this boundary and loses them. Operationa...",
    "operational_effect": "Without the guardrail, the downstream effects compound: - **Cost invariants break silently.** A `0`-token span is indistinguishable from a genuinely empty completion at the collector. Budget alarms computed from `sum(gen_ai.usage.output_tokens)` undercount by the fraction of tool-call turns, which is precisely the expensive fraction. - **Budget enforcement d..."
  },
  "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": "117d2e45c2d36ef54c98ea06bb5e48777f7d0eceee80b163cd05d1d219237371",
    "verified_classes": [
      "GenAISpanAttributeLoss",
      "GenAISpan"
    ],
    "verified_functions": [
      "finalize_chat_span",
      "set_attribute",
      "end"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "GenAISpanAttributeLoss"
    ],
    "sample_fail_closed_invariants": [
      "span already ended before finalize"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
