Esmerald Datadog
🚀 ASGI integration with TimingASGIMiddleware for Esmerald . 🚀
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
- Python 3.7 +
- Esmerald
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']
Metadata
Release files for esmerald-timing 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| esmerald_timing-0.1.0.tar.gz | 4.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| esmerald_timing-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.5 kB
Release files / esmerald_timing-0.1.0.tar.gz
| Download URL | esmerald_timing-0.1.0.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ae091bb1bd020db71b0686c5dbda0f8f48a9d4c314852324f35883f117f3a2c4
|
|
BLAKE2b-256 checksum How to use checksums |
876e0f4af35ca5f4f2957d592a1a15f8092740a4a803aa6ec45ac61dee8400a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.15
|
Release files / esmerald_timing-0.1.0-py3-none-any.whl
| Download URL | esmerald_timing-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a2a0fd7fbbe492d7e7fd5d817865cf6743307dbbe808a686e242eae1b4d1a8d7
|
|
BLAKE2b-256 checksum How to use checksums |
24beff7b4244b8d5ddfb947fe8db04f459c2e25271d63138c0bcb5666ba95626
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.15
|