Zero-config OpenTelemetry auto-instrumentation for Flask apps with CubeAPM
Project description
otel-metry
Zero-config OpenTelemetry auto-instrumentation for Flask apps. One init() call and your app exports traces and metrics to CubeAPM (or any OTLP-compatible backend).
Installation
pip install otel-metry
With optional instrumentors:
pip install otel-metry[all] # requests, sqlalchemy, redis, psycopg2, celery
pip install otel-metry[requests] # just requests
Quick Start
import otelmetry
otelmetry.init(endpoint="http://cubeapm:4317", service_name="my-app")
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World"
That's it. All Flask requests, database queries, and outgoing HTTP calls are traced automatically.
Configuration
Programmatic
otelmetry.init(
endpoint="http://cubeapm:4317",
service_name="my-app",
insecure=True,
resource_attributes={"deployment.environment": "production"},
)
Environment Variables
| Variable | Fallback | Default |
|---|---|---|
OTEL_METRY_ENDPOINT |
OTEL_EXPORTER_OTLP_ENDPOINT |
http://localhost:4317 |
OTEL_METRY_SERVICE_NAME |
OTEL_SERVICE_NAME |
unknown-service |
OTEL_METRY_INSECURE |
— | true |
OTEL_METRY_ENABLED |
— | true |
Zero-Code (env vars only)
export OTEL_METRY_ENDPOINT=http://cubeapm:4317
export OTEL_METRY_SERVICE_NAME=my-app
import otelmetry.auto # auto-initializes from env vars
from flask import Flask
app = Flask(__name__)
Auto-Instrumented Libraries
If installed, the following are instrumented automatically:
- Flask (always)
- requests — outgoing HTTP calls
- SQLAlchemy — database queries
- Redis — cache operations
- psycopg2 — PostgreSQL queries
- Celery — task queues
API
otelmetry.init(...) # Initialize (call once)
otelmetry.shutdown() # Flush and stop (called automatically on exit)
otelmetry.get_tracer(name) # Get a tracer for manual spans
otelmetry.get_meter(name) # Get a meter for custom metrics
With Gunicorn
# gunicorn.conf.py
def post_fork(server, worker):
import otelmetry
otelmetry.init(endpoint="http://cubeapm:4317", service_name="my-app")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file otel_metry-0.1.0.tar.gz.
File metadata
- Download URL: otel_metry-0.1.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16c8d9e31ae5822f9e5efa7d2ad5ef524c590094d64f5ae3fcc496390a678bca
|
|
| MD5 |
667c06939ff5ef9a00546c93bb9234f0
|
|
| BLAKE2b-256 |
76bb0881a8314681be5034299ec5bc51220c01da4c7107e6425427df9351918e
|
File details
Details for the file otel_metry-0.1.0-py3-none-any.whl.
File metadata
- Download URL: otel_metry-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
675c27474868d98c6514bb6e3860a91501053ed2a31eeae3646cee2481e568ed
|
|
| MD5 |
2bfb84ef42c2f80c030e1ab6ef68075e
|
|
| BLAKE2b-256 |
180243db8f39ddc2b7d322201850c0b1f98f4a96c252ec2fec5f2406e829009a
|