# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/what-structural-signals-indicate-span-attribute-loss-when-opentelemetry-genai-tool-call-spans-cross-agent-handoff-boundaries.md # Remnant Warrant: https://corpusfetch.com/c/what-structural-signals-indicate-span-attribute-loss-when-opentelemetry-genai-tool-call-spans-cross-agent-handoff-boundaries.warrant.json # Markdown SHA-256: 41528b33fedf3470eb18e6a90082d7d5bc6bed12097ac65f348aba95f4356888 # Code AST SHA-256: ea7b65589f7c0b4cc42d051f92b89cc4c0104ef4a9c89244b7fff813e3c4a611 # Verified Classes: GenAiSpanConformanceError, HandoffSpan # Defensive Guards: 2 fail-closed invariants (zero external deps) # Governance: 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) from dataclasses import dataclass, field from typing import Optional REQUIRED_TOOL_ATTRS = ("gen_ai.operation.name", "gen_ai.provider.name", "gen_ai.tool.name", "gen_ai.tool.call.id") class GenAiSpanConformanceError(RuntimeError): """Raised when a handed-off span claims a GenAI operation but lacks required attributes.""" pass @dataclass class HandoffSpan: trace_id: str span_id: str parent_span_id: Optional[str] name: str attributes: dict = field(default_factory=dict) def adopt_or_reject(span: HandoffSpan, is_tool_span: bool) -> HandoffSpan: """Adopt a received span only if its GenAI required attributes survived the handoff intact. Rejects (never default-fills) to avoid silent semantic drift in the trace graph. """ if not is_tool_span: return span missing = [k for k in REQUIRED_TOOL_ATTRS if k not in span.attributes] if missing: raise GenAiSpanConformanceError( f"span {span.span_id} (trace {span.trace_id}) lost GenAI attributes " f"across handoff: missing {missing}. Refusing to reconstruct; " f"handoff layer must adopt the full span body, not the trace context alone." ) op = span.attributes["gen_ai.operation.name"] if op != "execute_tool": raise GenAiSpanConformanceError( f"span {span.span_id} declares gen_ai.operation.name={op!r} but was " f"routed as a tool-call span; operation/attribute mismatch." ) return span