PtcRunner.TraceLog.Handler (PtcRunner v0.7.0)

Copy Markdown View Source

Telemetry handler that captures SubAgent events for trace logging.

This handler attaches to all SubAgent telemetry events and forwards them to the Collector for writing to a JSONL file. Events are filtered by process - only events from processes that have an active collector in their TraceContext collector stack are captured.

Nested traces are supported - events are captured by all active collectors in the stack.

Summary

Functions

Attaches the handler to telemetry events.

Detaches the handler from telemetry events.

Returns the list of telemetry events this handler subscribes to.

Functions

attach(handler_id, collector, trace_id, meta \\ %{})

@spec attach(String.t(), pid(), String.t(), map()) :: :ok | {:error, :already_exists}

Attaches the handler to telemetry events.

Parameters

  • handler_id - Unique identifier for this handler attachment
  • collector - The Collector process to write events to
  • trace_id - The trace ID for this trace session
  • meta - Additional metadata to include with events (optional)

Examples

Handler.attach("my-trace", collector_pid, "trace-123")

detach(handler_id)

@spec detach(String.t()) :: :ok | {:error, :not_found}

Detaches the handler from telemetry events.

Parameters

  • handler_id - The handler ID that was used during attachment

Examples

Handler.detach("my-trace")

events()

@spec events() :: [[atom()]]

Returns the list of telemetry events this handler subscribes to.

handle_event(event, measurements, metadata, config)

@spec handle_event([atom()], map(), map(), map()) :: :ok

Handles a telemetry event.

Events are only captured if the calling process has the config's collector in its active TraceContext collector stack.

This function never raises - errors are logged at debug level to avoid crashing the caller's execution.