Note: Extensions are only supported by the asynchronous executor (
ariadne.graphql) and ASGI application (
Note: for performance reasons OpenTracing extension excludes default resolvers.
Enabling OpenTracing in the API
To enable OpenTracing in your API, import the
OpenTracingExtension class from
ariadne.contrib.tracing.opentracing and pass it to your server
from ariadne.contrib.tracing.opentracing import OpenTracingExtension app = GraphQL( schema, debug=True, extensions=[OpenTracingExtension], )
Sanitizing sensitive arguments data
By default all arguments are sent to the APM service. If your API fields have arguments for sensitive data like passwords or tokens, you will need to sanitize those before sending tracking data to the service.
OpenTracingExtension has single configuration option named
arg_filter, that can be a function that extension will call with the copy of the dict of arguments previously passed to field's resolver.
Because extension instances are created per request,
OpenTracingExtension can't be instantiated inside the
extensions. Instead Ariadne provides
opentracing_extension utility that creates partial function that initializes the
arg_filter option per request.
Here is an example defining custom sanitizing function named
my_arg_filter and using
opentracing_extension to enable OpenTracing with it:
from ariadne.contrib.tracing import opentracing_extension def my_arg_filter(args, info): if "password" in args: args["password"] = "[redacted]" if "secret" in args: args["password"] = "[redacted]" for key, value in args.items(): if isinstance(value, dict): args[key] = my_arg_filter(value) if isinstance(value, list): args[key] = [my_arg_filter(v) for v in value] return args schema = make_executable_schema(type_def, [query, mutation]) app = GraphQL( schema, debug=True, extensions=[ opentracing_extension(arg_filter=my_arg_filter), ], )