Using Sentry SDK with OTLP Integration
Overview
The Sentry SDK’s OTLP integration provides the simplest way to send OpenTelemetry data to Sentry. Unlike the direct SDK approach or collector approach, you don’t need to manually configure OTLP endpoints or authentication headers.
How the Demo App Uses This
The demo includes a Python Inventory Service that demonstrates the OTLP integration. This service:
- Runs on
http://localhost:3003 - Uses Flask with OpenTelemetry auto-instrumentation
- Sends traces directly to Sentry using only the DSN
Key Files
| File | Purpose |
|---|---|
python-service/src/instrument.py | Sentry OTLP integration setup |
python-service/src/app.py | Flask application with auto-instrumentation |
python-service/.env | Configuration (just needs SENTRY_DSN) |
Running the Python Service
-
Install dependencies
The setup script creates a virtual environment and installs dependencies:
Terminal window npm run python:install -
Configure environment
Terminal window npm run python:setupThen edit
python-service/.envand add your Sentry DSN:Terminal window SENTRY_DSN=https://YOUR_PUBLIC_KEY@YOUR-ORG-ID.ingest.us.sentry.io/YOUR-PROJECT-IDDATABASE_URL=postgresql://user:password@host/database -
Start the service
Terminal window npm run pythonYou should see output like:
📡 Service: python-inventory-service🔭 Sentry OTLP integration initialized✅ Flask app running on http://localhost:3003
What’s Happening Behind the Scenes
The Instrumentation File
The magic happens in python-service/src/instrument.py. Here’s the key setup:
# From python-service/src/instrument.py
import sentry_sdkfrom sentry_sdk.integrations.otlp import OTLPIntegration
# OpenTelemetry auto-instrumentationfrom opentelemetry.instrumentation.flask import FlaskInstrumentorfrom opentelemetry.instrumentation.requests import RequestsInstrumentorfrom opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
# Initialize Sentry with OTLP integrationsentry_sdk.init( dsn=os.environ.get("SENTRY_DSN"), environment=os.environ.get("ENVIRONMENT", "development"), send_default_pii=True, enable_logs=True, integrations=[ OTLPIntegration(), ],)
# Set up OpenTelemetry auto-instrumentationFlaskInstrumentor().instrument()RequestsInstrumentor().instrument()SQLAlchemyInstrumentor().instrument()What the OTLPIntegration Does Automatically
When you add OTLPIntegration() to your Sentry SDK init, it:
- Extracts the OTLP endpoint from your DSN (no manual configuration needed!)
- Configures the SpanExporter to send traces to Sentry
- Sets up propagators for distributed tracing (W3C traceparent/baggage)
- Links traces with errors so exceptions are connected to their trace context
Comparison: Python vs Node.js Setup
Here’s why the Python OTLP integration is simpler:
Python (with OTLPIntegration)
# .env - just ONE line needed for Sentry!SENTRY_DSN=https://key@org.ingest.us.sentry.io/project# Python - 3 lines of Sentry configsentry_sdk.init( dsn=os.environ.get("SENTRY_DSN"), integrations=[OTLPIntegration()],)Node.js (Direct SDK)
# .env - FOUR lines needed for Sentry!OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://org.ingest.us.sentry.io/api/project/integration/otlp/v1/logsOTEL_EXPORTER_OTLP_LOGS_HEADERS=x-sentry-auth=sentry sentry_key=keyOTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://org.ingest.us.sentry.io/api/project/integration/otlp/v1/tracesOTEL_EXPORTER_OTLP_TRACES_HEADERS=x-sentry-auth=sentry sentry_key=key// Node.js - manual exporter configurationconst traceExporter = new OTLPTraceExporter({ url: process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT,});const logExporter = new OTLPLogExporter({ url: process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT,});Testing the Integration
-
Generate traffic
Terminal window # Check service healthcurl http://localhost:3003/health# Get inventory datacurl http://localhost:3003/api/inventory -
Verify in Sentry
- Go to your Sentry project
- Navigate to Explore › Traces
- Look for traces from
python-inventory-service
Distributed Tracing
The Python service can participate in distributed traces with the Node.js services. The OTLPIntegration automatically:
- Reads incoming
traceparentheaders from requests - Propagates trace context to outgoing requests
- Ensures all services appear in the same trace waterfall
When you call the Python service from the Node.js gateway, you’ll see the complete trace across both services in Sentry.
Language Support
The OTLP integration is currently available for:
- Python (3.7+) -
sentry-sdk[opentelemetry-otlp] - JavaScript/Node.js - Coming soon!
Check the Sentry documentation for the latest language support.
What’s Next?
- Try distributed tracing: Call the Python service from the Node.js services and see the complete trace
- Compare approaches: Run direct mode, collector mode, and Python service side-by-side