Documentation Django Middleware
5 min read | June 24, 2026
Tutorial

Django Middleware

The Astralog Django middleware seamlessly integrates into the Django request-response lifecycle to track latencies and errors without impacting response times.

View on GitHub

Installation

pip install astralog-django astralog

Setup

Simply add your Token and the Middleware to your settings.py.

# settings.py
ASTRALOG_API_KEY = "ast_sk_live_xxxxxxxxxxxxx"

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    # Place the Astralog middleware as high as possible
    'astralog.middlewares.AstralogDjangoMiddleware',
    'django.middleware.common.CommonMiddleware',
]

How it works

Django’s synchronous architecture can be susceptible to blocking operations. Astralog solves this by passing the captured telemetry to the Astralog core client, which handles the network dispatch inside a separated background daemon thread, guaranteeing that your Django Views execute at maximum speed.