Span events vs span links vs logs: when do you use each?
IntermediateConceptTracing & OpenTelemetry
Answer
- Span event: a timestamped point inside one span, e.g.
exceptionwithexception.typeandexception.stacktrace, or "cache miss". Use it for things that only make sense in the context of that operation. - Span link: a reference from one span to another span, often in a different trace. Use it for batch consumers processing 100 messages from 100 different producers, or a job triggered by an earlier request. Parent/child cannot express many-to-one; links can.
- Log record: a standalone event with its own lifecycle, retention and search. With OTel logs, records carry
trace_idandspan_id, so they correlate anyway.
Rule of thumb: high-volume diagnostic output goes to logs; small, operation-specific facts go into span events.
More on Tracing & OpenTelemetry
What is distributed tracing, and what are a trace, a span and a span context?BeginnerWhat fields does an OpenTelemetry span carry?BeginnerWhat are span kinds and why do they matter?IntermediateWhat does the W3C `traceparent` header look like?IntermediateWhat is baggage, and how is it different from span attributes?IntermediateWhat is OpenTelemetry and what are its main parts?Beginner