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

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

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

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

Link to this function

add_event(name, attrs)

Simple wrapper around OpenTelemetry.Span.add_event/2

@spec current_span() :: any()

Returns the current span that can be used to add new events or attributes

Simple wrapper around OpenTelemetry.Tracer.end_span/0

Link to this function

extract(keywords)

Helper function for propogating opentelemetry

Link to this function

extract_map(map)

Helper function for propogating opentelemetry by using a map

Link to this function

inject(keywords \\ [])

Helper function for propogating opentelemetry

Link to this function

inject_map(meta \\ %{})

Helper function for propogating opentelemetry by using a map

Link to this function

monitor(span \\ nil)

Helper function to start Tracing.Monitor

Link to this function

set_attributes(attrs)

Simple wrapper around OpenTelemetry.Span.set_attributes/2

Link to this function

set_current_span(span \\ current_span())

Sets the current span to current_span() or what is provided

Link to this function

setup(elements)

Link to this function

setup_element(arg1)

@spec trace_id() :: String.t()

Returns hexadecimal string you can use to query in Honeycomb on trace.trace_id

Link to this macro

with_span(name, opts \\ quote do %{} end, list)

(macro)

Simple wrapper around OpenTelemetry.Tracer.with_span/3

Link to this macro

with_span_fn(name, opts \\ quote do %{} end, fun)

(macro)

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 to true to monitor the process