OpenTelemetry Auto-Instrumentation Not Working Fix
In this tutorial, you'll learn about OpenTelemetry Auto. We cover key concepts, practical examples, and best practices.
Your OpenTelemetry auto-instrumentation produces no spans — the application runs normally but no trace data is exported. The instrumentation agent is not attached, the packages are not installed, or the environment variables are misconfigured.
The Problem
# WRONG: running without auto-instrumentation
python app.py
The application starts and processes requests, but no tracing data is generated. The OpenTelemetry agent was never attached to the Python process.
Step-by-Step Fix
1. Install auto-instrumentation packages
pip install opentelemetry-distro opentelemetry-instrumentation
# Install specific instrumentations
pip install opentelemetry-instrumentation-flask
pip install opentelemetry-instrumentation-requests
pip install opentelemetry-instrumentation-django
pip install opentelemetry-instrumentation-sqlalchemy
2. Run with the instrumentation agent
# Python — use opentelemetry-instrument
opentelemetry-instrument \
--traces_exporter otlp \
--metrics_exporter otlp \
--logs_exporter otlp \
--service_name myapp \
python app.py
3. Configure via environment variables
export OTEL_SERVICE_NAME=myapp
export OTEL_TRACES_EXPORTER=otlp
export OTEL_METRICS_EXPORTER=otlp
export OTEL_LOGS_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
export OTEL_EXPORTER_OTLP_INSECURE=true
export OTEL_PYTHON_DISABLED_INSTRUMENTATIONS=
opentelemetry-instrument python app.py
4. Verify instrumentation is active
# Add a test endpoint to verify
from flask import Flask
app = Flask(__name__)
@app.route("/health")
def health():
return {"status": "ok"}
if __name__ == "__main__":
app.run(port=8080)
# Run with instrumentation
opentelemetry-instrument python app.py
# In another terminal, generate traffic
curl http://localhost:8080/health
5. Check for common issues
# Verify packages are installed
pip list | grep opentelemetry
# Check for version conflicts
pip check
# Run with debug logging
OTEL_PYTHON_LOG_LEVEL=debug opentelemetry-instrument python app.py
6. Java auto-instrumentation
# Download the Java agent JAR
wget https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar
# Run with the agent
java -javaagent:opentelemetry-javaagent.jar \
-Dotel.service.name=myapp \
-Dotel.traces.exporter=otlp \
-Dotel.exporter.otlp.endpoint=http://localhost:4317 \
-jar myapp.jar
Expected output:
2026-06-24T10:00:00.000Z INFO Starting OpenTelemetry instrumentation
2026-06-24T10:00:00.050Z INFO Flask instrumented — 3 middleware(s) added
2026-06-24T10:00:00.100Z INFO Requests instrumented
✓ Spans being exported to OTLP endpoint
Prevention Tips
- Install all required instrumentation packages for your framework
- Use
opentelemetry-instrumentwrapper instead of running the app directly - Set environment variables for consistent configuration
- Verify with a test endpoint before production deployment
- Check version compatibility between instrumentation packages
Common Mistakes with auto instrumentation
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
- Misunderstanding that
Stringis[Char]with poor performance for large text operations - Using
foldlinstead offoldl'causing stack overflow on large lists
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