---
title: "Data Collected"
description: "See what data is collected by the Sentry Python SDK."
url: https://docs.sentry.io/platforms/python/data-management/data-collected/
---

# Data Collected for Python

Sentry takes data privacy very seriously and has default settings in place that prioritize data safety, especially when it comes to personally identifiable information (PII) data. When you add the Sentry SDK to your application, you allow it to collect data and send it to Sentry during the runtime of your application.

The category types and amount of data collected vary, depending on the integrations you've enabled in the Sentry SDK. This page lists data categories that the Sentry Python SDK collects.

This page describes the data collected by version `3.x` of the Python SDK. For `2.x`, switch to `2.x` in the version selector.

Options to control data collection

You can control many of the categories listed here with the [`data_collection` option](https://docs.sentry.io/platforms/python/configuration/options.md#data_collection), which lets you opt in or out of each data category individually. Any category you don't set falls back to its default, described on this page.

Regardless of these options, you can always scrub any data before it's sent to Sentry. See [Scrubbing Sensitive Data](https://docs.sentry.io/platforms/python/data-management/sensitive-data.md) for details.

## [HTTP Headers](https://docs.sentry.io/platforms/python/data-management/data-collected.md#http-headers)

By default, the Sentry SDK sends HTTP request headers to Sentry, with the values of sensitive headers scrubbed. The Python SDK doesn't capture response headers.

Use `http_headers` to control this:

```python
import sentry_sdk

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    data_collection={
        # Collect nothing:
        "http_headers": {"request": {"mode": "off"}},
        # Or only send real values for the listed headers:
        # "http_headers": {"request": {"mode": "allowlist", "terms": ["content-type"]}},
        # Or collect everything, filtering additional terms:
        # "http_headers": {"request": {"mode": "denylist", "terms": ["-ip"]}},
    },
)
```

Values whose keys match Sentry's built-in sensitive denylist (such as `auth`, `token`, or `password`) are always scrubbed, while the keys are kept. See [Key-Value Collection Behavior](https://docs.sentry.io/platforms/python/data-management/data-collected.md#key-value-collection-behavior) below for details on `mode` and `terms`.

## [Cookies](https://docs.sentry.io/platforms/python/data-management/data-collected.md#cookies)

By default, the Sentry SDK sends cookies, with the values of sensitive cookies (such as the Session ID and CSRF Token cookies in Django) scrubbed. Opt out with `{"mode": "off"}`, or restrict which values are sent using `"allowlist"` or `"denylist"` mode:

```python
import sentry_sdk

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    data_collection={
        "cookies": {"mode": "off"},
    },
)
```

## [Information About Logged-in User](https://docs.sentry.io/platforms/python/data-management/data-collected.md#information-about-logged-in-user)

By default, the Sentry SDK populates user identity fields (`user.id`, `user.email`, `user.username`) from instrumentation. The type of logged-in user information you'll be able to send depends on the integrations you enable in Sentry's SDK. Most integrations won't send any user information. Some will only set the user ID, but there are a few that will set the user ID, username, and email address.

To disable this, set `user_info` to `False`:

```python
import sentry_sdk

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    data_collection={
        "user_info": False,
    },
)
```

## [Users' IP Address](https://docs.sentry.io/platforms/python/data-management/data-collected.md#users-ip-address)

By default, the Sentry SDK sends the user's IP address. Whether it's sent depends on the integrations you enable in Sentry's SDK. Most integrations won't set the user's IP address at all. Disable it by setting `user_info` to `False`.

Even when this is disabled, IP addresses can still reach Sentry through collected HTTP headers, cookies, or query parameters (for example, the `X-Forwarded-For` header). Add these terms to the deny lists for those categories so their values are filtered:

```python
import sentry_sdk

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    data_collection={
        "http_headers": {
            "request": {
                "mode": "denylist",
                "terms": ["forwarded", "-ip", "remote-", "via", "-user"],
            },
        },
        "cookies": {
            "mode": "denylist",
            "terms": ["forwarded", "-ip", "remote-", "via", "-user"],
        },
        "url_query_params": {
            "mode": "denylist",
            "terms": ["forwarded", "-ip", "remote-", "via", "-user"],
        },
    },
)
```

## [Request URL](https://docs.sentry.io/platforms/python/data-management/data-collected.md#request-url)

The full request URL of outgoing and incoming HTTP requests is **always sent to Sentry**. Depending on your application, this could contain PII data.

## [Request Query String](https://docs.sentry.io/platforms/python/data-management/data-collected.md#request-query-string)

By default, the full request query string of outgoing and incoming HTTP requests is sent to Sentry. Depending on your application, this could contain PII data. For example, a query string like `?user_id=1234`, where `1234` is a user id (which may be considered PII).

Use `url_query_params` to control this. Set it to `{"mode": "off"}` to disable collection entirely, or use `"allowlist"` / `"denylist"` mode to filter which values are sent. Values whose keys match the built-in sensitive denylist (terms like `auth`, `token`, `password`, and `secret`) are scrubbed automatically.

```python
import sentry_sdk

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    data_collection={
        "url_query_params": {"mode": "off"},
    },
)
```

Sentry also has some additional [server-side data scrubbing](https://docs.sentry.io/security-legal-pii/scrubbing/server-side-scrubbing.md) in place to remove sensitive data from the query string.

## [Request Body](https://docs.sentry.io/platforms/python/data-management/data-collected.md#request-body)

The request body of incoming HTTP requests can be sent to Sentry. Whether it's sent or not, depends on the type and size of request body as described below:

* **The type of the request body:**

  * JSON and form bodies are sent
  * Raw request bodies are always removed
  * Uploaded files in the request bodies are never sent to Sentry

* **The size of the request body:** There's a ["max\_request\_body\_size"](https://docs.sentry.io/platforms/python/configuration/options.md#max-request-body-size) option that's set to `medium` by default. This means that larger request bodies aren't sent to Sentry.

If you want to prevent bodies from being sent to Sentry altogether, set `max_request_body_size` to `"never"`.

By default, incoming and outgoing request bodies, as well as outgoing response bodies, are collected. To disable body collection, set `http_bodies` to an empty list, or provide only the body types you want:

```python
import sentry_sdk

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    # Collect only incoming request bodies:
    data_collection={
        "http_bodies": ["incoming_request"],
    },
)
```

The valid body types are `"incoming_request"`, `"outgoing_request"`, and `"outgoing_response"`. Currently, only the [Ariadne](https://docs.sentry.io/platforms/python/integrations/ariadne.md) and [Strawberry](https://docs.sentry.io/platforms/python/integrations/strawberry.md) integrations use `"outgoing_response"`, to attach the GraphQL response to error events. The Python SDK doesn't capture incoming response bodies.

`max_request_body_size` still applies on top of `http_bodies`.

## [Source Context](https://docs.sentry.io/platforms/python/data-management/data-collected.md#source-context)

When an unhandled exception is sent to Sentry, a snapshot of the source code surrounding the line where the error originates is sent with it.

Use `frame_context_lines` to control how many lines above and below each stack frame are captured. It defaults to `5`. Set it to `0` (or `False`) to opt out:

```python
import sentry_sdk

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    data_collection={
        "frame_context_lines": 0,
    },
)
```

## [Local Variables In Stack Trace](https://docs.sentry.io/platforms/python/data-management/data-collected.md#local-variables-in-stack-trace)

When unhandled errors and exceptions are sent to Sentry, the names and values of local variables that were set when the errors occurred are sent at the same time.

`stack_frame_variables` controls this and defaults to `True`. Local variable values aren't scrubbed by default. To filter out sensitive variables (such as `password` or `token`), use `"denylist"` mode, optionally with your own `terms`:

```python
import sentry_sdk

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    data_collection={
        "stack_frame_variables": {"mode": "denylist"},
    },
)
```

To opt out entirely, set `stack_frame_variables` to `False`:

```python
import sentry_sdk

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    data_collection={
        "stack_frame_variables": False,
    },
)
```

## [SQL Queries](https://docs.sentry.io/platforms/python/data-management/data-collected.md#sql-queries)

While SQL queries are sent to Sentry, neither the full SQL query (`UPDATE app_user SET password='supersecret' WHERE id=1;`), nor the values of its parameters will ever be sent. A parameterized version of the query (`UPDATE app_user SET password='%s' WHERE id=%s;`) is sent instead.

Set `database_query_data` to `False` to stop collecting database query data:

```python
import sentry_sdk

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    data_collection={
        "database_query_data": False,
    },
)
```

## [GraphQL Documents And Variables](https://docs.sentry.io/platforms/python/data-management/data-collected.md#graphql-documents-and-variables)

By default, the GraphQL query document and its variables are collected. Both can be disabled independently:

```python
import sentry_sdk

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    data_collection={
        "graphql": {"document": False, "variables": False},
    },
)
```

## [Queue And Task Message Data](https://docs.sentry.io/platforms/python/data-management/data-collected.md#queue-and-task-message-data)

By default, message body data for queue and task-queue integrations is collected. Set `queues` to `False` to opt out:

```python
import sentry_sdk

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    data_collection={
        "queues": False,
    },
)
```

## [LLM Inputs And Responses](https://docs.sentry.io/platforms/python/data-management/data-collected.md#llm-inputs-and-responses)

By default, the `gen_ai` category records both the inputs and outputs of your AI integrations, such as LLM prompts, messages, and responses. Metadata like the model ID and token counts is always collected. See the [documentation for the specific AI framework](https://docs.sentry.io/platforms/python/integrations.md#ai) for details on what's attached.

```python
import sentry_sdk

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    data_collection={
        "gen_ai": {"inputs": False, "outputs": False},
    },
)
```

Tool arguments, tool results, and prompt content of the [MCP integration](https://docs.sentry.io/platforms/python/integrations/mcp.md) are controlled separately by the `mcp` category, which works the same way.

## [`data_collection` Reference](https://docs.sentry.io/platforms/python/data-management/data-collected.md#data_collection-reference)

### [Keys](https://docs.sentry.io/platforms/python/data-management/data-collected.md#keys)

| Key                     | Type                                    | Default                                                         | Description                                                                                                                                                                                                                                                                                                                                          |
| ----------------------- | --------------------------------------- | --------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `user_info`             | `bool`                                  | `True`                                                          | Populate `user.*` fields (`id`, `email`, `username`, `ip_address`) from instrumentation.                                                                                                                                                                                                                                                             |
| `cookies`               | key-value behavior                      | `{"mode": "denylist"}`                                          | Collect cookies.                                                                                                                                                                                                                                                                                                                                     |
| `http_headers`          | `{"request": key-value behavior}`       | `{"request": {"mode": "denylist"}}`                             | Collect HTTP request headers. The Python SDK currently doesn't capture response headers.                                                                                                                                                                                                                                                             |
| `http_bodies`           | `list[str]`                             | `["incoming_request", "outgoing_request", "outgoing_response"]` | Body types to collect. Set to `[]` to disable. The Python SDK currently doesn't capture incoming response bodies.                                                                                                                                                                                                                                    |
| `url_query_params`      | key-value behavior                      | `{"mode": "denylist"}`                                          | Collect URL query parameters.                                                                                                                                                                                                                                                                                                                        |
| `graphql`               | `{"document": bool, "variables": bool}` | both `True`                                                     | Collect the GraphQL query document and its variables.                                                                                                                                                                                                                                                                                                |
| `gen_ai`                | `{"inputs": bool, "outputs": bool}`     | both `True`                                                     | Collect generative AI input and output content. Metadata such as the model ID and token counts is always collected.                                                                                                                                                                                                                                  |
| `mcp`                   | `{"inputs": bool, "outputs": bool}`     | both `True`                                                     | Collect MCP tool arguments, tool results, and prompt content.                                                                                                                                                                                                                                                                                        |
| `database_query_data`   | `bool`                                  | `True`                                                          | Collect database query data. Query parameter values are never sent; queries are parameterized first.                                                                                                                                                                                                                                                 |
| `queues`                | `bool`                                  | `True`                                                          | Collect message body data for queue and task-queue integrations.                                                                                                                                                                                                                                                                                     |
| `stack_frame_variables` | `bool` or key-value behavior            | `True`                                                          | Include local variable values captured within stack frames. Accepts a boolean (`True` collects all variables, `False` collects none) or a key-value behavior to filter which variables are sent by name (see [Filtering Stack Frame Variables](https://develop.sentry.dev/sdk/foundations/client/data-collection/#filtering-stack-frame-variables)). |
| `frame_context_lines`   | `int` or `bool`                         | `5`                                                             | Source code lines captured above and below each stack frame. `True` means the default of `5`, `False` means `0`.                                                                                                                                                                                                                                     |

### [Key-Value Collection Behavior](https://docs.sentry.io/platforms/python/data-management/data-collected.md#key-value-collection-behavior)

The `cookies`, `http_headers["request"]`, and `url_query_params` categories take a dictionary with a `mode` and an optional list of `terms`:

```python
{"mode": "denylist", "terms": ["forwarded", "-ip", "remote-", "via", "-user"]}
```

| `mode`        | Behavior                                                                                                              |
| ------------- | --------------------------------------------------------------------------------------------------------------------- |
| `"denylist"`  | Collect everything, replacing the value of any key matching `terms` (in addition to the built-in sensitive denylist). |
| `"allowlist"` | Only keys matching `terms` send their real value. Every other key is kept, but its value is replaced.                 |
| `"off"`       | Collect nothing in this category.                                                                                     |

`terms` match partially and case-insensitively, so `"-ip"` matches `X-Real-IP`. Filtered values are replaced with `[Filtered]`; the key itself is always preserved. The built-in sensitive denylist (`auth`, `token`, `secret`, `password`, `key`, `session`, and similar) always applies, even in `"allowlist"` mode.
