parse_transform
module for passage
Copyright © 2017 Takeru Ohta <phjgt308@gmail.com>
A parse_transform
module for passage
This module handles passage_trace
attribute.
If the attribute is appeared, the next function will be traced automatically.
See following example:
-module(example). -compile({parse_transform, passage_transform}). % Enables `passage_transform' -compile({passage_default_tracer, "foo_tracer"}). % Specifies the default tracer (optional) -passage_trace([{tags, #{foo => "bar", size => "byte_size(Bin)"}}]). -spec foo(binary()) -> binary(). foo(Bin) -> <<"foo", Bin/binary>>.
The above foo
function will be transformed as follows:
foo(Bin) -> passage_pd:start_span('example:foo/1', []), try passage_pd:set_tags( fun () -> #{ 'location.pid' => self(), 'location.application' => example, 'location.module' => example, 'location.line' => 7 foo => bar, size => byte_size(Bin) } end), <<"foo", Bin/binary>> after passage_pd:finish_span() end.
expr_string() = string()
The textual representation of an expression.
When used, it will be converted to an AST representation as follows:
{ok, Tokens, _} = erl_scan:string(ExprString ++ "."), {ok, [Expr]} = erl_parse:parse_exprs(Tokens).
passage_trace_option() = {tracer, expr_string()} | {tags, #{passage:tag_name() => expr_string()}} | {child_of, expr_string()} | {follows_from, expr_string()} | {error_if, expr_string()} | {error_if_exception, boolean()}
passage:start_span/2
passage:tags()
except the values are dynamically evaluated in the transforming phase.passage:start_span/2
passage:start_span/2
%% {error_if, ErrorPattern} case Body of ErrorPattern = Error -> passage_pd:log(#{message, Result}, [error]), Error; Ok -> Ok end.
passage_pd:with_span_option()
parse_transform/2 | Performs transformations for passage |
parse_transform(AbstractForms, CompileOptions::list()) -> AbstractForms
Performs transformations for passage
Generated by EDoc