OpenTelemetry API v1.0.0-rc.2 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:
- The span name
- An immutable SpanContext (
OpenTelemetry.span_ctx/0
) that uniquely identifies the Span - A parent Span in the form of a Span (
OpenTelemetry.span/0
), SpanContext (OpenTelemetry.span_ctx/0
), orundefined
- A start timestamp
- An end timestamp
- An ordered mapping of Attributes (
OpenTelemetry.attributes/0
) - A list of Links to other Spans (
OpenTelemetry.link/0
) - A list of timestamped Events (
OpenTelemetry.event/0
) - A Status (
OpenTelemetry.status/0
)
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.
Record an exception as an event, following the semantics convetions for exceptions.
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
add_event(span_ctx, event, attributes)
add_event( OpenTelemetry.span_ctx(), OpenTelemetry.event_name(), OpenTelemetry.attributes() ) :: boolean()
Add an event to the currently active Span.
add_events(span_ctx, events)
add_events(OpenTelemetry.span_ctx(), [OpenTelemetry.event()]) :: boolean()
Add a list of events to the currently active Span.
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
.
is_recording(span_ctx)
is_valid(span_ctx)
record_exception(span_ctx, exception, trace \\ nil, attributes \\ [])
Record an exception as an event, following the semantics convetions for exceptions.
If trace is not provided, the stacktrace is retrieved from Process.info/2
set_attribute(span_ctx, key, value)
set_attribute( OpenTelemetry.span_ctx(), OpenTelemetry.attribute_key(), OpenTelemetry.attribute_value() ) :: boolean()
Set an attribute with key and value on the currently active Span.
set_attributes(span_ctx, attributes)
set_attributes(OpenTelemetry.span_ctx(), OpenTelemetry.attributes()) :: boolean()
Add a list of attributes to the currently active Span.
set_status(span_ctx, status)
set_status(OpenTelemetry.span_ctx(), OpenTelemetry.status()) :: boolean()
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.
tracestate(span)
tracestate(OpenTelemetry.span_ctx()) :: OpenTelemetry.tracestate()
Get the Tracestate of a Span.
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.