---
title: "GQL"
description: "GQL GraphQL client integration"
url: https://docs.sentry.io/platforms/python/integrations/gql/
---

# GQL for Python

The [GQL](https://gql.readthedocs.io/en/stable/) integration allows you to monitor all GraphQL requests that your Python application makes using the `gql` library. Specifically, this integration reports every [`TransportQueryError`](https://gql.readthedocs.io/en/latest/modules/transport_exceptions.html#gql.transport.exceptions.TransportQueryError) to Sentry and provides additional context including:

* The URL the request was made to
* The GraphQL query which caused the error
* The `errors` information that the GraphQL server returns

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

Make sure you have the latest version of the Sentry SDK installed:

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

*Other available variations of the above snippet: uv*

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

If you have the `gql` package in your dependencies, the GQL 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
)
```

## [Data Privacy and the GQL Integration](https://docs.sentry.io/platforms/python/integrations/gql.md#data-privacy-and-the-gql-integration)

To ensure data privacy, the SDK avoids sending any information that may potentially contain personally identifiable information (PII) by default. See the docs for the [`data_collection`](https://docs.sentry.io/platforms/python/configuration/options.md#data_collection) and [`send_default_pii`](https://docs.sentry.io/platforms/python/configuration/options.md#send_default_pii) options for more information.

For the GQL integration, this policy means that the SDK **doesn't send** the GraphQL queries and the `errors` information that the GraphQL server returns, unless you override the default configuration.

To have Sentry record the GraphQL queries and the `errors` information returned by the GraphQL server, enable the `graphql` key of the `data_collection` option in your SDK init. The `document` key controls the queries and the `errors` information, and the `variables` key controls the query variables:

```python
sentry_sdk.init(
    # ...
    data_collection={
        "graphql": {"document": True, "variables": True},
    },
)
```

These are also the defaults 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 set `send_default_pii` to `True`, though `send_default_pii` will be removed in version 3.0 of the SDK:

```python
sentry_sdk.init(
    # ...
    # 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,
)
```

Before enabling the `send_default_pii` flag, ensure you've configured Sentry's [sensitive data scrubbing](https://docs.sentry.io/platforms/python/data-management/sensitive-data.md) tools to scrub all PII. Since `send_default_pii` affects all integrations, consider using `data_collection` to enable only the categories you need instead.
