Span (and Trace) collection in OTeL is standardized through tracing SDKs/Libraries that can directly send via the OTLP
protocol to a collector. Traces can strongly supplement generic logging with its structure and linked information that can be represented as directed acyclic graph. This can not only diagnose issues due to dependencies, it can also give crucial information on component timing. The hallmark of tracing libraries is auto-instrumentation.
Trace Data Model
Just like Logs and Metrics, the OTeL Spec defines a Data Model (for Spans). Let's look at a few key fields:
Time
start_time
andend_time
: together these can calculateduration
Context
trace_id
andspan_id
: unique identifiers that help link spans together as part of a trace
Kind
- Can be one either
Client
,Server
,Internal
,Producer
, orConsumer
: provides clues to how spans should be linked. Represents outgoing calls, incoming calls, or calls that are nested internally.
- Can be one either
Status
status_code
andstatus_message
: provides information on wether the span represents an error or without issue ("ok").
Attribution
resource
andattributes
: just like other telemetry, resource attribution can represent metadata about the runtime environment (host, pod, etc). Attributes can help add metadata context to spans, like User ID.
Links
- "Links" can help bridge different traces. Especially useful for asynchronous and distributed operations.
Events
- Additional data that can represent a singular event of significance.
Instrumentation
Zero-Code Instrumentation
Zero-Code instrumentation libraries provide an effective way for practitioners to gather trace telemetry without code changes. Here is an example with Node.Js:
env OTEL_TRACES_EXPORTER=otlp OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=your-endpoint \
node --require @opentelemetry/auto-instrumentations-node/register app.js
Note how OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
points to your collector. There are various environment variables one can set, examples as outlined here.
Additionally, one can verify supported libraries (Node.Js example).
Output
Once this is configured, you can start receiving traces, as seen below: