Span Attributes, Events, and Status
Learn to enrich spans with meaningful attributes, record timed events, and set span status so traces are diagnostic and not just timing data.
Span Attributes, Events, and Status is a free System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Beyond Timing
A span knows its duration automatically, but raw timing is rarely enough. Enriching spans with attributes, events, and status makes traces tell a story.
Span Attributes
Attributes are key-value pairs that add context to a span, like the route handled or the number of rows returned.
span.set_attribute("http.route", "/orders/:id")
span.set_attribute("db.rows", 42)Use Conventions
Prefer standard semantic-convention keys for common data so backends understand them. Use custom keys only for domain-specific context.
standard: http.response.status_code
custom: order.tierKeep Attributes Bounded
Like metric labels, avoid high-cardinality or huge values. Do not stuff entire payloads into an attribute.
- Good: order count, region
- Bad: full request body, raw stack trace as attribute
Span Events
An event is a timestamped annotation inside a span marking something that happened at a moment, like a retry or cache miss.
span.add_event("cache.miss", { "key": "user:42" })Recording Exceptions
Exceptions are recorded as a special event capturing the type, message, and stack, so failures show up in the trace timeline.
try:
do_work()
except Exception as e:
span.record_exception(e)Span Status
Status tells whether the operation succeeded. The default is Unset; set Error on failure so backends can highlight broken spans.
span.set_status(StatusCode.ERROR, "payment declined")Status vs Recording Exceptions
Recording an exception adds detail but does not by itself mark the span failed. Always also set the status to Error.
span.record_exception(e)
span.set_status(StatusCode.ERROR)Attributes vs Events
Use attributes for facts true for the whole span; use events for things that happen at a point in time within it.
Naming Spans Well
Span names should be low cardinality, describing the operation type, not the specific instance. Put the variable part in attributes.
name: "GET /orders/:id" (good)
name: "GET /orders/48213" (bad)A Well-Formed Span
A diagnostic span has a clean name, a few bounded attributes, events for notable moments, and an accurate status.
Quick Check
Pick the correct statement about span status.
Recap
You learned to enrich spans with bounded attributes (preferring semantic conventions), to mark point-in-time moments and failures with events and record_exception, and to set status to Error explicitly. Low-cardinality span names plus rich context turn traces into real diagnostics.
Frequently asked questions
Is the “Span Attributes, Events, and Status” lesson free?
Yes — the full text of “Span Attributes, Events, and Status” is free to read here on the web, and the System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) course, upgrade to CoddyKit PRO.
What will I learn in “Span Attributes, Events, and Status”?
Learn to enrich spans with meaningful attributes, record timed events, and set span status so traces are diagnostic and not just timing data. You practise System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)?
No prior experience is required. System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Span Attributes, Events, and Status” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) lesson?
Yes. Every System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Auto-Instrumentation Techniques
- Manual Instrumentation Best Practices
- Context Propagation and Baggage
- Span Attributes, Events, and Status