Skip to content

Commit

Permalink
feat(python): Add send_default_pii=True to snippets (#12473)
Browse files Browse the repository at this point in the history
See getsentry/team-sdks#121

---------

Co-authored-by: Alex Krawiec <[email protected]>
  • Loading branch information
sentrivana and coolguyzone authored Jan 29, 2025
1 parent 7cbc0d7 commit 75f3ac3
Show file tree
Hide file tree
Showing 43 changed files with 186 additions and 50 deletions.
2 changes: 1 addition & 1 deletion docs/platforms/python/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Grouping in Sentry is different for events with stack traces and without. As a r

<ConfigKey name="send-default-pii">

If this flag is enabled, certain personally identifiable information (PII) is added by active integrations. By default, no such data is sent.
If this flag is enabled, [certain personally identifiable information (PII)](/platforms/python/data-management/data-collected/) is added by active integrations. By default, no such data is sent.

<Alert>

Expand Down
20 changes: 13 additions & 7 deletions docs/platforms/python/data-management/data-collected.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ The category types and amount of data collected vary, depending on the integrati

## HTTP Headers

By default, the Sentry SDK doesn't send any HTTP headers. Even when sending HTTP headers is enabled, we have a [Denylist](https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/_wsgi_common.py#L19-L26) in place, which filters out any headers that contain sensitive data.
By default, the Sentry SDK doesn't send any HTTP headers. Even when sending HTTP headers is enabled, we have a [denylist](https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/_wsgi_common.py#L19-L26) in place, which filters out any headers that contain sensitive data.

To start sending HTTP headers, set `send_default_pii=True` in the `sentry_sdk.init()` call.

## Cookies

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

## Information About Logged-in User

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

Expand All @@ -45,9 +45,9 @@ The full request query string of outgoing and incoming HTTP requests is **always
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
- 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"](/platforms/python/configuration/options/#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"`.
Expand All @@ -60,10 +60,16 @@ To opt out of sending this source context to Sentry, set `include_source_context

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

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

## LLM Inputs And Responses

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 <PlatformLink to="/integrations/#ai">documentation for the specific AI framework</PlatformLink> for more information.
5 changes: 4 additions & 1 deletion docs/platforms/python/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ Configuration should happen as early as possible in your application's lifecycle



```python {"onboardingOptions": {"performance": "5-7", "profiling": "8-11"}}
```python {"onboardingOptions": {"performance": "8-10", "profiling": "11-14"}}
import sentry_sdk

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# Add request headers and IP for users,
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
Expand Down
5 changes: 4 additions & 1 deletion docs/platforms/python/integrations/asgi/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ Select which Sentry features you'd like to install in addition to Error Monitori
]}
/>

```python {"onboardingOptions": {"performance": "8-10", "profiling": "11-14"}}
```python {"onboardingOptions": {"performance": "11-13", "profiling": "14-17"}}
import sentry_sdk
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware

from my_asgi_app import app

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,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
Expand Down
5 changes: 4 additions & 1 deletion docs/platforms/python/integrations/asyncio/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ Select which Sentry features you'd like to install in addition to Error Monitori
]}
/>

```python {filename:main.py} {"onboardingOptions": {"performance": "7-9", "profiling": "10-13"}}
```python {filename:main.py} {"onboardingOptions": {"performance": "10-12", "profiling": "13-16"}}
import sentry_sdk
from sentry_sdk.integrations.asyncio import AsyncioIntegration

async def main():
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,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ Select which Sentry features you'd like to install in addition to Error Monitori
]}
/>

```python {"onboardingOptions": {"performance": "6-8", "profiling": "9-12"}}
```python {"onboardingOptions": {"performance": "9-11", "profiling": "12-15"}}
import sentry_sdk
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration

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,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
Expand Down
5 changes: 4 additions & 1 deletion docs/platforms/python/integrations/beam/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ Select which Sentry features you'd like to install in addition to Error Monitori
]}
/>

```python {"onboardingOptions": {"performance": "6-8", "profiling": "9-12"}}
```python {"onboardingOptions": {"performance": "9-11", "profiling": "12-15"}}
import sentry_sdk
from sentry_sdk.integrations.beam import BeamIntegration

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,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
Expand Down
5 changes: 4 additions & 1 deletion docs/platforms/python/integrations/celery/crons.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Select which Sentry features you'd like to install in addition to Error Monitori
options={["error-monitoring", "performance", "profiling"]}
/>

```python {diff} {filename:tasks.py} {"onboardingOptions": {"performance": "12-14", "profiling": "15-18"}}
```python {diff} {filename:tasks.py} {"onboardingOptions": {"performance": "15-17", "profiling": "18-21"}}
# tasks.py
from celery import signals

Expand All @@ -62,6 +62,9 @@ from sentry_sdk.integrations.celery import CeleryIntegration
def init_sentry(**kwargs):
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,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
Expand Down
10 changes: 8 additions & 2 deletions docs/platforms/python/integrations/celery/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ In addition to capturing errors, you can use Sentry for [distributed tracing](/c
options={["error-monitoring", "performance", "profiling"]}
/>

```python {filename:tasks.py} {"onboardingOptions": {"performance": "12-14", "profiling": "15-18"}}
```python {filename:tasks.py} {"onboardingOptions": {"performance": "15-17", "profiling": "18-21"}}
from celery import Celery, signals
import sentry_sdk

Expand All @@ -47,6 +47,9 @@ app = Celery("tasks", broker="...")
def init_sentry(**_kwargs):
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# Add request headers and IP for users,
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
Expand All @@ -70,14 +73,17 @@ The [`celeryd_init`](https://docs.celeryq.dev/en/stable/userguide/signals.html?#
options={["error-monitoring", "performance", "profiling"]}
/>

```python {filename:main.py} {"onboardingOptions": {"performance": "8-10", "profiling": "11-14"}}
```python {filename:main.py} {"onboardingOptions": {"performance": "11-13", "profiling": "14-17"}}
from tasks import add
import sentry_sdk

def main():
# Initializing Sentry SDK in our process
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,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ Select which Sentry features you'd like to install in addition to Error Monitori
]}
/>

