Plugin that provides observability callbacks for Malla services.
This module defines the callback interface that telemetry plugins can override to integrate with observability backends (OpenTelemetry, Datadog, etc.).
For the user-facing API, see Malla.Tracer.
For comprehensive documentation, see the guide:
- Tracing and Instrumentation: For a guide on how to use the tracer.
Summary
Callbacks
Creates a tracing span around the given code block.
Record an error within the current span.
Record an event within a span.
Get the base span context for propagation.
Set global attributes that apply to all spans in this context.
Retrieve information about the current span.
Set labels for the current span.
Log a message within the current span.
Record a metric within a span.
Update the current span with new attributes.
Types
@type span_id() :: Malla.Tracer.span_id()
Callbacks
Creates a tracing span around the given code block.
Called when user code uses Malla.Tracer.span/2 or span/3 macros.
By default, it will simply:
- Call
Malla.metric([:malla, :tracer, :starts], %{counter: 1}, %{span_name: name, opts: opts}) - Execute the code
- Call
Malla.metric([:malla, :tracer, :stops], %{counter: 1}, %{span_name: name, result: res})
Record an error within the current span.
Called when user code calls Malla.Tracer.error/1 with a non-string value.
It simply returns the error unchanged.
Record an event within a span.
Called when user code calls Malla.Tracer.event/1, event/2, or event/3.
By default it does nothing.
@callback malla_span_get_base() :: any()
Get the base span context for propagation.
Called when user code calls Malla.Tracer.get_base/0.
By default it returns nil.
Set global attributes that apply to all spans in this context.
Called when user code calls Malla.Tracer.globals/1.
By default it does nothing.
Retrieve information about the current span.
Called when user code calls Malla.Tracer.get_info/0 or get_info/1.
By default it returns nil.
Set labels for the current span.
Called when user code calls Malla.Tracer.labels/1.
By default it does nothing.
@callback malla_span_log( atom() | pos_integer(), String.t() | (-> String.t()), keyword() | map() ) :: :ok
Log a message within the current span.
Called when user code calls logging macros like debug/1, info/1, etc.
By default it delegates to Elixir's Logger.bare_log/3 with appropriate level mapping.
Record a metric within a span.
Called when user code calls Malla.Tracer.metric/2 or metric/3.
By default it calls Malla.metric([:malla, :tracer, id], data, meta)
@callback malla_span_update(keyword()) :: :ok
Update the current span with new attributes.
Called when user code calls Malla.Tracer.span_update/1.
By default it does nothing.