instrument_flight_recorder (instrument v1.0.0)
View SourceFlight recorder for low-overhead message tracing.
This module captures message passing events at VM level with minimal overhead, correlating them with OpenTelemetry spans via trace_id labels.
Uses erlang:trace with a custom erl_tracer NIF that distributes events across a pool of workers, avoiding the single-process bottleneck of seq_trace.
Example Usage
%% Flight recorder starts enabled by default
instrument_tracer:with_span(<<"request">>, fun() ->
%% All message passing captured with trace_id label
gen_server:call(some_server, request),
another_process ! message
end),
%% On error or slow request, dump the trace
TraceId = instrument_tracer:trace_id(),
Events = instrument_flight_recorder:get_trace(TraceId).
Summary
Functions
Clears all events from the buffer.
Disables the flight recorder. Stops the worker pool. Buffer is retained.
Gets all events in the buffer.
Gets and clears all events for a trace ID.
Enables the flight recorder. Starts the worker pool and enables tracing.
Gets all events for a trace ID. Returns events as a list of {Timestamp, Event} tuples.
Checks if the flight recorder is enabled.
Adds a custom marker event with current trace context.
Adds a custom marker event with metadata.
Sets the buffer size (for testing). Takes effect immediately.
Starts the flight recorder with default options.
Starts the flight recorder with options.
Returns statistics about the flight recorder.
Gets the tracer state for use with erlang:trace.
Functions
-spec clear() -> ok.
Clears all events from the buffer.
-spec disable() -> ok.
Disables the flight recorder. Stops the worker pool. Buffer is retained.
Gets all events in the buffer.
Gets and clears all events for a trace ID.
-spec enable() -> ok.
Enables the flight recorder. Starts the worker pool and enables tracing.
Gets all events for a trace ID. Returns events as a list of {Timestamp, Event} tuples.
-spec is_enabled() -> boolean().
Checks if the flight recorder is enabled.
-spec mark(binary()) -> ok.
Adds a custom marker event with current trace context.
Adds a custom marker event with metadata.
-spec set_buffer_size(pos_integer()) -> ok.
Sets the buffer size (for testing). Takes effect immediately.
Starts the flight recorder with default options.
Starts the flight recorder with options.
-spec stats() -> map().
Returns statistics about the flight recorder.
Gets the tracer state for use with erlang:trace.