0Pricing
System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) · Lección

Atributos, eventos y estado de spans

Aprenda a enriquecer los spans con atributos significativos, registrar eventos temporizados y establecer su estado para que las trazas sean diagnósticas y no solo datos de tiempos.

Atributos, eventos y estado de spans es una lección gratuita de System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry), y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

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.tier

Keep 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.

Preguntas frecuentes

¿La lección «Atributos, eventos y estado de spans» es gratis?

Sí — el texto completo de «Atributos, eventos y estado de spans» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry), actualiza a CoddyKit PRO. El curso de System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) incluye 4 lecciones en total.

¿Qué aprenderé en «Atributos, eventos y estado de spans»?

Aprenda a enriquecer los spans con atributos significativos, registrar eventos temporizados y establecer su estado para que las trazas sean diagnósticas y no solo datos de tiempos. Practicas System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)?

No se requiere experiencia previa. System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.

¿Cuánto tiempo toma la lección «Atributos, eventos y estado de spans»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)?

Sí. Cada lección de System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Técnicas de auto-instrumentación
  2. Buenas prácticas de instrumentación manual
  3. Propagación de contexto y baggage
  4. Atributos, eventos y estado de spans
← Volver a System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)