Skip to content

Commit 75f3ac3

Browse files
feat(python): Add send_default_pii=True to snippets (#12473)
See getsentry/team-sdks#121 --------- Co-authored-by: Alex Krawiec <[email protected]>
1 parent 7cbc0d7 commit 75f3ac3

File tree

43 files changed

+186
-50
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+186
-50
lines changed

Diff for: docs/platforms/python/configuration/options.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Grouping in Sentry is different for events with stack traces and without. As a r
9595

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

98-
If this flag is enabled, certain personally identifiable information (PII) is added by active integrations. By default, no such data is sent.
98+
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.
9999

100100
<Alert>
101101

Diff for: docs/platforms/python/data-management/data-collected.mdx

+13-7
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ The category types and amount of data collected vary, depending on the integrati
1010

1111
## HTTP Headers
1212

13-
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.
13+
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.
1414

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

1717
## Cookies
1818

19-
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).
19+
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.
2020

2121
If you want to send cookies, set `send_default_pii=True` in the `sentry_sdk.init()` call.
2222

2323
## Information About Logged-in User
2424

25-
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.
25+
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.
2626

2727
To start sending logged-in user information, set `send_default_pii=True` in the `sentry_sdk.init()` call.
2828

@@ -45,9 +45,9 @@ The full request query string of outgoing and incoming HTTP requests is **always
4545
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:
4646

4747
- **The type of the request body:**
48-
-JSON and form bodies are sent
49-
-Raw request bodies are always removed
50-
-Uploaded files in the request bodies are never sent to Sentry
48+
- JSON and form bodies are sent
49+
- Raw request bodies are always removed
50+
- Uploaded files in the request bodies are never sent to Sentry
5151
- **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.
5252

