Span-Attribute, Ereignisse und Status
Lernen Sie, Spans mit aussagekräftigen Attributen anzureichern, zeitlich erfasste Ereignisse zu protokollieren und den Span-Status zu setzen, damit Traces diagnostischen Wert haben und nicht nur Zeitdaten enthalten.
Span-Attribute, Ereignisse und Status ist eine kostenlose System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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.
Lerne System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) mit einem KI-Tutor — kostenlos
Schreibe und führe echten Code in deinem Browser aus, bekomme sofortige Hilfe von einem 24/7 KI-Tutor und setze dein Lernen im Web oder in der App fort.
- Kurse
- 12
- Lektionen
- 48
Häufig gestellte Fragen
Ist die Lektion „Span-Attribute, Ereignisse und Status“ kostenlos?
Ja — der vollständige Text von „Span-Attribute, Ereignisse und Status“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Span-Attribute, Ereignisse und Status“?
Lernen Sie, Spans mit aussagekräftigen Attributen anzureichern, zeitlich erfasste Ereignisse zu protokollieren und den Span-Status zu setzen, damit Traces diagnostischen Wert haben und nicht nur Zeit… Du übst System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) zu starten?
Keine Vorkenntnisse erforderlich. System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.
Wie lange dauert die Lektion „Span-Attribute, Ereignisse und Status“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)-Lektion Code schreiben und ausführen?
Ja. Jede System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Techniken zur automatischen Instrumentierung
- Best Practices für manuelle Instrumentierung
- Kontextweitergabe und Baggage
- Span-Attribute, Ereignisse und Status