---
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 service spans 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. This is enabled 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. 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`, the request body 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.

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

* graphene: 3.3+
* Python: 3.8+
