Telemetry handler that re-emits LangChain telemetry events as GenAI Semantic Convention-aligned intermediary metric events.
Important: This module does not directly record OpenTelemetry histograms
or counters. It emits :telemetry.execute/3 events that must be consumed by
a metrics library to become actual OTel metrics. Without a consumer attached
to these events, enable_metrics: true has no visible effect.
To produce actual OTel metrics, attach a consumer such as Telemetry.Metrics
with an OpenTelemetry reporter, PromEx, or equivalent to the events below.
Emitted events
[:langchain, :otel, :operation, :duration]— with%{duration_s: float()}measurement and GenAI attributes as metadata. Emitted for both successful (:stop) and failed (:exception) operations; failures additionally carry anerror.typeattribute so error rate is observable alongside latency.[:langchain, :otel, :token, :usage]— with%{tokens: integer()}measurement and GenAI attributes (includinggen_ai.token.type) as metadata[:langchain, :otel, :operation, :time_to_first_token]— with%{duration_s: float()}measurement and GenAI attributes as metadata. Emitted once per streaming LLM call, measuring the time from request start to the first streamed chunk (aligns with the semantic-conventiongen_ai.server.time_to_first_tokenmetric).
Usage
This module is used internally by LangChain.OpenTelemetry.setup/1 when
enable_metrics: true (the default). You typically don't need to interact
with it directly.
Summary
Functions
Returns the list of telemetry events this handler attaches to.
Telemetry handler callback. Re-emits duration and token usage metric events.
Returns the telemetry handler ID prefix used for attaching/detaching.