Data Collected for Python
See what data is collected by the Sentry Python SDK.
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.
By default, the Sentry SDK sends HTTP request headers to Sentry but filters out any headers that contain sensitive data. (See the list of headers that are filtered). The Python SDK doesn't capture response headers.
To send all HTTP headers, set send_default_pii=True in the sentry_sdk.init() call.
When using data_collection, request headers are collected with sensitive values scrubbed. Use http_headers to control this:
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
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"]}},
},
)
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
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 below for details on mode and terms.
Additionally a data scrubber removes sensitive data from headers (and a lot of other fields) right before sending data to Sentry.
By default, the Sentry SDK doesn't send cookies. Sentry tries to remove any cookies that contain sensitive information, such as the Session ID and CSRF Token cookies in Django.
If you want to send cookies, set send_default_pii=True in the sentry_sdk.init() call.
When using data_collection, cookies are collected by default with sensitive values scrubbed. Opt out with {"mode": "off"}, or restrict which values are sent using "allowlist" or "denylist" mode:
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
data_collection={
"cookies": {"mode": "off"},
},
)
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
data_collection={
"cookies": {"mode": "off"},
},
)
Additionally a data scrubber removes sensitive data from cookies (and a lot of other fields) right before sending data to Sentry.
By default, the Sentry SDK doesn't send any information about the logged-in user, such as email address, user ID, or username. Even if enabled, 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 start sending logged-in user information, set send_default_pii=True in the sentry_sdk.init() call.
When using data_collection, the SDK populates user identity fields (user.id, user.email, user.username) from instrumentation by default. To disable this, set user_info to False:
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
data_collection={
"user_info": False,
},
)
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
data_collection={
"user_info": False,
},
)
By default, the Sentry SDK doesn't send the user's IP address. Even if enabled, whether you're able to send the user's IP address or not, will depend on the integrations you enable in Sentry's SDK. Most integrations won't set the user's IP address at all.
To enable sending the user's IP address, set send_default_pii=True in the sentry_sdk.init() call.
When using data_collection, the user's IP address is sent by default. 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). If you use data_collection, add these terms to the deny lists for those categories so their values are filtered:
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
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"],
},
},
)
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
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"],
},
},
)
The full request URL of outgoing and incoming HTTP requests is always sent to Sentry. Depending on your application, this could contain PII data.
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).
When using data_collection, 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.
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
data_collection={
"url_query_params": {"mode": "off"},
},
)
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
data_collection={
"url_query_params": {"mode": "off"},
},
)
Sentry also has some additional server-side data scrubbing in place to remove sensitive data from the query string.
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" option that's set to
mediumby 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".
When using data_collection, incoming and outgoing request bodies are collected by default. To disable body collection, set http_bodies to an empty list, or provide only the body types you want:
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# Collect only incoming request bodies:
data_collection={
"http_bodies": ["incoming_request"],
},
)
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# Collect only incoming request bodies:
data_collection={
"http_bodies": ["incoming_request"],
},
)
The valid body types are "incoming_request" and "outgoing_request". The Python SDK doesn't capture response bodies, so there are no response body types.
max_request_body_size still applies on top of http_bodies.
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.
To opt out of sending this source context to Sentry, set include_source_context to False.
When using data_collection, 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:
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
data_collection={
"frame_context_lines": 0,
},
)
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
data_collection={
"frame_context_lines": 0,
},
)
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.
You can stop sending local variables to Sentry by setting include_local_variables=False in the sentry_sdk.init() call.
When using data_collection, stack_frame_variables controls this and defaults to True.
To opt out explicitly, set stack_frame_variables to False:
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
data_collection={
"stack_frame_variables": False,
},
)
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
data_collection={
"stack_frame_variables": False,
},
)
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.
When using data_collection, set database_query_data to False to stop collecting database query data:
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
data_collection={
"database_query_data": False,
},
)
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
data_collection={
"database_query_data": False,
},
)
When using data_collection, the GraphQL query document and its variables are collected by default. Both can be disabled independently:
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
data_collection={
"graphql": {"document": False, "variables": False},
},
)
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
data_collection={
"graphql": {"document": False, "variables": False},
},
)
Without data_collection (and with send_default_pii unset or False), GraphQL documents and variables aren't collected.
When using data_collection, message body data for queue and task-queue integrations is collected by default. Set queues to False to opt out:
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
data_collection={
"queues": False,
},
)
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
data_collection={
"queues": False,
},
)
Without data_collection (and with send_default_pii unset or False), this data isn't collected.
When using Sentry in your AI apps, the SDK by default won't add data like LLM inputs and responses to spans. To start recording these, add send_default_pii=True to your sentry_sdk.init() call.
Most AI integrations have an additional parameter to control whether prompts should be included called include_prompts. See the documentation for the specific AI framework for more information.
When using data_collection, the gen_ai category records both inputs and outputs unless you opt out. Metadata like the model ID and token counts is always collected.
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
data_collection={
"gen_ai": {"inputs": False, "outputs": False},
},
)
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
data_collection={
"gen_ai": {"inputs": False, "outputs": False},
},
)
gen_ai supersedes the per-integration include_prompts parameter. When data_collection is set, gen_ai determines whether prompt content is recorded, regardless of what an individual integration's include_prompts is set to.
| 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"] | Body types to collect. Set to [] to disable. The Python SDK currently doesn't capture 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. |
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). |
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. |
The cookies, http_headers["request"], and url_query_params categories take a dictionary with a mode and an optional list of terms:
{"mode": "denylist", "terms": ["forwarded", "-ip", "remote-", "via", "-user"]}
{"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.
To keep the conservative collection you get from send_default_pii=False while using data_collection, opt out of each category explicitly:
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
data_collection={
"user_info": False,
"gen_ai": {"inputs": False, "outputs": False},
"graphql": {"document": False, "variables": False},
"database_query_data": False,
"queues": False,
"http_bodies": [],
"cookies": {
"mode": "denylist",
"terms": ["forwarded", "-ip", "remote-", "via", "-user"],
},
"http_headers": {
"request": {
"mode": "denylist",
"terms": ["forwarded", "-ip", "remote-", "via", "-user"],
},
},
"url_query_params": {
"mode": "denylist",
"terms": ["forwarded", "-ip", "remote-", "via", "-user"],
},
},
)
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
data_collection={
"user_info": False,
"gen_ai": {"inputs": False, "outputs": False},
"graphql": {"document": False, "variables": False},
"database_query_data": False,
"queues": False,
"http_bodies": [],
"cookies": {
"mode": "denylist",
"terms": ["forwarded", "-ip", "remote-", "via", "-user"],
},
"http_headers": {
"request": {
"mode": "denylist",
"terms": ["forwarded", "-ip", "remote-", "via", "-user"],
},
},
"url_query_params": {
"mode": "denylist",
"terms": ["forwarded", "-ip", "remote-", "via", "-user"],
},
},
)
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").