Observability
OpenTelemetry helpers for GLLM Inference.
LMSpanAttributeSetter(logger)
Writes canonical GenAI text content attributes onto an invocation span.
Initialize the span attribute setter with the invoker's logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger
|
The logger used to record optional content serialization failures. |
required |
set_input_content(span, trace_context, messages)
Record enabled canonical input parts without modifying the source messages.
Text, tool-call, and tool-result parts are independently controlled by their respective input capture options. Unrepresentable parts are skipped without affecting the remaining content; tool results are emitted in canonical tool-role messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
span
|
Span
|
The invocation span to record the attribute on. |
required |
trace_context
|
LMTraceContext
|
Invocation-scoped trace state. |
required |
messages
|
list[Message]
|
The effective messages to serialize. |
required |
set_output_content(span, trace_context, output)
Record canonical output parts without modifying the normalized result.
Text, structured, and thinking parts are each independently opt-in and keep the
ordering of LMOutput.outputs. A part whose value cannot be converted to JSON is
skipped without affecting the remaining parts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
span
|
Span
|
The invocation span to record the attribute on. |
required |
trace_context
|
LMTraceContext
|
Invocation-scoped trace state. |
required |
output
|
LMOutput
|
The model output to serialize. |
required |
set_response_metadata(span, output)
Record allowlisted optional response metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
span
|
Span
|
The invocation span to record the attribute on. |
required |
output
|
LMOutput
|
The model output containing optional response metadata. |
required |
set_system_instructions(span, trace_context, messages)
Record the source system instruction when provider handling removed it from history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
span
|
Span
|
The invocation span to record the attribute on. |
required |
trace_context
|
LMTraceContext
|
Invocation-scoped trace state. |
required |
messages
|
list[Message]
|
The effective messages after provider system handling. |
required |
set_tool_definitions(span, trace_context, tools)
Record configured tool definitions without exposing native-tool configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
span
|
Span
|
The invocation span to record the attribute on. |
required |
trace_context
|
LMTraceContext
|
Invocation-scoped trace state. |
required |
tools
|
list[Tool | NativeTool]
|
Configured function and provider-native tools. |
required |
set_usage(span, output)
Record available token usage attributes on a completed model-operation span.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
span
|
Span
|
The invocation span to record the attributes on. |
required |
output
|
LMOutput
|
The LMOutput object containing token usage information. |
required |
LMTraceContentConfig
Bases: ContentCaptureConfig
Model to hold configuration settings for capturing LM trace content.
Attributes:
| Name | Type | Description |
|---|---|---|
system_instructions |
bool
|
Whether to capture system instructions. Defaults to False. |
tool_definitions |
bool
|
Whether to capture configured tool definitions. Defaults to False. |
input_text |
bool
|
Whether to capture input text. Defaults to False. |
input_tool_calls |
bool
|
Whether to capture tool calls in input history. Defaults to False. |
input_tool_results |
bool
|
Whether to capture tool results in input history. Defaults to False. |
input_attachments |
bool
|
Whether to capture input attachments. Defaults to False. |
output_text |
bool
|
Whether to capture output text. Defaults to False. |
output_structured |
bool
|
Whether to capture structured output. Defaults to False. |
output_thinking |
bool
|
Whether to capture thinking output. Defaults to False. |
output_tool_calls |
bool
|
Whether to capture model-produced tool calls. Defaults to False. |
output_attachments |
bool
|
Whether to capture generated attachments. Defaults to False. |
output_citations |
bool
|
Whether to capture output citations. Defaults to False. |
output_code_exec_results |
bool
|
Whether to capture code execution results. Defaults to False. |
output_mcp_calls |
bool
|
Whether to capture MCP calls. Defaults to False. |
max_attribute_bytes |
int
|
Maximum number of bytes to capture for each attribute. Defaults to DEFAULT_MAX_ATTRIBUTE_BYTES. |
has_input_capture_enabled
property
Return whether any input trace-content capture option is enabled.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True when input text, tool calls, tool results, or attachments are captured. |
has_output_capture_enabled
property
Return whether any output trace-content capture option is enabled.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True when any supported output content category is captured. |
LMTraceContext
Bases: BaseModel
Invocation-scoped trace state shared across provider calls in a tool loop.
Attributes:
| Name | Type | Description |
|---|---|---|
trace_attributes |
dict[str, TraceValue]
|
Validated caller-supplied span attributes. |
trace_config |
LMTraceContentConfig
|
Invocation-scoped content capture config snapshot. |
system_instruction |
str | None
|
Source system text from the caller's history. Defaults to None. |
get_tracer()
Gets the GLLM Inference tracer singleton.
Returns:
| Type | Description |
|---|---|
Tracer
|
trace.Tracer: The versioned tracer for GLLM Inference instrumentation. |