nemoguardrails.tracing.adapters.opentelemetry

View as Markdown

OpenTelemetry Adapter for NeMo Guardrails

This adapter follows OpenTelemetry best practices for libraries:

  • Uses only the OpenTelemetry API (not SDK)
  • Does not modify global state
  • Relies on the application to configure the SDK

Module Contents

Classes

NameDescription
OpenTelemetryAdapterOpenTelemetry adapter that follows library best practices.

Functions

NameDescription
_get_base_time_nsGet the base time in nanoseconds for tracing spans.

API

class nemoguardrails.tracing.adapters.opentelemetry.OpenTelemetryAdapter(
service_name: str = 'nemo_guardrails'
)

Bases: InteractionLogAdapter

OpenTelemetry adapter that follows library best practices.

This adapter uses only the OpenTelemetry API and relies on the application to configure the SDK. It does not modify global state or create its own tracer provider.

name
= 'OpenTelemetry'
tracer
nemoguardrails.tracing.adapters.opentelemetry.OpenTelemetryAdapter._create_span(
span_data,
parent_context,
spans,
base_time_ns
)

Create OTel span from a span.

This is a pure API bridge - all semantic attributes are extracted by the formatting function. We only handle:

  1. Timestamp conversion (relative to absolute)
  2. Span kind mapping (string to enum)
  3. API calls to create spans and events
nemoguardrails.tracing.adapters.opentelemetry.OpenTelemetryAdapter.transform(
interaction_log: 'InteractionLog'
)

Transforms the InteractionLog into OpenTelemetry spans.

nemoguardrails.tracing.adapters.opentelemetry.OpenTelemetryAdapter.transform_async(
interaction_log: 'InteractionLog'
)
async

Transforms the InteractionLog into OpenTelemetry spans asynchronously.

nemoguardrails.tracing.adapters.opentelemetry._get_base_time_ns(
interaction_log: nemoguardrails.tracing.InteractionLog
) -> int

Get the base time in nanoseconds for tracing spans.

Parameters:

interaction_log
InteractionLog

The interaction log containing rail timing information

Returns: int

Base time in nanoseconds, either from the first activated rail or current time