ReqLLM.OpenTelemetry.Content (ReqLLM v1.14.0)

View Source

Shapes ReqLLM request and response payloads into the GenAI content attributes — gen_ai.input.messages, gen_ai.system_instructions, gen_ai.tool.definitions, gen_ai.output.messages.

Used by both ReqLLM.OpenTelemetry and ReqLLM.Telemetry.OpenTelemetry when content capture is opted in (content: :attributes or :event — default is :none). The caller must also have raw payload telemetry on (telemetry: [payloads: :raw]) for the request payload to be available.

Span attribute content is JSON-encoded before being returned, so attribute values are [String.t()] (an array of primitives — what the OpenTelemetry attribute spec accepts and what GenAI-aware backends like Langfuse, Honeycomb, and Grafana decode for display). Event content remains structured for the gen_ai.client.inference.operation.details event. request_attributes/1 returns roughly:

%{
  "gen_ai.system_instructions" => [
    ~s({"type":"text","content":"You are a helpful assistant."})
  ],
  "gen_ai.input.messages" => [
    ~s({"role":"user","parts":[{"type":"text","content":"Hi"}]})
  ],
  "gen_ai.tool.definitions" => [
    ~s({"type":"function","name":"get_weather","parameters":{...}})
  ]
}

Reasoning text is excluded in every mode — ReqLLM's payload sanitizer redacts it before this module sees the messages, and content parts are filtered to spec-friendly types (text, image, image_url, video_url, file) so thinking output cannot leak through.

Summary

Functions

Returns the input-message list for gen_ai.input.messages, excluding any system messages (which are exposed via system_instructions/1). Each message is JSON-encoded so the result is a primitive-array attribute value.

Returns the response message list for gen_ai.output.messages. Each message is JSON-encoded so the result is a primitive-array attribute value.

Builds the request-side content-attribute map (input messages, system instructions, tool definitions). Empty values are dropped.

Builds the request-side content-event map with structured values.

Builds the response-side content-attribute map (output messages).

Builds the response-side content-event map with structured values.

Returns the gen_ai.system_instructions part list extracted from system messages in the request payload. Reasoning text is intentionally excluded. Each part is JSON-encoded so the result is a primitive-array attribute value.

Returns tool definitions for gen_ai.tool.definitions from the request payload. Each tool is JSON-encoded so the result is a primitive-array attribute value (entries decode to %{"type" => "function", "name" => ..., ...}).

Functions

input_messages(metadata)

@spec input_messages(map()) :: [String.t()]

Returns the input-message list for gen_ai.input.messages, excluding any system messages (which are exposed via system_instructions/1). Each message is JSON-encoded so the result is a primitive-array attribute value.

output_messages(metadata)

@spec output_messages(map()) :: [String.t()]

Returns the response message list for gen_ai.output.messages. Each message is JSON-encoded so the result is a primitive-array attribute value.

request_attributes(metadata)

@spec request_attributes(map()) :: %{optional(String.t()) => term()}

Builds the request-side content-attribute map (input messages, system instructions, tool definitions). Empty values are dropped.

request_event_attributes(metadata)

@spec request_event_attributes(map()) :: %{optional(String.t()) => term()}

Builds the request-side content-event map with structured values.

response_attributes(metadata)

@spec response_attributes(map()) :: %{optional(String.t()) => term()}

Builds the response-side content-attribute map (output messages).

response_event_attributes(metadata)

@spec response_event_attributes(map()) :: %{optional(String.t()) => term()}

Builds the response-side content-event map with structured values.

system_instructions(metadata)

@spec system_instructions(map()) :: [String.t()]

Returns the gen_ai.system_instructions part list extracted from system messages in the request payload. Reasoning text is intentionally excluded. Each part is JSON-encoded so the result is a primitive-array attribute value.

tool_definitions(metadata)

@spec tool_definitions(map()) :: [String.t()]

Returns tool definitions for gen_ai.tool.definitions from the request payload. Each tool is JSON-encoded so the result is a primitive-array attribute value (entries decode to %{"type" => "function", "name" => ..., ...}).