ReqLLM.OpenTelemetry.Shared (ReqLLM v1.12.0)

View Source

Cross-cutting helpers shared by ReqLLM.OpenTelemetry and ReqLLM.Telemetry.OpenTelemetry — option parsing, Langfuse cost-details merging, error rendering.

Both surfaces accept the same :content and :langfuse options and need to render error values the same way. This module is where that small but easy-to-drift logic lives.

content_mode/1 resolves the user-facing option to a canonical mode:

content_mode(content: :attributes)  #=> :attributes
content_mode(content: true)         #=> :attributes
content_mode(content: :event)       #=> :event
content_mode([])                    #=> :none

merge_langfuse/3 adds "langfuse.observation.cost_details" (a JSON-encoded input/output/reasoning/total breakdown) to an attribute map when langfuse: true is set and ReqLLM has cost data. If encoding fails it logs at debug and drops the attribute rather than raising — span emission keeps working.

Summary

Functions

Resolves the :content option to one of :none | :attributes | :event.

Renders an error value into a span-status / exception-event message string.

Merges langfuse.observation.cost_details into attributes when langfuse: true is set in opts and ReqLLM has a cost breakdown.

Types

content_mode()

@type content_mode() :: :none | :attributes | :event

Functions

content_mode(opts)

@spec content_mode(keyword()) :: content_mode()

Resolves the :content option to one of :none | :attributes | :event.

Accepts true as an alias for :attributes and false (or anything unrecognized) as an alias for :none.

error_message(error)

@spec error_message(any()) :: String.t() | nil

Renders an error value into a span-status / exception-event message string.

merge_langfuse(attributes, metadata, opts)

@spec merge_langfuse(map(), map(), keyword()) :: map()

Merges langfuse.observation.cost_details into attributes when langfuse: true is set in opts and ReqLLM has a cost breakdown.