```python {"onboardingOptions": {"performance": "6-8", "profiling": "9-12"}}
```python {"onboardingOptions": {"performance": "9-11", "profiling": "12-15"}}
import sentry_sdk
from sentry_sdk.integrations.cloud_resource_context import CloudResourceContextIntegration

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,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
Expand Down
5 changes: 4 additions & 1 deletion docs/platforms/python/integrations/django/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ Select which Sentry features you'd like to install in addition to Error Monitori
]}
/>

```python {filename:settings.py} {"onboardingOptions": {"performance": "5-7", "profiling": "8-11"}}
```python {filename:settings.py} {"onboardingOptions": {"performance": "8-10", "profiling": "11-14"}}
import sentry_sdk

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# Add data like request headers and IP for users;
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
Expand Down
3 changes: 3 additions & 0 deletions docs/platforms/python/integrations/dramatiq/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ from sentry_sdk.integrations.dramatiq import DramatiqIntegration

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,
integrations=[
DramatiqIntegration(),
],
Expand Down
2 changes: 1 addition & 1 deletion docs/platforms/python/integrations/falcon/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ from sentry_sdk.integrations.falcon import FalconIntegration

sentry_sdk.init(
# same as above
integrations = [
integrations=[
FalconIntegration(
transaction_style="path",
),
Expand Down
5 changes: 4 additions & 1 deletion docs/platforms/python/integrations/gcp-functions/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ Select which Sentry features you'd like to install in addition to Error Monitori
]}
/>

```python {"onboardingOptions": {"performance": "6-8", "profiling": "9-12"}}
```python {"onboardingOptions": {"performance": "9-11", "profiling": "12-15"}}
import sentry_sdk
from sentry_sdk.integrations.gcp import GcpIntegration

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,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
Expand Down
3 changes: 3 additions & 0 deletions docs/platforms/python/integrations/gnu_backtrace/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ from sentry_sdk.integrations.gnu_backtrace import GnuBacktraceIntegration

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,
integrations=[
GnuBacktraceIntegration(),
],
Expand Down
2 changes: 2 additions & 0 deletions docs/platforms/python/integrations/gql/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ To have Sentry record the GraphQL queries and the `errors` information returned
```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,
)
```
2 changes: 2 additions & 0 deletions docs/platforms/python/integrations/graphene/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ To capture request bodies:
```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,
)
```
Expand Down
5 changes: 4 additions & 1 deletion docs/platforms/python/integrations/grpc/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ Select which Sentry features you'd like to install in addition to Error Monitori

### Server

```python {"onboardingOptions": {"performance": "8-10", "profiling": "11-14"}}
```python {"onboardingOptions": {"performance": "11-13", "profiling": "14-17"}}
import grpc

import sentry_sdk
from sentry_sdk.integrations.grpc import GRPCIntegration

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,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
Expand Down
2 changes: 2 additions & 0 deletions docs/platforms/python/integrations/huggingface_hub/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ from sentry_sdk.integrations.huggingface_hub import HuggingfaceHubIntegration

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,
integrations=[
HuggingfaceHubIntegration(
Expand Down
9 changes: 5 additions & 4 deletions docs/platforms/python/integrations/langchain/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ Select which Sentry features you'd like to install in addition to Error Monitori
]}
/>

```python {"onboardingOptions": {"performance": "6-8", "profiling": "9-12"}}
```python {"onboardingOptions": {"performance": "9-11", "profiling": "12-15"}}
import sentry_sdk

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
send_default_pii=True, # send personally-identifiable information like LLM responses to sentry
# Send personally-identifiable information like LLM responses to Sentry;
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
traces_sample_rate=1.0,
Expand Down Expand Up @@ -97,8 +99,7 @@ from sentry_sdk.integrations.langchain import LangchainIntegration

sentry_sdk.init(
# ...
send_default_pii=True,
integrations = [
integrations=[
LangchainIntegration(
include_prompts=False, # LLM/tokenizer inputs/outputs will be not sent to Sentry, despite send_default_pii=True
max_spans=500,
Expand Down
3 changes: 3 additions & 0 deletions docs/platforms/python/integrations/launchdarkly/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ from sentry_sdk.integrations.launchdarkly import LaunchDarklyIntegration

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,
integrations=[
LaunchDarklyIntegration(),
],
Expand Down
5 changes: 4 additions & 1 deletion docs/platforms/python/integrations/litestar/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ Add `LitestarIntegration()` to your `integrations` list:
]}
/>

```python {"onboardingOptions": {"performance": "6-8", "profiling": "9-12"}}
```python {"onboardingOptions": {"performance": "9-11", "profiling": "12-15"}}
import sentry_sdk
from sentry_sdk.integrations.litestar import LitestarIntegration

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,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
Expand Down
5 changes: 4 additions & 1 deletion docs/platforms/python/integrations/logging/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ The logging integrations is a default integration so it will be enabled automati
import sentry_sdk

sentry_sdk.init(
dsn="___PUBLIC_DSN___"
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,
)
```

Expand Down
Loading

0 comments on commit 75f3ac3

Please sign in to comment.