---
title: "Graphene"
description: "Learn about importing the Graphene GraphQL integration and how it captures GraphQL errors."
url: https://docs.sentry.io/platforms/python/integrations/graphene/
---

# Graphene for Python

The Graphene integration captures errors from the [Graphene GraphQL library](https://graphene-python.org/), which can then be viewed in [Sentry](https://sentry.io).

## [Install](https://docs.sentry.io/platforms/python/integrations/graphene.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/graphene.md#configure)

If you have the `graphene` package in your dependencies, the Graphene integration will be enabled automatically when you initialize the Sentry SDK.

Error Monitoring\[ ]Tracing\[ ]Profiling

```python
import sentry_sdk

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={
        "user_info": 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
)
```

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

```python
import graphene

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

class Query(graphene.ObjectType):
    hello = graphene.String()

    def resolve_hello(self, info):
        1 / 0
        return "World"

schema = graphene.Schema(query=Query)

schema.execute("""
  query {
    hello
  }
""")
```

We've snuck a `ZeroDivisionError` into our `resolve_hello` resolver to ensure things are working as intended. When this code snippet is run, a new error event should appear in the Issues section of [sentry.io](https://sentry.io). It will take a couple of moments for the data to appear in [sentry.io](https://sentry.io).

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

When used together with one of our web framework integrations like [FastAPI](https://docs.sentry.io/platforms/python/integrations/fastapi.md) or [Flask](https://docs.sentry.io/platforms/python/integrations/flask.md), the Graphene integration can capture the request body for each GraphQL error that happens. Since the requests may contain sensitive data, no request bodies will be attached by default.

To capture request bodies:

* Make sure the integration for the web framework you're using is enabled.
* Initialize the SDK with the [`data_collection`](https://docs.sentry.io/platforms/python/configuration/options.md#data_collection) option. The `graphql` key's `document` setting controls whether the GraphQL request body is attached. If you set `http_bodies`, it must include `incoming_request` so that your web framework integration captures the body in the first place.

```python
sentry_sdk.init(
    # same options as above
    data_collection={
        "graphql": {"document": True},
    },
)
```

Both are enabled by default when you pass a `data_collection` dictionary. See [Data Collected](https://docs.sentry.io/platforms/python/data-management/data-collected.md) for all available keys.

Alternatively, you can initialize the SDK with the [`send_default_pii`](https://docs.sentry.io/platforms/python/configuration/options.md#send_default_pii) option set to `True`, though `send_default_pii` will be removed in version 3.0 of the SDK:

```python
sentry_sdk.init(
    # same options as above
    # Add data like request headers and IP for users, if applicable;
    # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
    send_default_pii=True,
)
```

##### Note

Since `send_default_pii` is a global SDK option, setting it to `True` affects all integrations, not just Graphene. Please make sure to take care of [scrubbing sensitive data](https://docs.sentry.io/platforms/python/data-management/sensitive-data.md) from events before enabling this option. With `data_collection`, you can enable only the categories you need instead.

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

* graphene: 3.3+
* Python: 3.8+
