Skip to content

OpenTelemetry SDK Configuration Not Applied Fix

DodaTech Updated 2026-06-24 3 min read

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_CONFIGURATOR for AWS-specific auto-configuration
  • Verify configuration with provider type introspection
  • Document required env vars in your deployment playbook

Common Mistakes with sdk config

  1. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  2. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  3. Misunderstanding that String is [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

### Which OTEL_* environment variables are most important?

The essential variables: OTEL_SERVICE_NAME, OTEL_TRACES_EXPORTER, OTEL_METRICS_EXPORTER, OTEL_LOGS_EXPORTER, OTEL_EXPORTER_OTLP_ENDPOINT, and OTEL_EXPORTER_OTLP_INSECURE (for non-TLS environments). All other settings have sensible defaults.

Why does programmatic config override environment variables?

The OpenTelemetry SDK reads environment variables at provider creation time. If you create a TracerProvider() without arguments, the SDK uses environment variables. If you pass arguments (like resource=...), those specific values override env vars but other settings still use env vars.

Can I mix environment variables and programmatic configuration?

Yes. Use programmatic configuration for settings that vary per-service (resource attributes, sampler rate) and environment variables for global settings (exporter type, endpoint). The SDK merges both sources, with programmatic values taking precedence.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro