OpenTelemetry API v0.5.0 OpenTelemetry.Span

This module contains macros for Span operations that update the active current Span in the current process. An example of creating an Event and adding it to the current Span:

require OpenTelemetry.Span
...
event = "ecto.query"
ecto_attributes = OpenTelemetry.event([{"query", query}, {"total_time", total_time}])
OpenTelemetry.Span.add_event(event, ecto_attributes)
...

A Span represents a single operation within a trace. Spans can be nested to form a trace tree. Each trace contains a root span, which typically describes the end-to-end latency and, optionally, one or more sub-spans for its sub-operations.

Spans encapsulate:

Link to this section Summary

Functions

Add an event to the currently active Span.

Add a list of events to the currently active Span.

End the Span. Sets the end timestamp for the currently active Span. This has no effect on any child Spans that may exist of this Span.

Set an attribute with key and value on the currently active Span.

Add a list of attributes to the currently active Span.

Sets the Status of the currently active Span.

Get the SpanId of a Span.

Get the TraceId of a Span.

Get the Tracestate of a Span.

Updates the Span name.

Link to this section Functions

Link to this function

add_event(span_ctx, event, attributes)

Add an event to the currently active Span.

Link to this function

add_events(span_ctx, events)

Add a list of events to the currently active Span.

Link to this function

end_span(span_ctx)

End the Span. Sets the end timestamp for the currently active Span. This has no effect on any child Spans that may exist of this Span.

The Span Context is returned with is_recording set to false.

Set an attribute with key and value on the currently active Span.

Link to this function

set_attributes(span_ctx, attributes)

Add a list of attributes to the currently active Span.

Link to this function

set_status(span_ctx, status)

Sets the Status of the currently active Span.

If used, this will override the default Span Status, which is Ok.

Get the SpanId of a Span.

Get the TraceId of a Span.

Get the Tracestate of a Span.

Link to this function

update_name(span_ctx, name)

update_name(OpenTelemetry.span_ctx(), String.t()) :: boolean()

Updates the Span name.

It is highly discouraged to update the name of a Span after its creation. Span name is often used to group, filter and identify the logical groups of spans. And often, filtering logic will be implemented before the Span creation for performance reasons. Thus the name update may interfere with this logic.

The function name is called UpdateName to differentiate this function from the regular property setter. It emphasizes that this operation signifies a major change for a Span and may lead to re-calculation of sampling or filtering decisions made previously depending on the implementation.