ReqLLM.OpenTelemetry (ReqLLM v1.9.0)

View Source

Bridges ReqLLM request lifecycle telemetry into OpenTelemetry GenAI client spans.

This module listens to the existing [:req_llm, :request, *] events and emits a single client span per model call. The span follows the OpenTelemetry Generative AI semantic conventions where ReqLLM has normalized data available, including:

  • gen_ai.provider.name
  • gen_ai.operation.name
  • gen_ai.request.model
  • gen_ai.output.type
  • gen_ai.response.finish_reasons
  • gen_ai.usage.*
  • error.type

Span export remains opt-in at the application level. You still need OpenTelemetry dependencies and SDK/exporter configuration in your host app. When the OpenTelemetry API modules are not available, attach/2 returns {:error, :opentelemetry_unavailable}.

For custom tracer integrations that want richer message and tool-call mapping without binding ReqLLM to a specific OpenTelemetry SDK, see ReqLLM.Telemetry.OpenTelemetry.

Summary

Functions

Attaches the OpenTelemetry bridge to ReqLLM request lifecycle events.

Returns whether the configured OpenTelemetry adapter is available.

Detaches the OpenTelemetry bridge and clears any in-flight spans for the handler.

Returns the request lifecycle events used by the bridge.

Returns the GenAI span name for a ReqLLM request.

Types

attach_opt()

@type attach_opt() :: {:adapter, module()} | {:handler_id, term()} | {atom(), term()}

Functions

attach(handler_id \\ "req-llm-open-telemetry", opts \\ [])

@spec attach(
  term(),
  keyword()
) :: :ok | {:error, :already_exists | :opentelemetry_unavailable}

Attaches the OpenTelemetry bridge to ReqLLM request lifecycle events.

available?(opts \\ [])

@spec available?(keyword()) :: boolean()

Returns whether the configured OpenTelemetry adapter is available.

detach(handler_id \\ "req-llm-open-telemetry")

@spec detach(term()) :: :ok

Detaches the OpenTelemetry bridge and clears any in-flight spans for the handler.

events()

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

Returns the request lifecycle events used by the bridge.

span_name(metadata)

@spec span_name(map()) :: String.t()

Returns the GenAI span name for a ReqLLM request.