Skip to content
This repository was archived by the owner on Oct 21, 2024. It is now read-only.

Latest commit

 

History

History
60 lines (36 loc) · 1.28 KB

File metadata and controls

60 lines (36 loc) · 1.28 KB

OpenTelemetry ASGI Middleware

pypi

This library provides a ASGI middleware that can be used on any ASGI framework (such as Django, Starlette, FastAPI or Quart) 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 3.0)

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

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

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

application = get_asgi_application()
application = OpenTelemetryMiddleware(application)

References