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.
Metadata
Release files for graphene-django-observability 1.0.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 | Provenance | Actions |
|---|---|---|---|---|
| graphene_django_observability-1.0.0.tar.gz | 16.1 kB | With provenance | Details for graphene_django_observability-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| graphene_django_observability-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for graphene_django_observability-1.0.0-py3-none-any.whl |
Total release size: 37.0 kB
Release files / graphene_django_observability-1.0.0.tar.gz
| Download URL | graphene_django_observability-1.0.0.tar.gz |
|---|---|
| Size | 16.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a4d91ffef26edb42b5dd629e438e070492c3822ac8eb22b0751a57132dcb668a
|
|
BLAKE2b-256 checksum How to use checksums |
a6d9774d1141ccee35b3d276b3bb3c087aaf0e4858ac18a8afa9f61d1d904a9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 20, 2026.
Transparency logRelease files / graphene_django_observability-1.0.0-py3-none-any.whl
| Download URL | graphene_django_observability-1.0.0-py3-none-any.whl |
|---|---|
| Size | 21.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
26658bc67bbaf0d2580826b0212d3ef65ec8d410a9bde4bb9485ffcd1ebecebf
|
|
BLAKE2b-256 checksum How to use checksums |
0f71a864a93c3bab0e53a12507adf7741d762ee938f78f391ac184e7afd44936
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 20, 2026.
Transparency logSecurity for graphene-django-observability 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for graphene_django_observability-1.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.