A simple and lightweight Python SDK for exporting OpenTelemetry logs, metrics, and traces to OpenObserve.
Generate auth token:
echo -n "root@example.com:Complexpass#123" | base64
# Output: cm9vdEBleGFtcGxlLmNvbTpDb21wbGV4cGFzcyMxMjM=Set environment variables:
# Optional (defaults shown below)
export OPENOBSERVE_URL="http://localhost:5080" # default
export OPENOBSERVE_ORG="default" # default
# Required
export OPENOBSERVE_AUTH_TOKEN="Basic cm9vdEBleGFtcGxlLmNvbTpDb21wbGV4cGFzcyMxMjM="
export OPENAI_API_KEY="your-api-key"
export ANTHROPIC_API_KEY="your-api-key"Install dependencies:
uv pip install openai opentelemetry-instrumentation-openaiUse with OpenAI:
from opentelemetry.instrumentation.openai import OpenAIInstrumentor
from openobserve import openobserve_init
# Initialize OpenObserve and instrument OpenAI
OpenAIInstrumentor().instrument()
openobserve_init()
from openai import OpenAI
# Use OpenAI as normal - traces are automatically captured
client = OpenAI()
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)openobserve_init() initializes logs, metrics, and traces when no signal arguments are provided. As soon as you pass any of the logs, metrics, or traces flags, only the explicitly provided signals are enabled.
# All signals (logs + metrics + traces)
openobserve_init()
# Logs only
openobserve_init(logs=True)
# Logs + metrics (no traces)
openobserve_init(logs=True, metrics=True)| Variable | Required | Description |
|---|---|---|
OPENOBSERVE_URL |
No | OpenObserve base URL (default: "http://localhost:5080") |
OPENOBSERVE_ORG |
No | Organization name (default: "default") |
OPENOBSERVE_AUTH_TOKEN |
✅ | Authorization token (Format: "Basic ") |
OPENOBSERVE_TIMEOUT |
No | Request timeout in seconds (default: 30) |
OPENOBSERVE_ENABLED |
No | Enable/disable tracing (default: "true") |
OPENOBSERVE_PROTOCOL |
No | Protocol: "grpc" or "http/protobuf" (default: "http/protobuf") |
OPENOBSERVE_TRACES_STREAM_NAME |
No | Stream name for traces (default: "default") |
OPENOBSERVE_LOGS_STREAM_NAME |
No | Stream name for logs (default: "default") |
HTTP/Protobuf (default)
- Uses HTTP with Protocol Buffers encoding.
- Works with both HTTP and HTTPS endpoints.
- Organization is specified in the URL path:
/api/{org}/v1/{signal}, where{signal}istraces,logs, ormetrics. - Automatically adds the
stream-nameheader fromOPENOBSERVE_TRACES_STREAM_NAMEfor traces andOPENOBSERVE_LOGS_STREAM_NAMEfor logs. - Standard HTTP header handling (preserves case).
gRPC
- Uses gRPC protocol with automatic configuration:
- Organization is passed as a header (not in the URL).
- Automatically adds required headers:
organization: Set toOPENOBSERVE_ORG.stream-name: Set toOPENOBSERVE_TRACES_STREAM_NAMEfor traces andOPENOBSERVE_LOGS_STREAM_NAMEfor logs.
- Headers are normalized to lowercase per gRPC specification.
- TLS is automatically configured based on URL scheme:
http://URLs use insecure (non-TLS) connections.https://URLs use secure (TLS) connections.
# Install the SDK (includes both HTTP/Protobuf and gRPC support)
uv pip install -e .
# Or using requirements.txt
uv pip install -r requirements.txtexamples/openai_example.py– end-to-end traces example with the OpenAI instrumentation.examples/logs_example.py– bridges standard Python logging through OpenTelemetry and ships the records to OpenObserve. Run withuv run examples/logs_example.py.examples/metrics_example.py– demonstrates counters, histograms, and up/down counters exported to OpenObserve. Run withuv run examples/metrics_example.py.examples/session_demo.py,examples/qa_chain.py, etc. – additional traces-first demos.
MIT