Skip to content

Latest commit

 

History

History
61 lines (38 loc) · 1.29 KB

File metadata and controls

61 lines (38 loc) · 1.29 KB

OpenTelemetry ASGI Middleware

pypi

This library provides a ASGI middleware that can be used on any ASGI framework (such as Django / Flask) to track requests timing through OpenTelemetry.

Installation

pip install opentelemetry-ext-asgi

Usage (Quart)

from quart import Quart
from opentelemetry.ext.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)

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

import os
import django
from channels.routing import get_default_application
from opentelemetry.ext.asgi import OpenTelemetryMiddleware

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings')
django.setup()

application = get_default_application()
application = OpenTelemetryMiddleware(application)

References