ReqLLM.Telemetry
(ReqLLM v1.11.0)
View Source
Shared telemetry helpers for ReqLLM request lifecycle instrumentation.
This module owns:
- request correlation IDs
- request lifecycle events
- reasoning lifecycle events
- summary extraction
- payload policy
- compatibility emission for
[:req_llm, :token_usage]
Summary
Functions
Emits the compatibility token usage event.
Emits request exception telemetry and returns the updated context.
Builds a telemetry context for a request lifecycle.
Observes a terminal response and updates response and reasoning state.
Observes a streaming chunk and emits milestone-based reasoning updates.
Stores telemetry context in a Req request.
Stores telemetry context in a Req response private map.
Returns the normalized metadata map for reasoning lifecycle events.
Reads telemetry context from a Req request.
Returns the private key used to store telemetry context on Req requests.
Returns the normalized request metadata map for request lifecycle events.
Emits request start telemetry and returns the updated context.
Emits request stop telemetry and returns the updated context.
Extracts token usage metadata from a Req response private map.
Types
@type context() :: %{ request_id: String.t(), model: LLMDB.Model.t(), operation: atom(), mode: lifecycle_mode(), transport: transport(), payload_mode: payload_mode(), reasoning_contract: reasoning_contract(), original_opts: keyword(), request_summary: map(), request_payload: any(), request_started?: boolean(), request_stopped?: boolean(), started_at: integer() | nil, request_measurement: map() | nil, requested_reasoning: map(), effective_reasoning: map(), reasoning_started?: boolean(), reasoning_started_at: integer() | nil, reasoning_observation: map(), response_summary_state: map() }
@type lifecycle_mode() :: :sync | :stream
@type payload_mode() :: :none | :raw
@type reasoning_contract() ::
:openai_effort
| :openai_or_thinking
| :anthropic_thinking
| :platform_anthropic
| :google_budget
| :alibaba_thinking
| :thinking_toggle
| :zenmux_reasoning
| :unsupported
@type transport() :: :req | :finch
Functions
@spec emit_token_usage(LLMDB.Model.t(), map() | nil, keyword()) :: :ok
Emits the compatibility token usage event.
@spec exception_request(context(), Exception.t() | term(), keyword()) :: context()
Emits request exception telemetry and returns the updated context.
@spec new_context(LLMDB.Model.t(), keyword(), keyword()) :: context()
Builds a telemetry context for a request lifecycle.
Observes a terminal response and updates response and reasoning state.
@spec observe_stream_chunk(context(), ReqLLM.StreamChunk.t()) :: context()
Observes a streaming chunk and emits milestone-based reasoning updates.
@spec put_request_context(Req.Request.t(), context()) :: Req.Request.t()
Stores telemetry context in a Req request.
@spec put_response_context(Req.Response.t(), context()) :: Req.Response.t()
Stores telemetry context in a Req response private map.
Returns the normalized metadata map for reasoning lifecycle events.
@spec request_context(Req.Request.t()) :: context() | nil
Reads telemetry context from a Req request.
@spec request_context_key() :: atom()
Returns the private key used to store telemetry context on Req requests.
Returns the normalized request metadata map for request lifecycle events.
Emits request start telemetry and returns the updated context.
Emits request stop telemetry and returns the updated context.
Extracts token usage metadata from a Req response private map.