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'
-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, line => 7, foo => bar}}]),
passage_pd:set_tags(#{process => self(), size => byte_size(Bin)}),
<<"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, passage:tracer_id()} | {tags, passage:tags()} | {eval_tags, #{passage:tag_name() => expr_string()}} | {child_of, expr_string()} | {follows_from, expr_string()} | {error_if, expr_string()} | error_if_exception
passage:start_span/2passage:start_span/2tags except the values are dynamically evaluated in the transforming phase.passage:start_span/2passage:start_span/2 %% {error_if, ErrorPattern}
case Body of
ErrorPattern = Error ->
passage_pd:log(#{message, Result}, [error]),
Error;
Ok -> Ok
end.
try
Body
catch
Class:Error ->
passage_pd:log(#{'error.kind' => class,
'message' => Error,
'stack' => erlang:get_stacktrace()},
[error]),
erlang:raise(Class, Error, erlang:get_stacktrace())
end.
| parse_transform/2 | Performs transformations for passage |
parse_transform(AbstractForms, CompileOptions::list()) -> AbstractForms
Performs transformations for passage
Generated by EDoc, Oct 28 2017, 05:08:05.