Graphene-Django middleware for GraphQL observability: Prometheus metrics and structured query logging.
Project description
graphene-django-observability
Prometheus metrics and structured query logging for graphene-django — works with any Django project.
Overview
graphene-django-observability is a generic Django library that provides comprehensive observability for any graphene-django GraphQL API.
It ships two Graphene middlewares that instrument every GraphQL operation with Prometheus metrics and optional structured query logging — with zero changes to your application code.
Features
Prometheus Metrics (PrometheusMiddleware):
- Request metrics: Count and measure the duration of all GraphQL queries and mutations.
- Error tracking: Count errors by operation and exception type.
- Query depth & complexity: Histogram metrics for nesting depth and total field count.
- Per-user tracking: Count requests per authenticated user for auditing and capacity planning.
- Per-field resolution: Optionally measure individual field resolver durations (useful for debugging).
- A built-in
/metrics/endpoint is provided for Prometheus scraping.
Query Logging (GraphQLQueryLoggingMiddleware):
- Structured log entries: Operation type, name, user, duration, and status for every query.
- Optional query body and variables: Include the full query text and variables in log entries.
- Standard Python logging: Route logs to any backend (file, syslog, ELK, Loki, etc.) via Django's
LOGGINGconfiguration.
Quick Install
pip install graphene-django-observability
# settings.py
INSTALLED_APPS = [
...
"graphene_django_observability",
]
MIDDLEWARE = [
...
"graphene_django_observability.django_middleware.GraphQLObservabilityDjangoMiddleware",
]
GRAPHENE = {
"SCHEMA": "myapp.schema.schema",
"MIDDLEWARE": [
"graphene_django_observability.middleware.PrometheusMiddleware",
# optional structured query logging:
"graphene_django_observability.logging_middleware.GraphQLQueryLoggingMiddleware",
],
}
# optional — expose a /metrics/ endpoint
# urls.py
from django.urls import include, path
urlpatterns = [
...
path("graphql-observability/", include("graphene_django_observability.urls")),
]
Configuration
All settings are optional. Configure via GRAPHENE_OBSERVABILITY in settings.py:
GRAPHENE_OBSERVABILITY = {
# Paths to instrument (default: ["/graphql/"])
"graphql_paths": ["/graphql/"],
# Prometheus metrics
"graphql_metrics_enabled": True,
"track_query_depth": True,
"track_query_complexity": True,
"track_field_resolution": False, # enables per-field timing (high overhead)
"track_per_user": True,
# Query logging
"query_logging_enabled": False,
"log_query_body": False,
"log_query_variables": False, # warning: may log sensitive data
}
Prometheus Metrics
| Metric | Type | Labels | Description |
|---|---|---|---|
graphql_requests_total |
Counter | operation_type, operation_name, status |
Total requests (success / error). |
graphql_request_duration_seconds |
Histogram | operation_type, operation_name |
Full request duration in seconds. |
graphql_errors_total |
Counter | operation_type, operation_name, error_type |
Errors by exception type. |
graphql_query_depth |
Histogram | operation_name |
Query nesting depth. |
graphql_query_complexity |
Histogram | operation_name |
Total field count. |
graphql_field_resolution_duration_seconds |
Histogram | type_name, field_name |
Per-field resolver duration (opt-in). |
graphql_requests_by_user_total |
Counter | user, operation_type, operation_name |
Requests per authenticated user. |
Documentation
Full documentation is available in the docs folder:
- User Guide (
docs/user/) — Overview, Getting Started, Use Cases, FAQ. - Administrator Guide (
docs/admin/) — Installation, Configuration, Upgrade, Uninstall. - Developer Guide (
docs/dev/) — Extending, Code Reference, Contributing.
Questions & Contributing
For questions, check the FAQ or open an issue. Contributions are very welcome — see the contributing guide.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file graphene_django_observability-1.0.0.tar.gz.
File metadata
- Download URL: graphene_django_observability-1.0.0.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4d91ffef26edb42b5dd629e438e070492c3822ac8eb22b0751a57132dcb668a
|
|
| MD5 |
2860162ffc1f0c7195172fb18fe5ddc8
|
|
| BLAKE2b-256 |
a6d9774d1141ccee35b3d276b3bb3c087aaf0e4858ac18a8afa9f61d1d904a9c
|
Provenance
The following attestation bundles were made for graphene_django_observability-1.0.0.tar.gz:
Publisher:
release.yml on slydien/graphene-django-observability
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
graphene_django_observability-1.0.0.tar.gz -
Subject digest:
a4d91ffef26edb42b5dd629e438e070492c3822ac8eb22b0751a57132dcb668a - Sigstore transparency entry: 973748972
- Sigstore integration time:
-
Permalink:
slydien/graphene-django-observability@7415904edaa7da972c76cfc495eb3ab41bf1f798 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/slydien
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7415904edaa7da972c76cfc495eb3ab41bf1f798 -
Trigger Event:
release
-
Statement type:
File details
Details for the file graphene_django_observability-1.0.0-py3-none-any.whl.
File metadata
- Download URL: graphene_django_observability-1.0.0-py3-none-any.whl
- Upload date:
- Size: 21.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26658bc67bbaf0d2580826b0212d3ef65ec8d410a9bde4bb9485ffcd1ebecebf
|
|
| MD5 |
ca624a474eef67515326e61dfbcfbce1
|
|
| BLAKE2b-256 |
0f71a864a93c3bab0e53a12507adf7741d762ee938f78f391ac184e7afd44936
|
Provenance
The following attestation bundles were made for graphene_django_observability-1.0.0-py3-none-any.whl:
Publisher:
release.yml on slydien/graphene-django-observability
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
graphene_django_observability-1.0.0-py3-none-any.whl -
Subject digest:
26658bc67bbaf0d2580826b0212d3ef65ec8d410a9bde4bb9485ffcd1ebecebf - Sigstore transparency entry: 973749075
- Sigstore integration time:
-
Permalink:
slydien/graphene-django-observability@7415904edaa7da972c76cfc495eb3ab41bf1f798 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/slydien
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7415904edaa7da972c76cfc495eb3ab41bf1f798 -
Trigger Event:
release
-
Statement type: