View Source Spandex (Spandex v3.2.0)

The functions here call the corresponding functions on the configured adapter.

Link to this section Summary

Types

Used for Span and Trace IDs (type defined by adapters)

Unix timestamp in nanoseconds

Functions

Given a %SpanContext{}, resumes a trace from a different process or service.

Given a trace_id and span_id, resumes a trace from a different process or service.

Given a span struct, resumes a trace from a different process or service.

Returns the current %SpanContext{} or an error.

Returns the %Span{} struct for the currently-running span

Returns the id of the currently-running span.

Returns the id of the currently-running trace.

Returns the context from a given set of HTTP headers, as determined by the adapter.

Finishes the current span.

Finishes the current trace.

Alters headers to include the outgoing HTTP headers necessary to continue a distributed trace, as determined by the adapter.

Updates the current span with error details.

Start a new span.

Starts a new trace.

Updates all spans, whether complete or in-progress.

Updates the current span.

Updates the top-most parent span.

Link to this section Types

@type headers() ::
  [{atom(), binary()}]
  | [{binary(), binary()}]
  | %{required(binary()) => binary()}
@type id() :: term()

Used for Span and Trace IDs (type defined by adapters)

@type timestamp() :: non_neg_integer()

Unix timestamp in nanoseconds

Link to this section Functions

Link to this function

continue_trace(name, span_context, opts)

View Source
@spec continue_trace(String.t(), Spandex.SpanContext.t(), Keyword.t()) ::
  {:ok, Spandex.Trace.t()}
  | {:error, :disabled}
  | {:error, :trace_already_present}

Given a %SpanContext{}, resumes a trace from a different process or service.

Span updates for the top span may be passed in. They are skipped if they are invalid updates. As such, if you aren't sure if your updates are valid, it is safer to perform a second call to update_span/2 and check the return value.

Link to this function

continue_trace(name, trace_id, span_id, opts)

View Source
This function is deprecated. Use continue_trace/3 instead.
@spec continue_trace(String.t(), id(), id(), Keyword.t()) ::
  {:ok, Spandex.Trace.t()}
  | {:error, :disabled}
  | {:error, :trace_already_present}

Given a trace_id and span_id, resumes a trace from a different process or service.

Span updates for the top span may be passed in. They are skipped if they are invalid updates. As such, if you aren't sure if your updates are valid, it is safer to perform a second call to update_span/2 and check the return value.

Link to this function

continue_trace_from_span(name, span, opts)

View Source
@spec continue_trace_from_span(String.t(), Spandex.Span.t(), Spandex.Tracer.opts()) ::
  {:ok, Spandex.Trace.t()}
  | {:error, :disabled}
  | {:error, :trace_already_present}

Given a span struct, resumes a trace from a different process or service.

Span updates for the top span may be passed in. They are skipped if they are invalid updates. As such, if you aren't sure if your updates are valid, it is safer to perform a second call to update_span/2 and check the return value.

@spec current_context(Spandex.Tracer.opts()) ::
  {:ok, Spandex.SpanContext.t()}
  | {:error, :disabled}
  | {:error, :no_span_context}
  | {:error, :no_trace_context}

Returns the current %SpanContext{} or an error.

deprecation-warning

DEPRECATION WARNING

Expect changes to this in the future, as this will eventualy be refactored to only ever return a %SpanContext{}, or at least to always return something consistent.

@spec current_span(Spandex.Tracer.opts()) :: Spandex.Span.t() | nil

Returns the %Span{} struct for the currently-running span

@spec current_span_id(Spandex.Tracer.opts()) :: id() | nil

Returns the id of the currently-running span.

@spec current_trace_id(Spandex.Tracer.opts()) :: id() | nil

Returns the id of the currently-running trace.

Link to this function

distributed_context(metadata, opts)

View Source
@spec distributed_context(Plug.Conn.t(), Spandex.Tracer.opts()) ::
  {:ok, Spandex.SpanContext.t()} | {:error, :disabled}
@spec distributed_context(headers(), Spandex.Tracer.opts()) ::
  {:ok, Spandex.SpanContext.t()} | {:error, :disabled}

Returns the context from a given set of HTTP headers, as determined by the adapter.

@spec finish_span(Spandex.Tracer.opts()) ::
  {:ok, Spandex.Span.t()}
  | {:error, :disabled}
  | {:error, :no_trace_context}
  | {:error, :no_span_context}

Finishes the current span.

Span updates for that span may be passed in. They are skipped if they are invalid updates. As such, if you aren't sure if your updates are valid, it is safer to perform a call to update_span/2 and check the return value before finishing the span.

@spec finish_trace(Spandex.Tracer.opts()) ::
  {:ok, Spandex.Trace.t()} | {:error, :disabled} | {:error, :no_trace_context}

Finishes the current trace.

Span updates for the top span may be passed in. They are skipped if they are invalid updates. As such, if you aren't sure if your updates are valid, it is safer to perform a call to update_span/2 and check the return value before finishing the trace.

Link to this function

inject_context(headers, span_context, opts)

View Source
@spec inject_context(headers(), Spandex.SpanContext.t(), Spandex.Tracer.opts()) ::
  headers()

Alters headers to include the outgoing HTTP headers necessary to continue a distributed trace, as determined by the adapter.

Link to this function

span_error(exception, stacktrace, opts)

View Source
@spec span_error(Exception.t(), Enum.t(), Spandex.Tracer.opts()) ::
  {:ok, Spandex.Span.t()}
  | {:error, :disabled}
  | {:error, :no_trace_context}
  | {:error, :no_span_context}
  | {:error, [Optimal.error()]}

Updates the current span with error details.

In the case of an invalid value, validation errors are returned.

@spec start_span(String.t(), Spandex.Tracer.opts()) ::
  {:ok, Spandex.Span.t()} | {:error, :disabled} | {:error, :no_trace_context}

Start a new span.

Span updates for that span may be passed in. They are skipped if they are invalid updates. As such, if you aren't sure if your updates are valid, it is safer to perform a second call to update_span/2 and check the return value.

@spec start_trace(binary(), Spandex.Tracer.opts()) ::
  {:ok, Spandex.Trace.t()}
  | {:error, :disabled}
  | {:error, :trace_running}
  | {:error, [Optimal.error()]}

Starts a new trace.

Span updates for the first span may be passed in. They are skipped if they are invalid updates. As such, if you aren't sure if your updates are valid, it is safer to perform a second call to update_span/2 and check the return value.

@spec update_all_spans(Spandex.Tracer.opts()) ::
  {:ok, Spandex.Trace.t()}
  | {:error, :disabled}
  | {:error, :no_trace_context}
  | {:error, [Optimal.error()]}

Updates all spans, whether complete or in-progress.

In the case of an invalid update for any span, validation errors are returned.

Link to this function

update_span(opts, top? \\ false)

View Source
@spec update_span(Spandex.Tracer.opts(), boolean()) ::
  {:ok, Spandex.Span.t()}
  | {:error, :disabled}
  | {:error, :no_trace_context}
  | {:error, :no_span_context}
  | {:error, [Optimal.error()]}

Updates the current span.

In the case of an invalid update, validation errors are returned.

@spec update_top_span(Spandex.Tracer.opts()) ::
  {:ok, Spandex.Span.t()}
  | {:error, :disabled}
  | {:error, :no_trace_context}
  | {:error, [Optimal.error()]}

Updates the top-most parent span.

Any spans that have already been started will not inherit any of the updates from that span. For instance, if you change service, it will not be reflected in already-started spans.

In the case of an invalid update, validation errors are returned.