Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

otel_metry-0.2.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

otel_metry-0.2.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file otel_metry-0.2.0.tar.gz.

File metadata

  • Download URL: otel_metry-0.2.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for otel_metry-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2332524ba5c81524831f122cfc91a602c255925f466ad6d565a16ef10bfb1cb0
MD5 929136266a4cba70887c31afd90142e8
BLAKE2b-256 dfe238f9beff1c1df5dee672225ba91fbe9ae1e8387ef5e315ba72d0480b431a

See more details on using hashes here.

File details

Details for the file otel_metry-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: otel_metry-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for otel_metry-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da9fc0fe97b1ed6cc3f408f1c5d1886a8fd73c466463d4a02236fd37d6d462be
MD5 490a6e5c032f590077f4bd9cac708354
BLAKE2b-256 7652c936057cf9f408dd4f5391807e50dde3a5ca3e2b79d1c59900133330b7c5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page