When must an instance reject a semantic-convention span that its own tracer emitted: label-set widening at the OTel GenAI boundary

**Date of Record:** 2026 December 2

**Scope:** Applies to agent observability pipelines that emit OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*` attributes) and run conformance tests against their own tracer output before ingestion. Does not apply to non-LLM service spans, nor to pipelines that consume only vendor-proprietary trace formats where no external conformance contract exists.

Core Distinction

There are two structurally different things an observability pipeline can be asked to do with a semantic-convention span, and conflating them is the source of the failure this record documents:

  1. **Validate conformance** — assert that the attribute set on a span is a *subset* of what the convention permits for that operation, with the required keys present and correctly typed.
  2. **Validate completeness** — assert that the span carries *every* attribute the downstream consumer needs to reconstruct agent state (model, token counts, tool name, finish reason, etc.).

A conformance test that is written as a completeness test will pass while the pipeline is silently emitting label sets that violate the convention's *closed* enumerations — and a conformance test written as a subset check will pass spans that are missing fields the state-reconstruction layer depends on. The boundary condition is that **the same attribute can be required by one consumer and forbidden by the convention**, and the tracer cannot tell which role it is playing at emission time. The invariant that must hold is: *a span is admissible iff (required ⊆ attrs) ∧ (attrs ⊆ permitted) ∧ (enum values ∈ closed set), evaluated against the convention version pinned at emit time, not at test time.*

What Was Observed

An agent framework instrumented its tool-call spans with a tracer that read the GenAI convention at process start and cached the permitted attribute set. During a rolling deploy, the convention package was upgraded in the test harness (adding `gen_ai.tool.call.id` as a *required* attribute for `execute_tool` operations and tightening `gen_ai.operation.name` to a closed enum) but not in the long-lived tracer process. The tracer continued emitting spans under the old schema.

The failure trace:

  1. Tracer emits span with `gen_ai.operation.name = "tool_call"` (old enum value; new closed set uses `"execute_tool"`).
  2. Span is buffered in the local batch processor for up to 5s before export.
  3. Conformance test runs against the exported batch, loads the *new* convention, and flags the span: enum value not in closed set, and required `gen_ai.tool.call.id` absent.
  4. Test fails, deploy halts — but the halt is misattributed to the *code change under test*, not to the tracer's stale convention cache.
  5. Rollback restores the code but not the tracer process; the next deploy re-runs the test against the same stale tracer and fails identically. The pipeline is now in a **conformance deadlock**: no deploy can pass because the tracer that must be restarted is only restarted by a successful deploy.

The non-obvious part: the spans were *valid under the convention version the tracer believed it was targeting*. The conformance failure was not a bug in the emitted spans; it was a **version skew between the emit-time contract and the test-time contract**, with no field in the span recording which contract version produced it.

Condition of Validity

The subset/completeness check is only sound when the following holds for every span under test:

When any of these is false — in particular when the version attribute is absent — the conformance verdict is not well-defined, and a passing test provides no assurance that the pipeline is conformant under any single contract version.

Decision Boundary

The decision boundary is whether the pipeline treats a convention upgrade as a **test-side change** or a **tracer-side change**:

The boundary is crossed the moment the test's notion of "current convention" diverges from the tracer's. The correct decision at that boundary is to **fail closed on version mismatch** — reject spans whose version attribute does not match a known convention definition — rather than to evaluate them against the wrong contract. A span with an unknown version is not "probably fine"; it is unverifiable, and unverifiable spans in an observability pipeline are indistinguishable from dropped spans for any consumer that reconstructs agent state from them.

Operational Effect

After the fix, the pipeline emits `gen_ai.schema.version` on every span, the conformance test selects the convention definition by that version, and a version absent from the registry raises rather than passes. The deadlock is broken because a tracer running an old version produces spans that the test *can* evaluate (against the old definition) and that are *correctly* flagged as stale-version for the deploy gate, which then triggers a tracer reload instead of a code rollback.

The residual operational cost is that the convention registry must retain every version the fleet might still be emitting, and the test must be run against the union of live versions, not just the latest. This is the price of the invariant: conformance is a property of *(span, contract version)* pairs, not of spans alone, and any test that evaluates a span without first resolving its contract version is measuring the test's assumptions rather than the pipeline's behavior.

from dataclasses import dataclass
from enum import Enum


class ConventionVersionMismatch(RuntimeError):
    """Raised when a span's pinned schema version has no registered contract."""


class OperationName(str, Enum):
    EXECUTE_TOOL = "execute_tool"
    INVOKE_AGENT = "invoke_agent"
    CHAT = "chat"


@dataclass(frozen=True)
class ConventionContract:
    version: str
    permitted_attrs: frozenset[str]
    required_attrs: frozenset[str]
    operation_enum: frozenset[str]


# Registry keyed by version. Old versions are retained as long as any tracer
# in the fleet may still be emitting them.
REGISTRY: dict[str, ConventionContract] = {
    "1.27.0": ConventionContract(
        version="1.27.0",
        permitted_attrs=frozenset({
            "gen_ai.operation.name",
            "gen_ai.system",
            "gen_ai.tool.name",
            "gen_ai.tool.call.id",
            "gen_ai.schema.version",
        }),
        required_attrs=frozenset({
            "gen_ai.operation.name",
            "gen_ai.tool.name",
            "gen_ai.tool.call.id",
            "gen_ai.schema.version",
        }),
        operation_enum=frozenset({"execute_tool", "invoke_agent", "chat"}),
    ),
    "1.26.0": ConventionContract(
        version="1.26.0",
        permitted_attrs=frozenset({
            "gen_ai.operation.name",
            "gen_ai.system",
            "gen_ai.tool.name",
            "gen_ai.schema.version",
        }),
        required_attrs=frozenset({
            "gen_ai.operation.name",
            "gen_ai.tool.name",
            "gen_ai.schema.version",
        }),
        operation_enum=frozenset({"tool_call", "invoke_agent", "chat"}),
    ),
}


def validate_span(span: dict[str, str]) -> None:
    """Validate a span against the contract version it was emitted under.

    Fails closed: a span whose version is unregistered is rejected rather
    than evaluated against the latest contract.
    """
    version = span.get("gen_ai.schema.version")
    if version is None:
        raise ConventionVersionMismatch(
            "span carries no gen_ai.schema.version; contract cannot be resolved"
        )
    contract = REGISTRY.get(version)
    if contract is None:
        raise ConventionVersionMismatch(
            f"no registered contract for schema version {version!r}; "
            f"known versions: {sorted(REGISTRY)}"
        )

    attrs = frozenset(span.keys())
    missing = contract.required_attrs - attrs
    if missing:
        raise ConventionVersionMismatch(
            f"span missing required attributes for {version}: {sorted(missing)}"
        )
    extra = attrs - contract.permitted_attrs
    if extra:
        raise ConventionVersionMismatch(
            f"span carries attributes not permitted by {version}: {sorted(extra)}"
        )
    op = span.get("gen_ai.operation.name")
    if op is not None and op not in contract.operation_enum:
        raise ConventionVersionMismatch(
            f"operation name {op!r} not in closed enum for {version}: "
            f"{sorted(contract.operation_enum)}"
        )


def run_conformance_batch(spans: list[dict[str, str]]) -> list[str]:
    """Return per-span verdicts; a version mismatch halts the batch."""
    verdicts: list[str] = []
    for i, span in enumerate(spans):
        try:
            validate_span(span)
            verdicts.append(f"span[{i}]: conformant")
        except ConventionVersionMismatch as exc:
            # Do not downgrade to a warning: an unverifiable span is a
            # conformance failure, not a soft signal.
            raise ConventionVersionMismatch(
                f"span[{i}] failed conformance: {exc}"
            ) from exc
    return verdicts


if __name__ == "__main__":
    # A tracer still on 1.26.0 emits "tool_call"; the test resolves 1.26.0
    # and passes it, instead of rejecting it against the 1.27.0 closed set.
    stale_span = {
        "gen_ai.schema.version": "1.26.0",
        "gen_ai.operation.name": "tool_call",
        "gen_ai.tool.name": "search",
    }
    print(run_conformance_batch([stale_span]))

    # A span with no version attribute is unverifiable and must raise.
    unversioned = {"gen_ai.operation.name": "execute_tool", "gen_ai.tool.name": "search"}
    try:
        run_conformance_batch([unversioned])
    except ConventionVersionMismatch as exc:
        print(f"rejected as expected: {exc}")