---
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 | Sentry 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"
```

## [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\[ ]Logs

```python
import sentry_sdk

sentry_sdk.init(
    dsn="___PUBLIC_DSN___",
    # 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,
    # ___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
    # ___PRODUCT_OPTION_START___ logs

    # Enable logs to be sent to Sentry
    enable_logs=True,
    # ___PRODUCT_OPTION_END___ logs
)
```

## [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:

* Initialize the SDK with the [send\_default\_pii](https://docs.sentry.io/platforms/python/configuration/options.md#send-default-pii) option set to `True`.
* Make sure the integration for the web framework you're using is enabled.

```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.

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

* graphene: 3.3+
* Python: 3.8+
