OpenTelemetryExtension#

This extension adds tracing information that is compatible with Open Telemetry.

This extension requires additional requirements:

pip install 'strawberry-graphql[opentelemetry]'

Usage example:#

import strawberry
from strawberry.extensions.tracing import OpenTelemetryExtension

schema = strawberry.Schema(
    Query,
    extensions=[
        OpenTelemetryExtension,
    ],
)

If you are not running in an Async context then you’ll need to use the sync version:

import strawberry
from strawberry.extensions.tracing import OpenTelemetryExtensionSync

schema = strawberry.Schema(
    Query,
    extensions=[
        OpenTelemetryExtensionSync,
    ],
)

API reference:#

class OpenTelemetryExtension(arg_filter=None):
    ...

arg_filter: Optional[ArgFilter]#

A function to filter certain field arguments from being included in the tracing data.

ArgFilter = Callable[[Dict[str, Any], GraphQLResolveInfo], Dict[str, Any]]

More examples:#

Using `arg_filter`
import strawberry
from strawberry.extensions.tracing import OpenTelemetryExtensionSync


def arg_filter(kwargs, info):
    filtered_kwargs = {}
    for name, value in kwargs:
        # Never include any arguments called "password"
        if name == "password":
            continue
        filtered_kwargs[name] = value

    return filtered_kwargs


schema = strawberry.Schema(
    Query,
    extensions=[
        OpenTelemetryExtensionSync(
            arg_filter=arg_filter,
        ),
    ],
)