otel_span (OpenTelemetry API v1.4.0)

View Source

Span behaviour.

Summary

Types

Start options for a span.

Functions

Adds an event to the given span context.

Same as add_event/3, but takes a list of events.

Ends the given span context.

Ends the given span context with the given timestamp.

Returns whether the span is recording.

Returns whether the span context is valid.

Returns the span ID of the given span context.

Returns the trace ID of the given span context.

Updates the name of the given span context to Name.

Validates the start options for a span and fills in defaults.

Types

start_config/0

-type start_config() ::
          #{attributes := opentelemetry:attributes_map(),
            links := [opentelemetry:link()],
            is_recording := boolean(),
            start_time := opentelemetry:timestamp(),
            kind := opentelemetry:span_kind()}.

Start options for a span.

start_opts/0

-type start_opts() ::
          #{attributes => opentelemetry:attributes_map(),
            links => [opentelemetry:link()],
            is_recording => boolean(),
            start_time => opentelemetry:timestamp(),
            kind => opentelemetry:span_kind()}.

Functions

add_event(SpanCtx, Name, Attributes)

-spec add_event(SpanCtx, Name, Attributes) -> boolean()
                   when
                       Name :: opentelemetry:event_name(),
                       Attributes :: opentelemetry:attributes_map(),
                       SpanCtx :: opentelemetry:span_ctx().

Adds an event to the given span context.

Returns false if the given span context is not recording, or if the event Name is not valid.

add_events(SpanCtx, Events)

-spec add_events(SpanCtx, Events) -> boolean()
                    when Events :: [opentelemetry:event()], SpanCtx :: opentelemetry:span_ctx().

Same as add_event/3, but takes a list of events.

Returns false if the given span context is not recording.

end_span(SpanCtx)

-spec end_span(SpanCtx) -> SpanCtx when SpanCtx :: opentelemetry:span_ctx().

Ends the given span context.

If SpanCtx is not recording, this function doesn't do anything. Returns the updated span context.

end_span(SpanCtx, Timestamp)

-spec end_span(SpanCtx, Timestamp) -> SpanCtx
                  when SpanCtx :: opentelemetry:span_ctx(), Timestamp :: integer() | undefined.

Ends the given span context with the given timestamp.

If SpanCtx is not recording, this function doesn't do anything. If Timestamp is undefined, this is equivalent to end_span/1. Returns the updated span context.

hex_span_ctx(Span_ctx)

-spec hex_span_ctx(opentelemetry:span_ctx() | undefined) ->
                      #{otel_trace_id := unicode:charlist(),
                        otel_span_id := unicode:charlist(),
                        otel_trace_flags := unicode:charlist()} |
                      #{}.

hex_span_id(Span_ctx)

hex_trace_id(Span_ctx)

is_recording(SpanCtx)

-spec is_recording(SpanCtx) -> boolean() when SpanCtx :: opentelemetry:span_ctx() | undefined.

Returns whether the span is recording.

is_valid(SpanCtx)

-spec is_valid(SpanCtx) -> boolean() when SpanCtx :: opentelemetry:span_ctx().

Returns whether the span context is valid.

record_exception(SpanCtx, Class, Term, Stacktrace, Attributes)

-spec record_exception(SpanCtx, Class, Term, Stacktrace, Attributes) -> boolean()
                          when
                              SpanCtx :: opentelemetry:span_ctx(),
                              Class :: atom(),
                              Term :: term(),
                              Stacktrace :: [any()],
                              Attributes :: opentelemetry:attributes_map().

record_exception(SpanCtx, Class, Term, Message, Stacktrace, Attributes)

-spec record_exception(SpanCtx, Class, Term, Message, Stacktrace, Attributes) -> boolean()
                          when
                              SpanCtx :: opentelemetry:span_ctx(),
                              Class :: atom(),
                              Term :: term(),
                              Message :: unicode:unicode_binary(),
                              Stacktrace :: [any()],
                              Attributes :: opentelemetry:attributes_map().

set_attribute(SpanCtx, Key, Value)

-spec set_attribute(SpanCtx, Key, Value) -> boolean()
                       when
                           Key :: opentelemetry:attribute_key(),
                           Value :: opentelemetry:attribute_value(),
                           SpanCtx :: opentelemetry:span_ctx().

set_attributes(SpanCtx, Attributes)

-spec set_attributes(SpanCtx, Attributes) -> boolean()
                        when
                            Attributes :: opentelemetry:attributes_map(),
                            SpanCtx :: opentelemetry:span_ctx().

set_status(SpanCtx, StatusOrCode)

-spec set_status(SpanCtx, StatusOrCode) -> boolean()
                    when
                        StatusOrCode :: opentelemetry:status() | undefined | opentelemetry:status_code(),
                        SpanCtx :: opentelemetry:span_ctx().

set_status(SpanCtx, Code, Message)

-spec set_status(SpanCtx, Code, Message) -> boolean()
                    when
                        Code :: opentelemetry:status_code(),
                        Message :: unicode:unicode_binary(),
                        SpanCtx :: opentelemetry:span_ctx().

span_id(Span_ctx)

Returns the span ID of the given span context.

trace_id(Span_ctx)

Returns the trace ID of the given span context.

tracestate(Span_ctx)

-spec tracestate(opentelemetry:span_ctx() | undefined) -> otel_tracestate:t().

update_name(SpanCtx, Name)

-spec update_name(SpanCtx, Name) -> boolean()
                     when Name :: opentelemetry:span_name(), SpanCtx :: opentelemetry:span_ctx().

Updates the name of the given span context to Name.

Returns false if the given span context is not recording, or if the name Name is not valid.

validate_start_opts(Opts)

-spec validate_start_opts(start_opts()) -> start_config().

Validates the start options for a span and fills in defaults.