Spandex (Spandex v3.1.0) View Source

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

Specs

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

Specs

id() :: term()

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

Specs

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

Specs

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.

Specs

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

Specs

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.

Specs

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

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.

Specs

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

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

Specs

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

Returns the id of the currently-running span.

Specs

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

Specs

distributed_context(Plug.Conn.t(), Spandex.Tracer.opts()) ::
  {:ok, Spandex.SpanContext.t()} | {:error, :disabled}
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.

Specs

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.

Specs

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

Specs

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

Specs

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.

Specs

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.

Specs

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.

Specs

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

Specs

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.

Specs

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.