Skip to main content

Unofficial ddtrace integration for ASGI apps and frameworks

Project description

ddtrace-asgi

Build Status Coverage Package version

Unofficial ddtrace integration for ASGI apps and frameworks.

Should work seamlessly for any ASGI web framework, e.g. Starlette, FastAPI, Quart, etc.

Note: This project is in alpha stage.

Installation

pip install ddtrace-asgi

Quickstart

To automatically send traces to Datadog APM on each HTTP request, wrap your ASGI application around TraceMiddleware:

# app.py
from ddtrace import tracer
from ddtrace_asgi.middleware import TraceMiddleware

async def app(scope, receive, send):
    assert scope["type"] == "http"
    headers = [[b"content-type", b"text/plain"]]
    await send({"type": "http.response.start", "status": 200, "headers": headers})
    await send({"type": "http.response.body", "body": b"Hello, world!"})

app = TraceMiddleware(app, tracer, service="asgi-hello-world")

Then use ddtrace-run when serving your application. For example, if serving with Uvicorn:

ddtrace-run uvicorn app:app

For more information on using ddtrace, please see the official ddtrace repository.

Examples

Starlette
from ddtrace import tracer
from ddtrace_asgi.middleware import TraceMiddleware
from starlette.applications import Starlette

app = Starlette()
app = TraceMiddleware(app, tracer, service="my-starlette-app")

API Reference

TracingMiddleware

class TracingMiddleware:
    def __init__(self, app, tracer, service="asgi", distributed_tracing=True):
        ...

An ASGI middleware that sends traces of HTTP requests to Datadog APM.

Parameters

  • app - An ASGI application.
  • tracer - A Tracer object.
  • service - (optional) Name of the service as it will appear on Datadog.
  • distributed_tracing - (optional) Whether to enable distributed tracing.

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog.

0.1.0 - 2019-10-23

Initial release.

Added

  • Add TracingMiddleware.

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

ddtrace-asgi-0.1.0.tar.gz (5.1 kB view details)

Uploaded Source

File details

Details for the file ddtrace-asgi-0.1.0.tar.gz.

File metadata

  • Download URL: ddtrace-asgi-0.1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

File hashes

Hashes for ddtrace-asgi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1e09b41bd8a19055aa59d077e69aecd780523f668dedb337cacc59a4010da7d2
MD5 95a19d15689cd41b08fd351056f47ba5
BLAKE2b-256 72370ba569a2cd8b970159cdd8a5729f059bad2b3513441f5d763b63c0d3fb74

See more details on using hashes here.

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