Module passage

API for operating active spans.

Copyright © 2017 Takeru Ohta <phjgt308@gmail.com>

Description

API for operating active spans.

Most of the functions and types provided in this module are based on the OpenTracing API.

Examples

  %% Registers `tracer'
  Context = passage_span_context_null,
  Sampler = passage_sampler_all:new(),
  Reporter = passage_reporter_process:new(self(), span),
  ok = passage_tracer_registry:register(tracer, Context, Sampler, Reporter),
 
  %% Starts a root span
  RootSpan = passage:start_span(example_root, [{tracer, tracer}]),
 
  %% Starts a child span
  ChildSpan = passage:start_span(example_child, [{child_of, RootSpan}]),
 
  %% Finishes spans
  passage:finish_span(ChildSpan),
  passage:finish_span(RootSpan),
 
  %% Receives the finished spans
  receive {span, FinishedChildSpan} -> ok end,
  receive {span, FinishedRootSpan} -> ok end.

Data Types

baggage_item_name()

baggage_item_name() = binary()

Baggage item name.

baggage_item_value()

baggage_item_value() = binary()

Baggage item value.

baggage_items()

baggage_items() = #{baggage_item_name() => baggage_item_value()}

Baggage items.

Baggage items are just key/value pairs that cross OS process boundaries.

finish_span_option()

finish_span_option() = {time, erlang:timestamp()} | {lifetime, pid()}

finish_span_options()

finish_span_options() = [finish_span_option()]

Options for finish_span/2.

log_field_name()

log_field_name() = atom()

Log field name.

log_field_value()

log_field_value() = term()

Log field value.

log_fields()

log_fields() = #{log_field_name() => log_field_value()}

Span log fields.

See also: Standard log fields (OpenTracing API)

log_option()

log_option() = {time, erlang:timestamp()} | error | {error, boolean()}

log_options()

log_options() = [log_option()]

Options for log/3.

maybe_span()

maybe_span() = passage_span:span() | undefined

Sampled or unsampled span.

undefined means the span is unsampled.

operation_name()

operation_name() = atom()

Operation name.

ref()

ref() = {ref_type(), passage_span:span()}

Span reference.

Note that the values of tags, references and logs of a reference are set to empty when the associated span is created.

See also: References between Spans (The OpenTracing Semantic Specification)

ref_type()

ref_type() = child_of | follows_from

Span reference type.

refs()

refs() = [ref()]

Span references.

start_span_option()

start_span_option() = {tracer, tracer_id()} | {tags, tags()} | {ref_type(), maybe_span()} | {time, erlang:timestamp()}

start_span_options()

start_span_options() = [start_span_option()]

Options for start_span/2.

tag_name()

tag_name() = atom()

Tag name.

tag_value()

tag_value() = term()

Tag value.

tags()

tags() = #{tag_name() => tag_value()}

Span tags.

See also: Standard span tags (OpenTracing API)

tracer_id()

tracer_id() = atom()

Tracer identifier.

Function Index

extract_span/4Extracts a span from Carrier.
finish_span/1Equivalent to finish_span(Span, []).
finish_span/2Finishes the span.
get_baggage_items/1Returns the baggage items carried by Span.
inject_span/4Injects Span into Carrier.
log/2Equivalent to log(Span, Fields, []).
log/3Logs the Fields to Span.
set_baggage_items/2Sets the baggage items of Span to Items.
set_operation_name/2Sets the operation name of Span to Name.
set_tags/2Sets the tags of Span to Tags.
set_tracer/2Sets the tracer of Span to Tracer.
start_span/1Equivalent to start_span(OperationName, []).
start_span/2Starts a span.
strip_span/1Strips the tags, logs and references from the given span.

Function Details

extract_span/4

extract_span(Tracer, Format, IterateFun, Carrier) -> maybe_span()

Extracts a span from Carrier.

If Carrier has no span context, this function will return undefined.

finish_span/1

finish_span(Span::maybe_span()) -> ok

Equivalent to finish_span(Span, []).

finish_span/2

finish_span(Span::maybe_span(), Options::finish_span_options()) -> ok

Finishes the span.

The finished span will be sent an external observer via the reporter associated with the tracer of the span.

Note that if you call this function on the same span more than once, duplicate reports will be sent.

get_baggage_items/1

get_baggage_items(Span::maybe_span()) -> baggage_items()

Returns the baggage items carried by Span.

inject_span/4

inject_span(Span, Format, InjectFun, Carrier) -> Carrier

Injects Span into Carrier.

log/2

log(Span::maybe_span(), Fields) -> maybe_span()

Equivalent to log(Span, Fields, []).

log/3

log(Span::maybe_span(), Fields, Options::log_options()) -> maybe_span()

Logs the Fields to Span.

set_baggage_items/2

set_baggage_items(Span::maybe_span(), Items) -> maybe_span()

Sets the baggage items of Span to Items.

Note that the existing items which have different keys with Items are preserved.

See also: Set a baggage item (The OpenTracing Semantic Specification)

set_operation_name/2

set_operation_name(Span::maybe_span(), Name::operation_name()) -> maybe_span()

Sets the operation name of Span to Name.

set_tags/2

set_tags(Span::maybe_span(), Tags) -> maybe_span()

Sets the tags of Span to Tags.

Note that the existing tags which have different keys with Tags are preserved.

set_tracer/2

set_tracer(Span::maybe_span(), Tracer::tracer_id()) -> maybe_span()

Sets the tracer of Span to Tracer.

At the finish of the span, the reporter of Tracer will be used to report it.

This change affects all descendants of this span.

start_span/1

start_span(OperationName::operation_name()) -> maybe_span()

Equivalent to start_span(OperationName, []).

start_span/2

start_span(OperationName::operation_name(), Options::start_span_options()) -> maybe_span()

Starts a span.

If any of the following conditions is matched, a valid span object (i.e., non undefined) will be returned.

If the first condition matches, the tracer associated with the first reference will be used for tracing the resulting span.

strip_span/1

strip_span(Span::maybe_span()) -> maybe_span()

Strips the tags, logs and references from the given span.


Generated by EDoc