version bump
1 file changed
tree: 4fe4a6241f980ecdaf3048a7830ff5bb1e257a89
  1. .gitignore
  2. .travis.yml
  3. LICENSE
  4. README.md
  5. include/
  6. rebar.config
  7. rebar.lock
  8. src/
  9. test/
README.md

passage

hex.pm version Build Status Code Coverage License: MIT

OpenTraceing API for Erlang

Documentation

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.

Process Dictionary Version

%% 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
ok = passage_pd:start_span(example_root, [{tracer, tracer}]),

%% Starts a child span
ok = passage_pd:start_span(example_child),

%% Finishes spans
passage_pd:finish_span(),  % child
passage_pd:finish_span(),  % root

%% Receives the finished spans
receive {span, FinishedChildSpan} -> ok end,
receive {span, FinishedRootSpan} -> ok end.

Parse Transform

-module(example).

-compile({parse_transform, passage_transform}). % Enables `passage_transform'

-passage_trace([{tags, #{foo => bar}}, {eval_tags, #{size => "byte_size(Bin)"}}]).
-spec foo(binary()) -> binary().
foo(Bin) ->
  <<"foo", Bin/binary>>.

The above foo function will be transformed as follows:

foo(Bin) ->
  try
    passage_pd:start_span(
      'example:foo/1',
      [{tags, #{application => example, module => example, lien => 7, foo => bar}}]),
    passage_pd:set_tags(#{process => self(), size => byte_size(Bin)}),
    <<"foo", Bin/binary>>
  after
    passage_pd:finish_span()
  end.

References