- If the timing of the action matters, use a span event.
- If it’s descriptive context about the span, use an attribute.
- A user uploads a file and a virus scan runs during that flow.
- Detecting a virus is a point-in-time action — it occurred at a specific moment during the span. Use a span event for that.
- Details like file type and file size describe the span but are not tied to a single instant. Use span attributes for those.
Use span events for time-specific occurrences and span attributes for persistent metadata describing the span.
- Timestamps
- Span events include timestamps — they represent something that happened at a particular instant.
- Span attributes do not carry separate timestamps; the span’s start/end times provide the temporal context.
- Use cases for span events
- Exceptions, errors, retries, milestones, logs — anything you want to mark at a specific moment.
- Events can include their own attributes (for example,
error.type,message).
- Use cases for span attributes
- Persistent metadata and context for the entire span — e.g.,
db.system,http.method,http.response.status_code,user.id,payment.method,file.type,file.size_kb.
- Persistent metadata and context for the entire span — e.g.,
- Durations
- If you need to represent an interval, rely on span start/end timestamps or a nested child span. Span events are single instants and cannot represent durations by themselves.
- Exceptions
- Exceptions are typically captured as events (many telemetry SDKs provide
record_exceptionor an equivalent that generates an event).
- Exceptions are typically captured as events (many telemetry SDKs provide
| Concept | Use When | Example attributes / events |
|---|---|---|
| Span event | You need a timestamped occurrence inside the span | span.add_event("error", {"type":"TimeoutError"}) |
| Span attribute | You need persistent contextual metadata for the span | span.set_attribute("http.method", "GET") |
| Interval/duration | You need to express a time range | Use span start/end or create a child span |
| Error reporting | Capture the exact time of the error | record_exception() or span.add_event("exception", {...}) |
- Use span events for time-specific actions, errors, or logs that matter at a precise instant.
- Use span attributes for contextual, persistent details about a span that apply for its whole duration.