OpenTelemetry SDK Configuration Not Applied Fix
In this tutorial, you'll learn about OpenTelemetry SDK Configuration Not Applied Fix. We cover key concepts, practical examples, and best practices.
Your OpenTelemetry SDK ignores OTEL_TRACES_EXPORTER=otlp and falls back to console export — the environment variables are not read, the SDK is configured before setting variables, or the programmatic configuration overrides environment defaults.
The Problem
export OTEL_TRACES_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
# WRONG: SDK manually configured after setting env vars
provider = TracerProvider()
# This overrides env vars — sets exporter to None
trace.set_tracer_provider(provider)
The SDK's auto-configuration uses environment variables by default. Overriding the provider programmatically without specifying an exporter disables the OTLP exporter.
Step-by-Step Fix
1. Let the SDK auto-configure from env vars
from opentelemetry import trace
# No programmatic configuration — SDK reads OTEL_* env vars
trace.get_tracer_provider()
export OTEL_SERVICE_NAME=myapp
export OTEL_TRACES_EXPORTER=otlp
export OTEL_METRICS_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
export OTEL_EXPORTER_OTLP_INSECURE=true
python app.py
2. Use environment variables with programmatic config
import os
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
# Read env vars explicitly
endpoint = os.environ.get("OTEL_EXPORTER_OTLP_ENDPOINT", "http://localhost:4317")
insecure = os.environ.get("OTEL_EXPORTER_OTLP_INSECURE", "true").lower() == "true"
provider = TracerProvider()
processor = BatchSpanProcessor(
OTLPSpanExporter(endpoint=endpoint, insecure=insecure)
)
provider.add_span_processor(processor)
trace.set_tracer_provider(provider)
3. Use OTEL_PYTHON_CONFIGURATOR
# Enable the auto-configurator
export OTEL_PYTHON_CONFIGURATOR=opentelemetry-sdk-extension-aws
from opentelemetry.sdk.extension.aws import AwsConfigurator
configurator = AwsConfigurator()
configurator.configure()
4. Configure all signals via environment variables
# Service identity
export OTEL_SERVICE_NAME=payment-service
export OTEL_RESOURCE_ATTRIBUTES=service.version=1.0,deployment.environment=staging
# Traces
export OTEL_TRACES_EXPORTER=otlp
export OTEL_BSP_SCHEDULE_DELAY=5000
export OTEL_BSP_MAX_EXPORT_BATCH_SIZE=512
# Metrics
export OTEL_METRICS_EXPORTER=otlp
export OTEL_METRIC_EXPORT_INTERVAL=30000
# Logs
export OTEL_LOGS_EXPORTER=otlp
# OTLP endpoint
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
export OTEL_EXPORTER_OTLP_INSECURE=true
export OTEL_EXPORTER_OTLP_PROTOCOL=grpc
5. Verify configuration
from opentelemetry import trace, metrics, _logs
# Check what's configured
tp = trace.get_tracer_provider()
print(f"Tracer provider: {type(tp).__name__}")
mp = metrics.get_meter_provider()
print(f"Meter provider: {type(mp).__name__}")
lp = _logs.get_logger_provider()
print(f"Logger provider: {type(lp).__name__}")
Expected output:
Tracer provider: TracerProvider
Meter provider: MeterProvider
Logger provider: LoggerProvider
All configured from environment variables
Prevention Tips
- Use environment variables for configuration — avoid hardcoded provider setup
- Set
OTEL_*variables before the Python process starts - Use
OTEL_PYTHON_CONFIGURATORfor AWS-specific auto-configuration - Verify configuration with provider type introspection
- Document required env vars in your deployment playbook
Common Mistakes with sdk config
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
- Misunderstanding that
Stringis[Char]with poor performance for large text operations
These mistakes appear frequently in real-world OPENTELEMETRY code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro