Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Use scope.should_send_default_pii in FastAPI integration #2846

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
190923c
Created async and sync decorators
szokeasaurusrex Oct 18, 2023
c8aeadb
Added use of each sentry decorator
szokeasaurusrex Oct 18, 2023
c18a902
Fix circular import
szokeasaurusrex Oct 18, 2023
0fbea43
Merge branch 'sentry-sdk-2.0' into szokeasaurusrex/sentry_patched_dec…
szokeasaurusrex Mar 15, 2024
9f5c279
Revert changes to starlette.py
szokeasaurusrex Mar 15, 2024
45b90ab
Rename method
szokeasaurusrex Mar 15, 2024
69ebafb
Use actual generics, move async implementation to utils
szokeasaurusrex Mar 15, 2024
46cd0e2
Refactor parameters
szokeasaurusrex Mar 15, 2024
7a8196a
Undo changes to _types.py
szokeasaurusrex Mar 15, 2024
d9016db
Use client instead of Hub
szokeasaurusrex Mar 15, 2024
75934d1
Add doc string
szokeasaurusrex Mar 15, 2024
66726d0
Move type comments
szokeasaurusrex Mar 15, 2024
4e48ce3
Merge branch 'sentry-sdk-2.0' into szokeasaurusrex/sentry_patched_dec…
szokeasaurusrex Mar 18, 2024
e8c921c
Fix mypy
szokeasaurusrex Mar 18, 2024
20688fd
Fix circular import
szokeasaurusrex Mar 18, 2024
d93ff92
Added unit tests for decorators
szokeasaurusrex Mar 18, 2024
4b90191
Merge branch 'sentry-sdk-2.0' into szokeasaurusrex/sentry_patched_dec…
szokeasaurusrex Mar 18, 2024
85c1a1f
Revert gql changes
szokeasaurusrex Mar 18, 2024
682eb71
Revert "Revert gql changes"
szokeasaurusrex Mar 18, 2024
49cadb0
Merge branch 'sentry-sdk-2.0' into szokeasaurusrex/gql-new-scope-api
szokeasaurusrex Mar 19, 2024
c4c4605
ref: Shortcut for `should_send_default_pii`
szokeasaurusrex Mar 19, 2024
8205626
revert gql changes
szokeasaurusrex Mar 19, 2024
e37fbe0
ref: Use `scope.should_send_default_pii` in FastAPI integration
szokeasaurusrex Mar 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion sentry_sdk/hub.py
Expand Up @@ -60,7 +60,7 @@ def overload(x):

def _should_send_default_pii():
# type: () -> bool
# TODO: Migrate existing code to client.should_send_default_pii() and remove this function.
# TODO: Migrate existing code to `scope.should_send_default_pii()` and remove this function.
# New code should not use this function!
client = Hub.current.client
if not client:
Expand Down
7 changes: 2 additions & 5 deletions sentry_sdk/integrations/fastapi.py
Expand Up @@ -5,7 +5,7 @@
import sentry_sdk
from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.integrations import DidNotEnable
from sentry_sdk.scope import Scope
from sentry_sdk.scope import Scope, should_send_default_pii
from sentry_sdk.tracing import SOURCE_FOR_STYLE, TRANSACTION_SOURCE_ROUTE
from sentry_sdk.utils import (
transaction_from_function,
Expand Down Expand Up @@ -118,10 +118,7 @@ def event_processor(event, hint):
# Extract information from request
request_info = event.get("request", {})
if info:
if (
"cookies" in info
and sentry_sdk.get_client().should_send_default_pii()
):
if "cookies" in info and should_send_default_pii():
request_info["cookies"] = info["cookies"]
if "data" in info:
request_info["data"] = info["data"]
Expand Down
6 changes: 6 additions & 0 deletions sentry_sdk/scope.py
Expand Up @@ -1658,5 +1658,11 @@ def use_isolation_scope(isolation_scope):
_isolation_scope.reset(isolation_token)


def should_send_default_pii():
# type: () -> bool
"""Shortcut for `Scope.get_client().should_send_default_pii()`."""
return Scope.get_client().should_send_default_pii()


# Circular imports
from sentry_sdk.client import NonRecordingClient
20 changes: 19 additions & 1 deletion tests/test_scope.py
Expand Up @@ -10,7 +10,13 @@
new_scope,
)
from sentry_sdk.client import Client, NonRecordingClient
from sentry_sdk.scope import Scope, ScopeType, use_isolation_scope, use_scope
from sentry_sdk.scope import (
Scope,
ScopeType,
use_isolation_scope,
use_scope,
should_send_default_pii,
)


def test_copying():
Expand Down Expand Up @@ -778,3 +784,15 @@ def test_nested_scopes_with_tags(sentry_init, capture_envelopes):
assert transaction["tags"] == {"isolation_scope1": 1, "current_scope2": 1, "trx": 1}
assert transaction["spans"][0]["tags"] == {"a": 1}
assert transaction["spans"][1]["tags"] == {"b": 1}


def test_should_send_default_pii_true(sentry_init):
sentry_init(send_default_pii=True)

assert should_send_default_pii() is True


def test_should_send_default_pii_false(sentry_init):
sentry_init(send_default_pii=False)

assert should_send_default_pii() is False