Attributi, eventi e stato degli span
Impari ad arricchire gli span con attributi significativi, registrare eventi temporizzati e impostare lo stato degli span, così che le trace siano diagnostiche e non semplici dati temporali.
Attributi, eventi e stato degli span è una lezione System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry), e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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.
Impara System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) con un tutor IA — gratis
Scrivi ed esegui vero codice nel tuo browser, ricevi aiuto istantaneo da un tutor IA disponibile 24/7, e riprendi da dove hai lasciato sul web o nell'app.
- Corsi
- 12
- Lezioni
- 48
Domande Frequenti
La lezione «Attributi, eventi e stato degli span» è gratuita?
Sì — il testo completo di «Attributi, eventi e stato degli span» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry), passa a CoddyKit PRO. Il corso System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) include 4 lezioni in totale.
Cosa imparerò in «Attributi, eventi e stato degli span»?
Impari ad arricchire gli span con attributi significativi, registrare eventi temporizzati e impostare lo stato degli span, così che le trace siano diagnostiche e non semplici dati temporali. Eserciti System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)?
Non è richiesta alcuna esperienza precedente. System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.
Quanto tempo richiede la lezione «Attributi, eventi e stato degli span»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)?
Sì. Ogni lezione System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Tecniche di auto-instrumentation
- Buone pratiche per la strumentazione manuale
- Propagazione del contesto e baggage
- Attributi, eventi e stato degli span