Implementation:Guardrails ai Guardrails Settings OpenTelemetry
| Knowledge Sources | |
|---|---|
| Domains | Observability, Monitoring |
| Last Updated | 2026-02-14 00:00 GMT |
Overview
Concrete configuration classes for managing server mode and OpenTelemetry tracing provided by the guardrails package.
Description
This is a Wrapper Doc covering the Settings singleton and OpenTelemetry integration. The Settings singleton (thread-safe, lazily initialized) provides use_server for enabling client-server mode and disable_tracing for controlling telemetry. The guardrails/telemetry/ module provides trace decorators and span management that integrate with the OpenTelemetry SDK.
Usage
Import the settings singleton to configure server mode and tracing. Set environment variables for OTLP export configuration.
Code Reference
Source Location
- Repository: guardrails
- Files:
- guardrails/settings.py (L1-50)
- guardrails/telemetry/__init__.py (L1-38)
Signature
class Settings:
"""Thread-safe singleton for global configuration."""
use_server: Optional[bool] # Route Guard calls to server
disable_tracing: Optional[bool] # Disable OpenTelemetry tracing
@property
def rc(self) -> RC:
"""Access the .guardrailsrc configuration."""
...
Import
from guardrails.settings import settings
# Settings is a singleton - access directly
settings.use_server = True
settings.disable_tracing = False
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| settings.use_server | Optional[bool] | No | Enable server mode for Guard calls |
| settings.disable_tracing | Optional[bool] | No | Disable OpenTelemetry tracing |
| OTEL_EXPORTER_OTLP_ENDPOINT | Env Var | No | OTLP exporter endpoint URL |
| OTEL_EXPORTER_OTLP_PROTOCOL | Env Var | No | OTLP protocol (grpc or http/protobuf) |
Outputs
| Name | Type | Description |
|---|---|---|
| Traces | OpenTelemetry Spans | Guard execution, validation, and LLM call traces |
| Settings state | Singleton | Global configuration accessible throughout the framework |
Usage Examples
Configure Tracing
import os
from guardrails.settings import settings
# Enable tracing to Jaeger
os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "http://localhost:4317"
os.environ["OTEL_EXPORTER_OTLP_PROTOCOL"] = "grpc"
# Ensure tracing is enabled
settings.disable_tracing = False
Configure Server Mode
from guardrails.settings import settings
# Route all Guard calls to a server
settings.use_server = True
os.environ["GUARDRAILS_BASE_URL"] = "http://guardrails-server:8000"
Disable Tracing
from guardrails.settings import settings
settings.disable_tracing = True