Package
nautobot_graphql_observability
¶
App declaration for nautobot_graphql_observability.
NautobotAppGraphqlObservabilityConfig
¶
Bases: NautobotAppConfig
App configuration for the nautobot_graphql_observability app.
Source code in nautobot_graphql_observability/__init__.py
ready()
¶
Patch Nautobot's GraphQLDRFAPIView to load Graphene middleware from settings.
Nautobot's GraphQLDRFAPIView.init_graphql() does not load middleware
from GRAPHENE["MIDDLEWARE"] when self.middleware is None (the
default). This is a known limitation of the DRF-based GraphQL view —
the standard graphene_django.views.GraphQLView (used by the GraphiQL
UI at /graphql/) loads middleware correctly.
No official extension point (override_views, etc.) can replace this
patch because the graphql-api URL is registered without a namespace.
Request duration and query logging are handled by
:class:~nautobot_graphql_observability.django_middleware.GraphQLObservabilityDjangoMiddleware,
which is registered via :attr:middleware (the official Nautobot mechanism).
Source code in nautobot_graphql_observability/__init__.py
nautobot_graphql_observability.middleware
¶
Graphene middleware for exporting Prometheus metrics from GraphQL queries.
PrometheusMiddleware
¶
Graphene middleware that instruments GraphQL resolvers with Prometheus metrics.
On root-level resolutions, records counters and advanced metrics immediately
(these are not timing-sensitive) and stashes operation labels onto the
request so that :class:PrometheusDjangoMiddleware can record the duration
histogram after the full HTTP response is built.
Optionally records advanced metrics based on app configuration:
track_query_depth: Record query nesting depth histogram.track_query_complexity: Record query field count histogram.track_field_resolution: Record per-field resolver duration histogram.track_per_user: Record per-user request counter.
Usage in Django settings::
GRAPHENE = {
"MIDDLEWARE": [
"nautobot_graphql_observability.middleware.PrometheusMiddleware",
]
}
Source code in nautobot_graphql_observability/middleware.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
resolve(next, root, info, **kwargs)
¶
Intercept each field resolution and record metrics.
Root-level resolutions (root is None) record counters and advanced metrics and stash labels for the Django middleware to record duration. Nested resolutions optionally record per-field duration when enabled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next |
callable
|
Callable to continue the resolution chain. |
required |
root |
object
|
Parent resolved value. None for top-level fields. |
required |
info |
GraphQLResolveInfo
|
GraphQL resolve info containing operation metadata. |
required |
**kwargs |
object
|
Field arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
object |
object
|
The result of the resolver. |
Source code in nautobot_graphql_observability/middleware.py
nautobot_graphql_observability.logging_middleware
¶
Graphene middleware for logging GraphQL queries via Python's logging module.
GraphQLQueryLoggingMiddleware
¶
Graphene middleware that captures GraphQL query metadata for logging.
On root-level resolutions, stashes operation metadata onto the request so
that :class:GraphQLQueryLoggingDjangoMiddleware can emit a log entry
with the real total request duration after the full response is built.
Controlled by app settings:
query_logging_enabled: Master switch (default: False).log_query_body: Include the full query text (default: False).log_query_variables: Include query variables (default: False).
Usage in Django settings::
GRAPHENE = {
"MIDDLEWARE": [
"nautobot_graphql_observability.logging_middleware.GraphQLQueryLoggingMiddleware",
"nautobot_graphql_observability.middleware.PrometheusMiddleware",
]
}
Source code in nautobot_graphql_observability/logging_middleware.py
resolve(next, root, info, **kwargs)
¶
Intercept root-level resolutions and stash metadata on the request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next |
callable
|
Callable to continue the resolution chain. |
required |
root |
object
|
Parent resolved value. None for top-level fields. |
required |
info |
GraphQLResolveInfo
|
GraphQL resolve info containing operation metadata. |
required |
**kwargs |
object
|
Field arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
object |
object
|
The result of the resolver. |
Source code in nautobot_graphql_observability/logging_middleware.py
nautobot_graphql_observability.metrics
¶
Prometheus metric definitions for GraphQL instrumentation.