Tapper v0.6.0 Tapper.Ctx View Source
Contextual interface to Tapper.
This interface uses the process dictionary to store and provide the Tapper.Id
to
API functions, removing this burden from your code, with the caveat of making things
slightly 'magic'.
It provides all the annotation helper functions of the non-contextual Tapper
API,
(in fact you can still use the helper functions from the Tapper
module, rather than
prefixing them all with Tapper.Ctx
).
You can still any API functions that need a Tapper.Id
via the
Tapper.Ctx.context/0
and Tapper.Ctx.put_context/1
functions, indeed
this is how to pass the Tapper.Id
through to child processes etc. Beware
however that functions outside of this module will not automatically update
the contextual Tapper.Id
for you. Contextual API functions return the
Tapper.Id
in the same way as the non-contextual API, should you need it.
Child Processes
Use Tapper.Ctx.context/0
and Tapper.Ctx.put_context/1
to surface and
submerge the id:
# surface from parent process
tapper_id = Tapper.Ctx.context()
pid = spawn(fn ->
# contextualize in child process
Tapper.Ctx.put_context(tapper_id)
# now use Tapper.Ctx functions as normal.
Tapper.Ctx.start_span(name: "child")
...
Tapper.Ctx.finish_span()
end)
Debugging
Set the :tapper
config var :debug_context
to debug missing contextual ids:
config :tapper,
debug_context: true
See also Tapper.Ctx.context/0
.
Link to this section Summary
Functions
Annotation helper: create an event annotation, general interface
Annotation helper: mark the span as asynchronous, and add an async
event annotation
Annotation helper: create a general binary annotation
Annotation helper: tag the client's address (ca
binary annotation)
Annotation helper: create a client_receive event (cr
event annotation)
Annotation helper: create a client_send event (cs
event annotation); see also :client
option on Tapper.start/1
determine if there is a Tapper.Id
in context
delete the in-context Tapper.Id
Annotation helper: create an error event (error
event annotation)
Annotation helper: tag with an error message (error
binary annotation)
Finishes the trace, for the current contextual Tapper.Id
, removing
the id from the process context
Annotation helper: tag with HTTP host information (http.host
binary annotation)
Annotation helper: tag with HTTP method information (http.method
binary annotation)
Annotation helper: tag with HTTP path information: should be without query parameters (http.path
binary annotation)
Annotation helper: tag with an HTTP request size (http.request.size
binary annotation)
Annotation helper: tag with an HTTP reponse size (http.response.size
binary annotation)
Annotation helper: tag with an HTTP status code (http.status_code
binary annotation)
Annotation helper: tag with full HTTP URL information (http.url
binary annotation)
Joins an existing trace, e.g. server recieving an annotated request
Annotation helper: name (or rename) the current span
Set the in-context Tapper.Id
of this process
Annotation helper: tag with the server's address (sa
binary annotation)
Annotation helper: create a server_receive event (sr
event annotation); see also :server
option on Tapper.start/1
Annotation helper: create a server_send event (ss
event annotation)
Annotation helper: tag with a database query (sql.query
binary annotation)
Starts a new root trace, e.g. on originating a request
Annotation helper: tag with a general (key,value,host) binary annotation, determining type of annotation automatically
Add annotations to the current contextual span, returning the same Tapper.Id
Annotation helper: create a receive event (wr
event annotation)
Annotation helper: create a send event (ws
event annotation)
Link to this section Functions
annotation(value, endpoint \\ nil)
View Source
annotation(
value :: Tapper.Tracer.Api.annotation_value(),
endpoint :: Tapper.Tracer.Api.maybe_endpoint()
) :: Tapper.Tracer.Api.annotation_delta()
annotation( value :: Tapper.Tracer.Api.annotation_value(), endpoint :: Tapper.Tracer.Api.maybe_endpoint() ) :: Tapper.Tracer.Api.annotation_delta()
Annotation helper: create an event annotation, general interface.
async()
View Source
async() :: Tapper.Tracer.Api.async_delta()
async() :: Tapper.Tracer.Api.async_delta()
Annotation helper: mark the span as asynchronous, and add an async
event annotation.
Adding this annotation is semantically equivalent to calling finish/2
with the async
option, and
instigates the same time-out behaviour.
You would probably add one of these to every asynchronous span, so we know which spans were async.
Ensure that child spans, and the whole trace, are finished as normal.
Example
# start a trace
id = Tapper.start(name: "main")
# spawn a task
ref = Task.start(fn ->
# start a child span in the task
child_id = Tapper.start_span(id, "fetch", annotations: Tapper.async())
res = do_something()
{res, child_id}
end)
# finish the trace, this won't send the spans; note we don't need async: true
# if Task has already called start_span(), but it might not have, so safer to do so!
Tapper.finish(id, async: true)
...
# await the result from our task
{res, span_id} = Task.await(ref)
send_result_to_queue_or_something(res)
# finish the child span; will complete trace and send spans
Tapper.finish_span(span_id)
See also
binary_annotation(type, key, value, endpoint \\ nil)
View Source
binary_annotation(
type :: Tapper.Tracer.Api.binary_annotation_type(),
key :: Tapper.Tracer.Api.binary_annotation_key(),
value :: Tapper.Tracer.Api.binary_annotation_value(),
endpoint :: Tapper.Tracer.Api.maybe_endpoint()
) :: Tapper.Tracer.Api.binary_annotation_delta()
binary_annotation( type :: Tapper.Tracer.Api.binary_annotation_type(), key :: Tapper.Tracer.Api.binary_annotation_key(), value :: Tapper.Tracer.Api.binary_annotation_value(), endpoint :: Tapper.Tracer.Api.maybe_endpoint() ) :: Tapper.Tracer.Api.binary_annotation_delta()
Annotation helper: create a general binary annotation.
type
is one of: :string
, :bool
, :i16
, :i32
, :i64
, :double
, :bytes
Example
binary_annotation(id, :i16, "tab", 4)
client_address(endpoint)
View Source
client_address(endpoint :: Tapper.Endpoint.t()) ::
Tapper.Tracer.Api.binary_annotation_delta()
client_address(endpoint :: Tapper.Endpoint.t()) :: Tapper.Tracer.Api.binary_annotation_delta()
Annotation helper: tag the client's address (ca
binary annotation).
client_receive()
View Source
client_receive() :: Tapper.Tracer.Api.annotation_delta()
client_receive() :: Tapper.Tracer.Api.annotation_delta()
Annotation helper: create a client_receive event (cr
event annotation).
client_send()
View Source
client_send() :: Tapper.Tracer.Api.annotation_delta()
client_send() :: Tapper.Tracer.Api.annotation_delta()
Annotation helper: create a client_send event (cs
event annotation); see also :client
option on Tapper.start/1
.
context()
View Source
context() :: Tapper.Id.t() | no_return()
context() :: Tapper.Id.t() | no_return()
Get the in-context Tapper.Id
of this process.
If the context does not exist, and :tapper
configuration option
:debug_context
is is :warn
will log a warning with stack-trace,
if otherwise truthy, will raise a RuntimeError
,
else will just return :ignore
.
context?() View Source
determine if there is a Tapper.Id
in context
delete_context() View Source
delete the in-context Tapper.Id
error()
View Source
error() :: Tapper.Tracer.Api.annotation_delta()
error() :: Tapper.Tracer.Api.annotation_delta()
Annotation helper: create an error event (error
event annotation).
error_message(message)
View Source
error_message(message :: any()) :: Tapper.Tracer.Api.binary_annotation_delta()
error_message(message :: any()) :: Tapper.Tracer.Api.binary_annotation_delta()
Annotation helper: tag with an error message (error
binary annotation)
finish(opts \\ [])
View Source
finish(opts :: Keyword.t()) :: :ok
finish(opts :: Keyword.t()) :: :ok
Finishes the trace, for the current contextual Tapper.Id
, removing
the id from the process context.
See Tapper.Tracer.finish/2
for options.
finish_span(opts \\ [])
View Source
finish_span(opts :: Keyword.t()) :: Tapper.Id.t()
finish_span(opts :: Keyword.t()) :: Tapper.Id.t()
Finish a nested span of the current contextual Tapper.Id
, returning an updated
Tapper.Id
, and updating the id in the context.
See Tapper.Tracer.finish_span/2
for options.
http_host(hostname)
View Source
http_host(hostname :: String.t()) :: Tapper.Tracer.Api.binary_annotation_delta()
http_host(hostname :: String.t()) :: Tapper.Tracer.Api.binary_annotation_delta()
Annotation helper: tag with HTTP host information (http.host
binary annotation).
http_method(method)
View Source
http_method(method :: String.t() | atom()) ::
Tapper.Tracer.Api.binary_annotation_delta()
http_method(method :: String.t() | atom()) :: Tapper.Tracer.Api.binary_annotation_delta()
Annotation helper: tag with HTTP method information (http.method
binary annotation).
http_path(path)
View Source
http_path(path :: String.t()) :: Tapper.Tracer.Api.binary_annotation_delta()
http_path(path :: String.t()) :: Tapper.Tracer.Api.binary_annotation_delta()
Annotation helper: tag with HTTP path information: should be without query parameters (http.path
binary annotation)
http_request_size(size)
View Source
http_request_size(size :: integer()) ::
Tapper.Tracer.Api.binary_annotation_delta()
http_request_size(size :: integer()) :: Tapper.Tracer.Api.binary_annotation_delta()
Annotation helper: tag with an HTTP request size (http.request.size
binary annotation)
http_response_size(size)
View Source
http_response_size(size :: integer()) ::
Tapper.Tracer.Api.binary_annotation_delta()
http_response_size(size :: integer()) :: Tapper.Tracer.Api.binary_annotation_delta()
Annotation helper: tag with an HTTP reponse size (http.response.size
binary annotation)
http_status_code(code)
View Source
http_status_code(code :: integer()) ::
Tapper.Tracer.Api.binary_annotation_delta()
http_status_code(code :: integer()) :: Tapper.Tracer.Api.binary_annotation_delta()
Annotation helper: tag with an HTTP status code (http.status_code
binary annotation)
http_url(url)
View Source
http_url(url :: String.t()) :: Tapper.Tracer.Api.binary_annotation_delta()
http_url(url :: String.t()) :: Tapper.Tracer.Api.binary_annotation_delta()
Annotation helper: tag with full HTTP URL information (http.url
binary annotation)
join(trace_id, span_id, parent_id, sample, debug, opts \\ [])
View Source
join(
trace_id :: Tapper.TraceId.t(),
span_id :: Tapper.SpanId.t(),
parent_id :: Tapper.SpanId.t() | :root,
sample :: boolean(),
debug :: boolean(),
opts :: Keyword.t()
) :: Tapper.Id.t()
join( trace_id :: Tapper.TraceId.t(), span_id :: Tapper.SpanId.t(), parent_id :: Tapper.SpanId.t() | :root, sample :: boolean(), debug :: boolean(), opts :: Keyword.t() ) :: Tapper.Id.t()
Joins an existing trace, e.g. server recieving an annotated request.
A Tapper.Id
is returned, and stored it in the process context.
id = Tapper.Ctx.join(trace_id, span_id, parent_id, sample, debug, name: "receive request")
^id = Tapper.Ctx.context()
See Tapper.Tracer.join/6
for options.
name(name)
View Source
name(name :: String.t() | atom()) :: Tapper.Tracer.Api.name_delta()
name(name :: String.t() | atom()) :: Tapper.Tracer.Api.name_delta()
Annotation helper: name (or rename) the current span.
put_context(id)
View Source
put_context(id :: Tapper.Id.t()) :: Tapper.Id.t()
put_context(id :: Tapper.Id.t()) :: Tapper.Id.t()
Set the in-context Tapper.Id
of this process.
server_address(endpoint)
View Source
server_address(endpoint :: Tapper.Endpoint.t()) ::
Tapper.Tracer.Api.binary_annotation_delta()
server_address(endpoint :: Tapper.Endpoint.t()) :: Tapper.Tracer.Api.binary_annotation_delta()
Annotation helper: tag with the server's address (sa
binary annotation).
server_receive()
View Source
server_receive() :: Tapper.Tracer.Api.annotation_delta()
server_receive() :: Tapper.Tracer.Api.annotation_delta()
Annotation helper: create a server_receive event (sr
event annotation); see also :server
option on Tapper.start/1
.
server_send()
View Source
server_send() :: Tapper.Tracer.Api.annotation_delta()
server_send() :: Tapper.Tracer.Api.annotation_delta()
Annotation helper: create a server_send event (ss
event annotation).
sql_query(query)
View Source
sql_query(query :: String.t()) :: Tapper.Tracer.Api.binary_annotation_delta()
sql_query(query :: String.t()) :: Tapper.Tracer.Api.binary_annotation_delta()
Annotation helper: tag with a database query (sql.query
binary annotation)
start(opts \\ [])
View Source
start(opts :: Keyword.t()) :: Tapper.Id.t()
start(opts :: Keyword.t()) :: Tapper.Id.t()
Starts a new root trace, e.g. on originating a request.
A new Tapper.Id
is returned, and stored in the process context,
see Tapper.Ctx.put_context/1
.
id = Tapper.Ctx.start(name: "request resource", type: :client, remote: remote_endpoint)
^id = Tapper.Ctx.context()
See Tapper.Tracer.start/1
for options.
start_span(opts \\ [])
View Source
start_span(opts :: Keyword.t()) :: Tapper.Id.t()
start_span(opts :: Keyword.t()) :: Tapper.Id.t()
Starts a child span of the current span of the current contextual Tapper.Id
,
returning an updated Tapper.Id
, and updating the id in the context.
See Tapper.Tracer.start_span/2
for options.
tag(key, value, endpoint \\ nil)
View Source
tag(
key :: Tapper.Tracer.Api.binary_annotation_key(),
value :: Tapper.Tracer.Api.binary_annotation_value(),
endpoint :: Tapper.Tracer.Api.maybe_endpoint()
) :: Tapper.Tracer.Api.binary_annotation_delta()
tag( key :: Tapper.Tracer.Api.binary_annotation_key(), value :: Tapper.Tracer.Api.binary_annotation_value(), endpoint :: Tapper.Tracer.Api.maybe_endpoint() ) :: Tapper.Tracer.Api.binary_annotation_delta()
Annotation helper: tag with a general (key,value,host) binary annotation, determining type of annotation automatically
update_span(deltas, opts \\ [])
View Source
update_span(
deltas :: Tapper.Tracer.Api.delta() | [Tapper.Tracer.Api.delta()],
opts :: Keyword.t()
) :: Tapper.Id.t()
update_span( deltas :: Tapper.Tracer.Api.delta() | [Tapper.Tracer.Api.delta()], opts :: Keyword.t() ) :: Tapper.Id.t()
Add annotations to the current contextual span, returning the same Tapper.Id
.
See Tapper.Tracer.update_span/3
for details.
wire_receive()
View Source
wire_receive() :: Tapper.Tracer.Api.annotation_delta()
wire_receive() :: Tapper.Tracer.Api.annotation_delta()
Annotation helper: create a receive event (wr
event annotation).
wire_send()
View Source
wire_send() :: Tapper.Tracer.Api.annotation_delta()
wire_send() :: Tapper.Tracer.Api.annotation_delta()
Annotation helper: create a send event (ws
event annotation).