Skip to main content

Web util for OpenTelemetry

Project description

pypi

This library provides ASGI, WSGI middleware and other HTTP-related functionality that is common to instrumented web frameworks (such as Django, Starlette, FastAPI, etc.) to track requests timing through OpenTelemetry.

Installation

pip install opentelemetry-util-http

Usage (Quart)

from quart import Quart
from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware

app = Quart(__name__)
app.asgi_app = OpenTelemetryMiddleware(app.asgi_app)

@app.route("/")
async def hello():
    return "Hello!"

if __name__ == "__main__":
    app.run(debug=True)

Usage (Django 3.0)

Modify the application’s asgi.py file as shown below.

import os
from django.core.asgi import get_asgi_application
from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'asgi_example.settings')

application = get_asgi_application()
application = OpenTelemetryMiddleware(application)

Usage (Raw ASGI)

from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware

app = ...  # An ASGI application.
app = OpenTelemetryMiddleware(app)

References

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

opentelemetry_util_http-0.45b0.tar.gz (7.2 kB view hashes)

Uploaded Source

Built Distribution

opentelemetry_util_http-0.45b0-py3-none-any.whl (6.9 kB view hashes)

Uploaded Python 3

Supported by

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