nemoguardrails.llm.telemetry

View as Markdown

Module Contents

Functions

NameDescription
_non_system_input_messages-
_set_llm_call_content_events-
_set_llm_call_content_json-
_stop_sequences-
_system_parts_from_messages-
_use_json_span_format-
llm_call_spanCreate a GenAI client span for one LLM call.
record_span_errorRecord error status and the exception type on a span.
set_llm_call_contentRecord LLM input and output content on a span when available.
set_llm_request_attributesRecord supported GenAI request parameters on a span.
set_llm_response_attributesRecord available model response metadata and token usage on a span.

Data

_GENAI_REQUEST_PARAMS

_LEGACY_EVENT_BY_ROLE

__all__

API

nemoguardrails.llm.telemetry._non_system_input_messages(
messages: list[dict[str, typing.Any]]
) -> list[dict]
nemoguardrails.llm.telemetry._set_llm_call_content_events(
span: opentelemetry.trace.Span,
input_messages: list[dict[str, typing.Any]],
output_text: typing.Optional[str]
) -> None
nemoguardrails.llm.telemetry._set_llm_call_content_json(
span: opentelemetry.trace.Span,
input_messages: list[dict[str, typing.Any]],
output_text: typing.Optional[str]
) -> None
nemoguardrails.llm.telemetry._stop_sequences(
params: dict
) -> typing.Optional[list]
nemoguardrails.llm.telemetry._system_parts_from_messages(
messages: list[dict[str, typing.Any]]
) -> list[dict]
nemoguardrails.llm.telemetry._use_json_span_format() -> bool
nemoguardrails.llm.telemetry.llm_call_span(
tracer: typing.Optional[opentelemetry.trace.Tracer],
model_name: str,
provider_name: str,
operation_name: str = 'chat'
) -> typing.Generator[typing.Optional[opentelemetry.trace.Span], None, None]

Create a GenAI client span for one LLM call.

Yields None when no tracer is configured. Provider exceptions from the wrapped call are recorded on the span and re-raised unchanged. Early stream closure (GeneratorExit) and task cancellation (CancelledError) are control flow, not provider failures, so they are re-raised without marking the span as an error.

nemoguardrails.llm.telemetry.record_span_error(
span: typing.Optional[opentelemetry.trace.Span],
exc: BaseException
) -> None

Record error status and the exception type on a span.

The exception message and stack trace are deliberately omitted: a provider error can embed request content, which must not reach telemetry unless content capture is explicitly enabled. Only the low-cardinality error type is recorded.

nemoguardrails.llm.telemetry.set_llm_call_content(
span: typing.Optional[opentelemetry.trace.Span],
input_messages: list[dict[str, typing.Any]],
output_text: typing.Optional[str] = None
) -> None

Record LLM input and output content on a span when available.

The configured OpenTelemetry content format determines whether content is stored as JSON attributes or legacy events. Telemetry failures are ignored so they cannot affect the model call.

nemoguardrails.llm.telemetry.set_llm_request_attributes(
span: typing.Optional[opentelemetry.trace.Span],
params: dict,
stream: bool = False
) -> None

Record supported GenAI request parameters on a span.

Unknown parameters are ignored, as are telemetry failures.

nemoguardrails.llm.telemetry.set_llm_response_attributes(
span: typing.Optional[opentelemetry.trace.Span],
model: typing.Optional[str] = None,
response_id: typing.Optional[str] = None,
finish_reason: typing.Optional[str] = None,
usage: typing.Optional[nemoguardrails.types.UsageInfo] = None
) -> None

Record available model response metadata and token usage on a span.

nemoguardrails.llm.telemetry._GENAI_REQUEST_PARAMS = {'temperature': GenAIAttributes.GEN_AI_REQUEST_TEMPERATURE, 'max_tokens': GenAIA...
nemoguardrails.llm.telemetry._LEGACY_EVENT_BY_ROLE = {'system': EventNames.GEN_AI_SYSTEM_MESSAGE, 'user': EventNames.GEN_AI_USER_MESS...
nemoguardrails.llm.telemetry.__all__ = ['llm_call_span', 'record_span_error', 'set_llm_call_content', 'set_llm_request_...