Tapper v0.6.0 Tapper.Tracer View Source
Low-level client API, interfaces between a Tapper client and a Tapper.Tracer.Server.
Most functions in Tapper delegate to this module; Tapper also provides helper functions
for creation of common annotations.
For protection against future API changes, prefer the higher-level interfaces.
See also
Tapper- high-level client API.Tapper.Ctx- high-level contextual client API.
Link to this section Summary
Functions
build a span annotation, suitable for passing to annotations option or update_span/3; see also convenience functions in Tapper
build an async action, suitable for passing to annotations option or update_span/3; see also Tapper.async/0
build a span binary annotation, suitable for passing to annotations option or update_span/3; see also convenience functions in Tapper
Finishes the trace, returns :ok
Finish a nested span, returning an updated Tapper.Id
join an existing trace, e.g. server recieving an annotated request, returning a Tapper.Id for subsequent operations:
id = Tapper.join(trace_id, span_id, parent_id, sample, debug, name: "receive request")
Provides some aliases for event annotation types
build an name-span action, suitable for passing to annotations option or update_span/3; see also Tapper.name/1
start a new root trace, e.g. on originating a request, e.g
Starts a child span, returning an updated Tapper.Id
Add annotations to the current span; returns the same Tapper.Id
Link to this section Functions
annotation_delta(value, endpoint \\ nil)
View Source
annotation_delta(
value :: Tapper.Tracer.Api.annotation_value(),
endpoint :: Tapper.Tracer.Api.maybe_endpoint()
) :: Tapper.Tracer.Api.annotation_delta()
annotation_delta( value :: Tapper.Tracer.Api.annotation_value(), endpoint :: Tapper.Tracer.Api.maybe_endpoint() ) :: Tapper.Tracer.Api.annotation_delta()
build a span annotation, suitable for passing to annotations option or update_span/3; see also convenience functions in Tapper.
async_delta()
View Source
async_delta() :: Tapper.Tracer.Api.async_delta()
async_delta() :: Tapper.Tracer.Api.async_delta()
build an async action, suitable for passing to annotations option or update_span/3; see also Tapper.async/0.
binary_annotation_delta(type, key, value, endpoint \\ nil)
View Source
binary_annotation_delta(
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_delta( 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()
build a span binary annotation, suitable for passing to annotations option or update_span/3; see also convenience functions in Tapper.
finish(id, opts \\ []) View Source
Finishes the trace, returns :ok.
For async processes (where spans persist in another process), just call
finish/2 when done with the main span, passing the async option, and finish
child spans as normal using finish_span/2. When the trace times out, spans will
be sent to the server, marking any unfinished spans with a timeout annotation.
id = Tapper.finish(id, async: true, annotations: [Tapper.http_status_code(401)])
Options
async(boolean) - mark the trace as asynchronous, allowing child spans to finish within the TTL.annotations(list) - list of annotations to attach to main span.
See also
Tapper.Tracer.Timeout- timeout behaviour.Tapper.async/0annotation.
finish_span(id, opts \\ []) View Source
Finish a nested span, returning an updated Tapper.Id.
Arguments
id- Tapper id.
Options
annotations(list, atom, typle) - a list of annotations to attach the the span.
id = finish_span(id, annotations: Tapper.http_status_code(202))
join(arg, opts \\ []) View Source
join(trace_id, span_id, parent_id, sample, debug, opts \\ []) View Source
join an existing trace, e.g. server recieving an annotated request, returning a Tapper.Id for subsequent operations:
id = Tapper.join(trace_id, span_id, parent_id, sample, debug, name: "receive request")
NB Probably called by an integration (e.g. tapper_plug)
with name, annotations etc. added in the service code, so the name is optional here, see Tapper.name/1.
Arguments
trace_id- the incoming trace id.span_id- the incoming span id.parent_span_id- the incoming parent span id, or:rootif none.sampleis the incoming sampling status;trueimplies trace has been sampled, and down-stream spans should be sampled also,falsethat it will not be sampled, and down-stream spans should not be sampled either.debugis the debugging flag, iftruethis turns sampling for this trace on, regardless of the value ofsampled.
Options
name(String) name of span, see alsoTapper.name/1.annotations(list, atom or tuple) - a single annotation or list of annotations, specified byTapper.tag/3etc.type- the type of the span, i.e..:client,:server; defaults to:server; determines which ofsr(:server) orcs(:client) annotations is added. Defaults to:server.endpoint- sets the endpoint for the initialcrorsrannotation, defaults to one derived from Tapper configuration (seeTapper.Application.start/2).remote(Tapper.Endpoint) - the remote endpoint: automatically creates a "sa" (:client) or "ca" (:server) binary annotation on this span, see alsoTapper.server_address/1.ttl- how long this span should live between operations, before automatically finishing it (useful for long-running async operations); milliseconds.reporter(module atom or function) - override the configured reporter for this trace; useful for testing.
Notes
- If neither
samplenordebugare set, all operations on this trace become a no-op. typedetermines the type of an automatically createdsr(:server) orcs(:client) annotation, see alsoTapper.client_send/0andTapper.server_receive/0.
map_annotation_type(type) View Source
Provides some aliases for event annotation types:
| alias | annotation value |
|---|---|
| :client_send | cs |
| :client_recv | cr |
| :server_send | ss |
| :server_recv | sr |
| :wire_send | ws |
| :wire_recv | wr |
name_delta(name)
View Source
name_delta(name :: String.t() | atom()) :: Tapper.Tracer.Api.name_delta()
name_delta(name :: String.t() | atom()) :: Tapper.Tracer.Api.name_delta()
build an name-span action, suitable for passing to annotations option or update_span/3; see also Tapper.name/1.
start(opts \\ []) View Source
start a new root trace, e.g. on originating a request, e.g.:
id = Tapper.start(name: "request resource", type: :client, remote: remote_endpoint)
Options
name- the name of the span.sample(boolean) - whether to sample this trace or not.debug(boolean) - the debugging flag, iftruethis turns sampling for this trace on, regardless of the value ofsample.annotations(list, atom or tuple) - a single annotation or list of annotations, specified byTapper.tag/3etc.type(:client|:server) - the type of the span; defaults to:client1.remote- the remoteTapper.Endpoint: creates a "sa" (client) or "ca" (server) binary annotation on this span.ttl- how long this span should live before automatically finishing it (useful for long-running async operations); milliseconds.reporter(module atom or function) - override the configured reporter for this trace; useful for testing.
1 determines the type of an automatically created sr (type :server) or cs (type :client) annotation, see also Tapper.client_send/0 and Tapper.server_receive/0.
Notes
- If neither
samplenordebugare set, all operations on this trace become a no-op.
start_span(id, opts \\ []) View Source
Starts a child span, returning an updated Tapper.Id.
Arguments
id- Tapper id.options- see below.
Options
name(string) - name of span.local(string) - provide a local span context name (via alcbinary annotation).annotations(list, atom or tuple) - a list of annotations to attach to the span.
id = Tapper.start_span(id, name: "foo", local: "do foo", annotations: [Tapper.sql_query("select * from foo")])
update_span(id, deltas, opts \\ [])
View Source
update_span(
id :: Tapper.Id.t(),
deltas :: Tapper.Tracer.Api.delta() | [Tapper.Tracer.Api.delta()],
opts :: Keyword.t()
) :: Tapper.Id.t()
update_span( id :: Tapper.Id.t(), deltas :: Tapper.Tracer.Api.delta() | [Tapper.Tracer.Api.delta()], opts :: Keyword.t() ) :: Tapper.Id.t()
Add annotations to the current span; returns the same Tapper.Id.
Arguments
id- Tapper id.deltas- list, or single annotation tuple/atom. See helper functions.opts- keyword list of options.
Options
timestamp- an alternative timestamp for these annotations, e.g. fromTapper.Timestamp.instant/0.
Use with annotation helper functions:
id = Tapper.start_span(id)
Tapper.update_span(id, [
Tapper.async(),
Tapper.name("child"),
Tapper.http_path("/server/x"),
Tapper.tag("x", 101)
])