Overview
TheTraceCtrlSpanProcessor is an OpenTelemetry SpanProcessor that runs on every span. It reads framework-set attributes and adds TraceCtrl security context — agent identity, tool risk classification, session correlation, and prompt integrity hashing.
Enrichment Pipeline
For each span, the processor runs these enrichment steps:Session ID
On span start, attaches the current
tracectrl.session_id from context vars. This ensures every span in a session is correlated.Agent Identity
For
AGENT spans, derives tracectrl.agent.id and tracectrl.agent.name from framework-specific attributes (e.g., Agno’s agno.agent.id, OpenInference’s agent.name). If only a name exists, the ID is derived as name.lower().replace(' ', '-').Tool Category
For spans with a
tool.name attribute, classifies the tool into one of 8 risk categories and sets tracectrl.tool.category.System Prompt Hash
For spans with
llm.system (the system prompt), computes a SHA-256 hash (truncated to 16 hex chars) and stores it as tracectrl.system_prompt_hash. A change in this hash between observations indicates prompt drift or tampering.Using the Processor Directly
The processor is automatically registered when you call.instrument() on any instrumentor. If you need to use it with a custom TracerProvider:
Prompt Drift Detection
Thetracectrl.system_prompt_hash attribute enables detecting when an agent’s system prompt changes unexpectedly:

