Telemetry integration for observability.
Puck automatically emits telemetry events when the :telemetry dependency
is installed. No configuration is required.
Events
Call Start
[:puck, :call, :start] - Executed before the LLM call.
Measurements
:system_time- The system time in native units.
Metadata
:client- ThePuck.Clientstruct.:prompt- The prompt content.:context- ThePuck.Contextstruct.
Call Stop
[:puck, :call, :stop] - Executed after a successful LLM call.
Measurements
:duration- Time taken in native units.
Metadata
:client- ThePuck.Clientstruct.:response- ThePuck.Responsestruct.:context- ThePuck.Contextstruct.
Call Exception
[:puck, :call, :exception] - Executed when the call fails.
Measurements
:duration- Time taken before failure in native units.
Metadata
:client- ThePuck.Clientstruct.:context- ThePuck.Contextstruct.:kind- The exception type (:error,:exit, or:throw).:reason- The error reason.:stacktrace- The stacktrace (may be empty).
Stream Start
[:puck, :stream, :start] - Executed before streaming begins.
Measurements
:system_time- The system time in native units.
Metadata
:client- ThePuck.Clientstruct.:prompt- The prompt content.:context- ThePuck.Contextstruct.
Stream Chunk
[:puck, :stream, :chunk] - Executed for each streamed chunk.
Measurements
No measurements.
Metadata
:client- ThePuck.Clientstruct.:chunk- The chunk data.:context- ThePuck.Contextstruct.
Stream Stop
[:puck, :stream, :stop] - Executed after streaming completes.
Measurements
:duration- Time taken in native units.
Metadata
:client- ThePuck.Clientstruct.:context- ThePuck.Contextstruct.
Stream Exception
[:puck, :stream, :exception] - Executed when streaming initialization fails.
Measurements
:duration- Time taken before failure in native units.
Metadata
:client- ThePuck.Clientstruct.:context- ThePuck.Contextstruct.:kind- The exception type (:error,:exit, or:throw).:reason- The error reason.:stacktrace- The stacktrace (may be empty).
Backend Request
[:puck, :backend, :request] - Executed before the backend request.
Measurements
:system_time- The system time in native units.
Metadata
:config- The backend configuration.:messages- The messages being sent.
Backend Response
[:puck, :backend, :response] - Executed after the backend response.
Measurements
:system_time- The system time in native units.
Metadata
:config- The backend configuration.:response- The backend response.
Compaction Start
[:puck, :compaction, :start] - Executed before context compaction.
Measurements
:system_time- The system time in native units.
Metadata
:context- ThePuck.Contextstruct before compaction.:strategy- The compaction strategy module.:config- The compaction configuration.
Compaction Stop
[:puck, :compaction, :stop] - Executed after successful compaction.
Measurements
:duration- Time taken in native units.:messages_before- Message count before compaction.:messages_after- Message count after compaction.
Metadata
:context- ThePuck.Contextstruct after compaction.:strategy- The compaction strategy module.
Compaction Error
[:puck, :compaction, :error] - Executed when compaction fails.
Measurements
:duration- Time taken before failure in native units.
Metadata
:context- ThePuck.Contextstruct.:strategy- The compaction strategy module.:reason- The error reason.
Attaching Handlers
:telemetry.attach_many("my-handler", Puck.Telemetry.event_names(), &handler/4, nil)
# Or use the default logger
Puck.Telemetry.attach_default_logger()
Summary
Functions
Attaches a default logging handler to all Puck telemetry events.
Detaches the default logging handler.
Returns all telemetry event names that can be emitted.
Functions
Attaches a default logging handler to all Puck telemetry events.
This is a convenience function for quick debugging. For production use, you should implement your own handler with appropriate log levels and formatting.
Options
:level- Log level to use (default::debug)
Example
Puck.Telemetry.attach_default_logger()
Puck.Telemetry.attach_default_logger(level: :info)
Detaches the default logging handler.
Returns all telemetry event names that can be emitted.
Useful for attaching handlers to all events.
Example
:telemetry.attach_many("my-handler", Puck.Telemetry.event_names(), &handler/4, nil)