Skip to content

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

FilePurpose
python-service/src/instrument.pySentry OTLP integration setup
python-service/src/app.pyFlask application with auto-instrumentation
python-service/.envConfiguration (just needs SENTRY_DSN)

Running the Python Service

  1. Install dependencies

    The setup script creates a virtual environment and installs dependencies:

    Terminal window
    npm run python:install
  2. Configure environment

    Terminal window
    npm run python:setup

    Then edit python-service/.env and add your Sentry DSN:

    Terminal window
    SENTRY_DSN=https://YOUR_PUBLIC_KEY@YOUR-ORG-ID.ingest.us.sentry.io/YOUR-PROJECT-ID
    DATABASE_URL=postgresql://user:password@host/database
  3. Start the service

    Terminal window
    npm run python

    You 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_sdk
from sentry_sdk.integrations.otlp import OTLPIntegration
# OpenTelemetry auto-instrumentation
from opentelemetry.instrumentation.flask import FlaskInstrumentor
from opentelemetry.instrumentation.requests import RequestsInstrumentor
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
# Initialize Sentry with OTLP integration
sentry_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-instrumentation
FlaskInstrumentor().instrument()
RequestsInstrumentor().instrument()
SQLAlchemyInstrumentor().instrument()

What the OTLPIntegration Does Automatically

When you add OTLPIntegration() to your Sentry SDK init, it:

  1. Extracts the OTLP endpoint from your DSN (no manual configuration needed!)
  2. Configures the SpanExporter to send traces to Sentry
  3. Sets up propagators for distributed tracing (W3C traceparent/baggage)
  4. 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)

Terminal window
# .env - just ONE line needed for Sentry!
SENTRY_DSN=https://key@org.ingest.us.sentry.io/project
# Python - 3 lines of Sentry config
sentry_sdk.init(
dsn=os.environ.get("SENTRY_DSN"),
integrations=[OTLPIntegration()],
)

Node.js (Direct SDK)

Terminal window
# .env - FOUR lines needed for Sentry!
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://org.ingest.us.sentry.io/api/project/integration/otlp/v1/logs
OTEL_EXPORTER_OTLP_LOGS_HEADERS=x-sentry-auth=sentry sentry_key=key
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://org.ingest.us.sentry.io/api/project/integration/otlp/v1/traces
OTEL_EXPORTER_OTLP_TRACES_HEADERS=x-sentry-auth=sentry sentry_key=key
// Node.js - manual exporter configuration
const 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

  1. Generate traffic

    Terminal window
    # Check service health
    curl http://localhost:3003/health
    # Get inventory data
    curl http://localhost:3003/api/inventory
  2. Verify in Sentry

    1. Go to your Sentry project
    2. Navigate to ExploreTraces
    3. 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 traceparent headers 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