5353
If you want to prevent bodies from being sent to Sentry altogether, set `max_request_body_size` to `"never"`.
@@ -60,10 +60,16 @@ To opt out of sending this source context to Sentry, set `include_source_context
6060

6161
## Local Variables In Stack Trace
6262

63-
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.
63+
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.
6464

6565
You can stop sending local variables to Sentry by setting `include_local_variables=False` in the `sentry_sdk.init()` call.
6666

6767
## SQL Queries
6868

6969
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.
70+
71+
## LLM Inputs And Responses
72+
73+
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.
74+
75+
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.

Diff for: docs/platforms/python/index.mdx

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@ Configuration should happen as early as possible in your application's lifecycle
3838

3939

4040

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

4444
sentry_sdk.init(
4545
dsn="___PUBLIC_DSN___",
46+
# Add request headers and IP for users,
47+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
48+
send_default_pii=True,
4649
# Set traces_sample_rate to 1.0 to capture 100%
4750
# of transactions for tracing.
4851
traces_sample_rate=1.0,

Diff for: docs/platforms/python/integrations/asgi/index.mdx

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,17 @@ Select which Sentry features you'd like to install in addition to Error Monitori
3232
]}
3333
/>
3434

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

3939
from my_asgi_app import app
4040

4141
sentry_sdk.init(
4242
dsn="___PUBLIC_DSN___",
43+
# Add data like request headers and IP for users, if applicable;
44+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
45+
send_default_pii=True,
4346
# Set traces_sample_rate to 1.0 to capture 100%
4447
# of transactions for tracing.
4548
traces_sample_rate=1.0,

Diff for: docs/platforms/python/integrations/asyncio/index.mdx

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ Select which Sentry features you'd like to install in addition to Error Monitori
2828
]}
2929
/>
3030

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

3535
async def main():
3636
sentry_sdk.init(
3737
dsn="___PUBLIC_DSN___",
38+
# Add data like request headers and IP for users, if applicable;
39+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
40+
send_default_pii=True,
3841
# Set traces_sample_rate to 1.0 to capture 100%
3942
# of transactions for tracing.
4043
traces_sample_rate=1.0,

Diff for: docs/platforms/python/integrations/aws-lambda/manual-instrumentation/index.mdx

+4-1
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ Select which Sentry features you'd like to install in addition to Error Monitori
4444
]}
4545
/>
4646

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

5151
sentry_sdk.init(
5252
dsn="___PUBLIC_DSN___",
53+
# Add data like request headers and IP for users, if applicable;
54+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
55+
send_default_pii=True,
5356
# Set traces_sample_rate to 1.0 to capture 100%
5457
# of transactions for tracing.
5558
traces_sample_rate=1.0,

Diff for: docs/platforms/python/integrations/beam/index.mdx

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ Select which Sentry features you'd like to install in addition to Error Monitori
2424
]}
2525
/>
2626

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

3131
sentry_sdk.init(
3232
dsn="___PUBLIC_DSN___",
33+
# Add data like request headers and IP for users, if applicable;
34+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
35+
send_default_pii=True,
3336
# Set traces_sample_rate to 1.0 to capture 100%
3437
# of transactions for tracing.
3538
traces_sample_rate=1.0,

Diff for: docs/platforms/python/integrations/celery/crons.mdx

+4-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Select which Sentry features you'd like to install in addition to Error Monitori
5050
options={["error-monitoring", "performance", "profiling"]}
5151
/>
5252

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

@@ -62,6 +62,9 @@ from sentry_sdk.integrations.celery import CeleryIntegration
6262
def init_sentry(**kwargs):
6363
sentry_sdk.init(
6464
dsn='___PUBLIC_DSN___',
65+
# Add data like request headers and IP for users, if applicable;
66+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
67+
send_default_pii=True,
6568
# Set traces_sample_rate to 1.0 to capture 100%
6669
# of transactions for tracing.
6770
traces_sample_rate=1.0,

Diff for: docs/platforms/python/integrations/celery/index.mdx

+8-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ In addition to capturing errors, you can use Sentry for [distributed tracing](/c
3535
options={["error-monitoring", "performance", "profiling"]}
3636
/>
3737

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

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

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

7780
def main():
7881
# Initializing Sentry SDK in our process
7982
sentry_sdk.init(
8083
dsn="___PUBLIC_DSN___",
84+
# Add data like request headers and IP for users, if applicable;
85+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
86+
send_default_pii=True,
8187
# Set traces_sample_rate to 1.0 to capture 100%
8288
# of transactions for tracing.
8389
traces_sample_rate=1.0,

Diff for: docs/platforms/python/integrations/cloudresourcecontext/index.mdx

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ Select which Sentry features you'd like to install in addition to Error Monitori
3030
]}
3131
/>
3232

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

3737
sentry_sdk.init(
3838
dsn="___PUBLIC_DSN___",
39+
# Add data like request headers and IP for users, if applicable;
40+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
41+
send_default_pii=True,
3942
# Set traces_sample_rate to 1.0 to capture 100%
4043
# of transactions for tracing.
4144
traces_sample_rate=1.0,

Diff for: docs/platforms/python/integrations/django/index.mdx

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ Select which Sentry features you'd like to install in addition to Error Monitori
3737
]}
3838
/>
3939

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

4343
sentry_sdk.init(
4444
dsn="___PUBLIC_DSN___",
45+
# Add data like request headers and IP for users;
46+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
47+
send_default_pii=True,
4548
# Set traces_sample_rate to 1.0 to capture 100%
4649
# of transactions for tracing.
4750
traces_sample_rate=1.0,

Diff for: docs/platforms/python/integrations/dramatiq/index.mdx

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ from sentry_sdk.integrations.dramatiq import DramatiqIntegration
3232

3333
sentry_sdk.init(
3434
dsn="___PUBLIC_DSN___",
35+
# Add data like request headers and IP for users, if applicable;
36+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
37+
send_default_pii=True,
3538
integrations=[
3639
DramatiqIntegration(),
3740
],

Diff for: docs/platforms/python/integrations/falcon/index.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ from sentry_sdk.integrations.falcon import FalconIntegration
6565

6666
sentry_sdk.init(
6767
# same as above
68-
integrations = [
68+
integrations=[
6969
FalconIntegration(
7070
transaction_style="path",
7171
),

Diff for: docs/platforms/python/integrations/gcp-functions/index.mdx

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@ Select which Sentry features you'd like to install in addition to Error Monitori
3535
]}
3636
/>
3737

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

4242
sentry_sdk.init(
4343
dsn="___PUBLIC_DSN___",
44+
# Add data like request headers and IP for users, if applicable;
45+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
46+
send_default_pii=True,
4447
# Set traces_sample_rate to 1.0 to capture 100%
4548
# of transactions for tracing.
4649
traces_sample_rate=1.0,

Diff for: docs/platforms/python/integrations/gnu_backtrace/index.mdx

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ from sentry_sdk.integrations.gnu_backtrace import GnuBacktraceIntegration
2626

2727
sentry_sdk.init(
2828
dsn="___PUBLIC_DSN___",
29+
# Add data like request headers and IP for users, if applicable;
30+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
31+
send_default_pii=True,
2932
integrations=[
3033
GnuBacktraceIntegration(),
3134
],

Diff for: docs/platforms/python/integrations/gql/index.mdx

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ To have Sentry record the GraphQL queries and the `errors` information returned
4040
```python
4141
sentry_sdk.init(
4242
# ...
43+
# Add data like request headers and IP for users, if applicable;
44+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
4345
send_default_pii=True,
4446
)
4547
```

Diff for: docs/platforms/python/integrations/graphene/index.mdx

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ To capture request bodies:
6767
```python
6868
sentry_sdk.init(
6969
# same options as above
70+
# Add data like request headers and IP for users, if applicable;
71+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
7072
send_default_pii=True,
7173
)
7274
```

Diff for: docs/platforms/python/integrations/grpc/index.mdx

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,17 @@ Select which Sentry features you'd like to install in addition to Error Monitori
3737

3838
### Server
3939

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

4343
import sentry_sdk
4444
from sentry_sdk.integrations.grpc import GRPCIntegration
4545

4646
sentry_sdk.init(
4747
dsn="___PUBLIC_DSN___",
48+
# Add data like request headers and IP for users, if applicable;
49+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
50+
send_default_pii=True,
4851
# Set traces_sample_rate to 1.0 to capture 100%
4952
# of transactions for tracing.
5053
traces_sample_rate=1.0,

Diff for: docs/platforms/python/integrations/huggingface_hub/index.mdx

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ from sentry_sdk.integrations.huggingface_hub import HuggingfaceHubIntegration
7777

7878
sentry_sdk.init(
7979
# ...
80+
# Add data like request headers and IP for users, if applicable;
81+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
8082
send_default_pii=True,
8183
integrations=[
8284
HuggingfaceHubIntegration(

Diff for: docs/platforms/python/integrations/langchain/index.mdx

+5-4
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ Select which Sentry features you'd like to install in addition to Error Monitori
4343
]}
4444
/>
4545

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

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

98100
sentry_sdk.init(
99101
# ...
100-
send_default_pii=True,
101-
integrations = [
102+
integrations=[
102103
LangchainIntegration(
103104
include_prompts=False, # LLM/tokenizer inputs/outputs will be not sent to Sentry, despite send_default_pii=True
104105
max_spans=500,

Diff for: docs/platforms/python/integrations/launchdarkly/index.mdx

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ from sentry_sdk.integrations.launchdarkly import LaunchDarklyIntegration
2525

2626
sentry_sdk.init(
2727
dsn="___PUBLIC_DSN___",
28+
# Add data like request headers and IP for users, if applicable;
29+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
30+
send_default_pii=True,
2831
integrations=[
2932
LaunchDarklyIntegration(),
3033
],

Diff for: docs/platforms/python/integrations/litestar/index.mdx

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ Add `LitestarIntegration()` to your `integrations` list:
2626
]}
2727
/>
2828

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

3333
sentry_sdk.init(
3434
dsn="___PUBLIC_DSN___",
35+
# Add data like request headers and IP for users, if applicable;
36+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
37+
send_default_pii=True,
3538
# Set traces_sample_rate to 1.0 to capture 100%
3639
# of transactions for tracing.
3740
traces_sample_rate=1.0,

Diff for: docs/platforms/python/integrations/logging/index.mdx

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ The logging integrations is a default integration so it will be enabled automati
2222
import sentry_sdk
2323

2424
sentry_sdk.init(
25-
dsn="___PUBLIC_DSN___"
25+
dsn="___PUBLIC_DSN___",
26+
# Add data like request headers and IP for users, if applicable;
27+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
28+
send_default_pii=True,
2629
)
2730
```
2831

0 commit comments

Comments
 (0)