---
title: "Strawberry"
description: "Learn how to import the Strawberry GraphQL integration and how it captures GraphQL errors and spans."
url: https://docs.sentry.io/platforms/python/integrations/strawberry/
---

# Strawberry for Python

The Strawberry integration captures errors and operations from the [Strawberry GraphQL library](https://strawberry.rocks/), which can then be viewed in [Sentry](https://sentry.io).

In SDK `3.x`, and in stream mode in SDK `2.x`, this page's references to "transaction" apply to service spans instead. See [Streamed Spans](https://docs.sentry.io/platforms/python/tracing/streamed-spans.md) for more information.

## [Install](https://docs.sentry.io/platforms/python/integrations/strawberry.md#install)

To get started, install `sentry-sdk` from PyPI.

```bash
pip install "sentry-sdk"
```

*Other available variations of the above snippet: uv*

## [Configure](https://docs.sentry.io/platforms/python/integrations/strawberry.md#configure)

In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](https://docs.sentry.io/concepts/key-terms/tracing.md). You can also collect and analyze performance profiles from real users with [profiling](https://docs.sentry.io/product/profiling.md).

Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.

Add `StrawberryIntegration()` to your `integrations` list:

Error Monitoring\[ ]Tracing\[ ]Profiling

```python
import sentry_sdk
from sentry_sdk.integrations.strawberry import StrawberryIntegration

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    # Check https://docs.sentry.io/platforms/python/data-management/data-collected/ to configure what data is collected
    data_collection={
        "graphql": {"document": True, "variables": True},
    },
    # ___PRODUCT_OPTION_START___ performance
    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for tracing.
    traces_sample_rate=1.0,
    # ___PRODUCT_OPTION_END___ performance
    # ___PRODUCT_OPTION_START___ profiling
    # To collect profiles for all profile sessions,
    # set `profile_session_sample_rate` to 1.0.
    profile_session_sample_rate=1.0,
    # Profiles will be automatically collected while
    # there is an active span.
    profile_lifecycle="trace",
    # ___PRODUCT_OPTION_END___ profiling
    integrations=[
        StrawberryIntegration(
            # Set async_execution to True if you have
            # at least one async resolver
            async_execution=True,
        ),
    ],
)
```

## [Verify](https://docs.sentry.io/platforms/python/integrations/strawberry.md#verify)

Make sure you have all the prerequisites installed:

```bash
pip install 'strawberry-graphql[debug-server]'
```

Create a `schema.py` file with the below content:

```python
import strawberry

sentry_sdk.init(...)  # same as above

async def resolve_hello(root) -> str:
    1 / 0
    return "Hello world!"

@strawberry.type
class Query:
    hello: str = strawberry.field(resolver=resolve_hello)

schema = strawberry.Schema(Query)
```

To start the web server, run:

```bash
strawberry server schema
```

Navigate to <http://127.0.0.1:8000/graphql> in your browser. You should see the GraphiQL graphical interface.

Type `query HelloQuery { hello }` into the query input field then press the "Execute query" button. Your web server will be queried, which should result in an exception due to the `ZeroDivisionError` we've snuck into the `resolve_hello` resolver.

This will create a `GraphQLError` in the Issues section as well as a transaction in the Performance section of [sentry.io](https://sentry.io). As long as the GraphQL query has a name (like `HelloQuery` in our example), the transaction will be named after it.

It might take a couple of moments for the error and transaction to appear in [sentry.io](https://sentry.io).

## [Options](https://docs.sentry.io/platforms/python/integrations/strawberry.md#options)

There are several options you will get to choose from:

### [Synchronous vs. Asynchronous Execution](https://docs.sentry.io/platforms/python/integrations/strawberry.md#synchronous-vs-asynchronous-execution)

Strawberry supports both synchronous and asynchronous execution of GraphQL queries. If you have at least one async resolver, you should initialize `StrawberryIntegration` with `async_execution=True`, otherwise set it to `False`.

By default, the SDK will use the synchronous version of the integration.

```python
sentry_sdk.init(
    # ...
    integrations=[
        StrawberryIntegration(
            async_execution=True  # or False
        ),
    ],
)
```

### [Capturing Request and Response Bodies](https://docs.sentry.io/platforms/python/integrations/strawberry.md#capturing-request-and-response-bodies)

The Strawberry integration can capture request and response bodies for each GraphQL error that happens. This is enabled by default.

To control capturing request and response bodies, use the [`data_collection`](https://docs.sentry.io/platforms/python/configuration/options.md#data_collection) option. The `graphql` key controls the query document and its variables in the request body, and the `outgoing_response` entry in `http_bodies` controls the response body:

```python
sentry_sdk.init(
    # ...
    data_collection={
        "graphql": {"document": True, "variables": True},
        "http_bodies": ["incoming_request", "outgoing_request", "outgoing_response"],
    },
)
```

These are the defaults, so you only need to set the keys you want to change. See [Data Collected](https://docs.sentry.io/platforms/python/data-management/data-collected.md) for all available keys.

In SDK versions prior to `3.0`, this data isn't attached by default. To attach it, pass a `data_collection` dictionary as shown above, or set the `send_default_pii` option to `True`. Since `send_default_pii` is a global SDK option, setting it to `True` affects all integrations, so make sure to [scrub sensitive data](https://docs.sentry.io/platforms/python/data-management/sensitive-data.md) from events first.

## [Notes](https://docs.sentry.io/platforms/python/integrations/strawberry.md#notes)

Strawberry comes with a (now deprecated) built-in [Sentry tracing extension](https://strawberry.rocks/docs/extensions/sentry-tracing) that this integration is built on. To prevent duplicate traces, the Sentry SDK integration will deactivate the built-in Strawberry extension if you happen to be using both.

## [Supported Versions](https://docs.sentry.io/platforms/python/integrations/strawberry.md#supported-versions)

* strawberry-graphql: 0.209.5+
* Python: 3.8+
