Observability

What Is a Span Event?

A timestamped occurrence attached to one span that records an important moment, error, retry, streamed chunk, or evaluation result.

What Is a Span Event?

A span event is a timestamped occurrence recorded inside one span in an LLM or agent observability trace. It marks something important that happened during the operation, such as a retry, exception, streamed output chunk, tool milestone, guardrail verdict, or evaluator result. Unlike a span attribute, which describes the span, a span event preserves event order inside the production trace without creating another child span. FutureAGI traceAI uses span events to make failures and eval results queryable.

Why Span Events Matter in Production LLM and Agent Systems

Most AI incidents are not just “the request failed.” They are ordered chains of smaller moments: the first model call streamed partial output, the retriever returned no policy chunk, the agent retried a tool, the retry timed out, and the fallback answer passed syntax checks but failed grounding. A span can show the operation duration. Span events show the notable moments inside that operation.

Ignoring span events creates two common failure modes. First, transient failures disappear. A tool span may finish successfully after a retry, while the expensive retry itself remains invisible. Second, quality failures lose timing. A Groundedness or ToolSelectionAccuracy result may exist somewhere in the eval store, but responders cannot tell whether it belonged to the original answer, the fallback answer, or the post-guardrail rewrite.

The pain lands differently by role. Developers lose the sequence that explains why an agent took the wrong branch. SREs see a p99 latency spike without knowing whether the added time came from retries, streaming stalls, or eval callbacks. Compliance teams cannot prove when a guardrail decision occurred relative to tool execution. Product teams see user complaints but cannot separate slow answers from wrong answers.

This is more important for 2026 multi-step pipelines than for single-turn chat. Agentic systems create many meaningful moments inside each span: planner decisions, tool retries, memory reads, handoffs, guardrail checks, evaluator verdicts, and fallback triggers. Unlike raw logs in Datadog or CloudWatch, span events keep those moments inside the parent span timeline instead of forcing responders to reconstruct order from loosely correlated timestamps.

How FutureAGI Handles Span Events

FutureAGI’s approach is to treat span events as the timeline layer between span attributes and full child spans. In a traceAI-langchain support agent, traceAI emits spans for the chain, retriever, LLM call, tool call, and guardrail. The LLM span may carry fi.span.kind="LLM", llm.token_count.prompt, and gen_ai.request.model as attributes. Events then capture timestamped moments inside that span.

A real workflow looks like this. A refund assistant answers from retrieved policy context. The LLM span streams output, then FutureAGI runs Groundedness on the answer and attaches an event with gen_ai.evaluation.name="Groundedness", gen_ai.evaluation.score.value=0.42, gen_ai.evaluation.explanation, and gen_ai.evaluation.target_span_id. The same trace may include a tool span with a tool.retry event and a guardrail span with a post_guardrail.blocked event.

The engineer’s next move is concrete. If Groundedness drops below 0.7 for the refund-policy-v5 cohort, the alert opens the failing trace, highlights the event, and shows the surrounding retriever and LLM spans. If ToolSelectionAccuracy failures cluster after a prompt release, the team compares event counts by prompt version, then runs a regression eval before rolling forward. If retries drive cost, Agent Command Center can route the affected cohort through model fallback while the tool owner fixes the upstream timeout.

This is different from treating eval results as detached rows. The event sits inside the trace, so the score, explanation, token count, model, prompt version, and upstream retrieval context remain inspectable together.

How to Measure or Detect Span Events

Span events are measured by coverage, rate, and correlation with user-visible failures:

  • Event coverage: percentage of LLM, TOOL, GUARDRAIL, and EVALUATOR spans that emit expected events; production target should be 99% for required events.
  • Exception-event rate: count of exception, tool.retry, and timeout events per 1,000 traces, grouped by fi.span.kind and service.
  • Eval-event quality: distribution of gen_ai.evaluation.score.value by evaluator name, prompt version, model, route, and tenant cohort.
  • Cost correlation: token-cost-per-trace when retry events or fallback events appear, using llm.token_count.prompt and output-token fields.
  • User proxy: thumbs-down rate and escalation rate for traces containing low-score evaluation events.
from opentelemetry import trace

tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("refund_tool") as span:
    span.add_event("tool.retry", {"retry.count": 1, "error.type": "TimeoutError"})

A useful dashboard starts with event count per trace, event rate by span kind, low-score eval events by cohort, and p99 span duration for traces that contain retry events.

Common Mistakes

Span events are easy to misuse because they sit between logs and child spans:

  • Using events for long-running work. If duration matters, create a child span instead of one timestamped event.
  • Emitting every streamed token as an event. Capture milestones or sampled chunks, or event volume will hide the incident.
  • Treating attributes and events as interchangeable. Stable query dimensions belong on attributes; ordered occurrences belong in events.
  • Dropping gen_ai.evaluation.target_span_id. Evaluation events become hard to trust when no one can identify the scored span.
  • Writing raw prompts or PII into event attributes. Redact or summarize before export, then keep sensitive content out of indexed fields.

Frequently Asked Questions

What is a span event?

A span event is a timestamped record inside one span that marks an important moment, such as a retry, exception, streamed chunk, guardrail decision, or evaluator result.

How is a span event different from a span attribute?

A span attribute describes the span as key/value metadata, usually for filtering or grouping. A span event records something that happened at a specific timestamp during that span.

How do you measure span events?

FutureAGI traceAI surfaces span events through fields such as `gen_ai.evaluation.name`, `gen_ai.evaluation.score.value`, and `gen_ai.evaluation.target_span_id`; dashboards track event rate, exception-event rate, and eval-fail-rate-by-cohort.