Tracing (Tracing v0.2.0)
OpenTelemetry convenience module for often repeated patterns
Tracing with a span
require Tracing
Tracing.with_span "this_is_my_span" do
// do_work()
end
Also see with_span_fn/2-3
for continued tracing within a spawned process.
Using the function decorator
use Tracing
@decorate with_span()
def do_work do
// do_more_work()
end
Summary
Functions
Simple wrapper around OpenTelemetry.Span.add_event/2
Returns the current span that can be used to add new events or attributes
Simple wrapper around OpenTelemetry.Tracer.end_span/0
Helper function for propogating opentelemetry
Helper function for propogating opentelemetry by using a map
Helper function for propogating opentelemetry
Helper function for propogating opentelemetry by using a map
Helper function to start Tracing.Monitor
Simple wrapper around OpenTelemetry.Span.set_attributes/2
Sets the current span to current_span() or what is provided
Returns hexadecimal string you can use to query in Honeycomb on trace.trace_id
Simple wrapper around OpenTelemetry.Tracer.with_span/3
Use this function when defining an anonymous function that will be used in another process. This function will ensure that the span in the parent process is the parent span of the span in the spawned process.
Functions
add_event(name, attrs)
Simple wrapper around OpenTelemetry.Span.add_event/2
current_span()
@spec current_span() :: any()
Returns the current span that can be used to add new events or attributes
end_span()
Simple wrapper around OpenTelemetry.Tracer.end_span/0
extract(keywords)
Helper function for propogating opentelemetry
extract_map(map)
Helper function for propogating opentelemetry by using a map
inject(keywords \\ [])
Helper function for propogating opentelemetry
inject_map(meta \\ %{})
Helper function for propogating opentelemetry by using a map
monitor(span \\ nil)
Helper function to start Tracing.Monitor
set_attributes(attrs)
Simple wrapper around OpenTelemetry.Span.set_attributes/2
set_current_span(span \\ current_span())
Sets the current span to current_span() or what is provided
setup(elements)
setup_element(arg1)
trace_id()
@spec trace_id() :: String.t()
Returns hexadecimal string you can use to query in Honeycomb on trace.trace_id
Simple wrapper around OpenTelemetry.Tracer.with_span/3
Use this function when defining an anonymous function that will be used in another process. This function will ensure that the span in the parent process is the parent span of the span in the spawned process.
Examples
spawn(Tracing.with_span_fn("do something", [key: :value], fn -> do_something() end))
Task.start_link(Tracing.with_span_fn("do something", fn -> do_something() end))
Task.async_stream(things, Tracing.with_span_fn("do something", fn thing -> do_something(thing) end))
Task.start_link(Tracing.with_span_fn(&do_something/0))
Options
You can pass options which are forwarded to OpenTelemetry.Tracer.with_span/3
. There is one
special option that will also monitor the spawned process and close the span correctly.
:monitor
- set totrue
to monitor the process