Skip to main content

The scheduler that nobody wants but every application needs.

Project description

Esmerald Datadog

Esmerald

🚀 ASGI integration with TimingASGIMiddleware for Esmerald . 🚀

Test Suite Package version Supported Python versions


Esmerald Documentation: https://esmerald.dymmond.com 📚

Esmerald Source Code: https://github.com/dymmond/esmerald


Motivation

This is an Esmerald integration to use the TimingMiddleware.

TimingMiddleware for ASGI is useful for automatic instrumentation of ASGI endpoints.

This package is an extension allowing the integration with Esmerald.

Requirements

Usage

import uvicorn
from esmerald_timing.integrations import EsmeraldScopeToName
from timing_asgi import TimingClient, TimingMiddleware

from esmerald import Gateway, Request, get
from esmerald.applications import Esmerald
from esmerald.responses import PlainTextResponse


class PrintTimings(TimingClient):
    def timing(self, metric_name, timing, tags):
        print(metric_name, timing, tags)


@get("/")
def homepage(request: Request) -> PlainTextResponse:
    return PlainTextResponse("Welcome to Esmerald!")


app = Esmerald(routes=[Gateway(handler=homepage)])

app.add_middleware(
    TimingMiddleware,
    client=PrintTimings(),
    metric_namer=EsmeraldScopeToName(prefix="myapp", esmerald_app=app),
)

if __name__ == "__main__":
    uvicorn.run(app)

Running this example and sending some requests:

$ python app.py
INFO:     Started server process [18769]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     127.0.0.1:58132 - "GET / HTTP/1.1" 200 OK
myapp.__main__.homepage 0.0009038448333740234 ['http_status:200', 'http_method:GET', 'time:wall']
myapp.__main__.homepage 0.0008970000000000367 ['http_status:200', 'http_method:GET', 'time:cpu']
myapp.favicon.ico 0.0006134510040283203 ['http_status:404', 'http_method:GET', 'time:wall']
myapp.favicon.ico 0.0006120000000000569 ['http_status:404', 'http_method:GET', 'time:cpu']
INFO:     127.0.0.1:58132 - "GET / HTTP/1.1" 200 OK
myapp.__main__.homepage 0.000881195068359375 ['http_status:200', 'http_method:GET', 'time:wall']
myapp.__main__.homepage 0.0008829999999999671 ['http_status:200', 'http_method:GET', 'time:cpu']
INFO:     127.0.0.1:58132 - "GET / HTTP/1.1" 200 OK
myapp.__main__.homepage 0.0014600753784179688 ['http_status:200', 'http_method:GET', 'time:wall']
myapp.__main__.homepage 0.0014729999999998356 ['http_status:200', 'http_method:GET', 'time:cpu']

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

esmerald_timing-0.1.0.tar.gz (4.7 kB view hashes)

Uploaded Source

Built Distribution

esmerald_timing-0.1.0-py3-none-any.whl (4.8 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