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(gql): Use new scopes API in GQL Integration #2838

Merged
merged 26 commits into from
Mar 19, 2024
Merged
Changes from all commits
Commits
Show all changes
26 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
29ff367
Revert "revert gql changes"
szokeasaurusrex Mar 19, 2024
04be9de
Fully update gql integration to new scopes API
szokeasaurusrex Mar 19, 2024
d2b8458
Merge remote-tracking branch 'origin/sentry-sdk-2.0' into szokeasauru…
szokeasaurusrex Mar 19, 2024
5a7af4c
code review changes
szokeasaurusrex Mar 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions sentry_sdk/integrations/gql.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from sentry_sdk.utils import event_from_exception, parse_version
from sentry_sdk.hub import Hub, _should_send_default_pii
import sentry_sdk
from sentry_sdk.utils import (
event_from_exception,
ensure_integration_enabled,
parse_version,
)

from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.scope import Scope, should_send_default_pii

try:
import gql # type: ignore[import-not-found]
Expand Down Expand Up @@ -85,25 +91,22 @@
# type: () -> None
real_execute = gql.Client.execute

@ensure_integration_enabled(GQLIntegration, real_execute)

Check warning on line 94 in sentry_sdk/integrations/gql.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/integrations/gql.py#L94

Added line #L94 was not covered by tests
def sentry_patched_execute(self, document, *args, **kwargs):
# type: (gql.Client, DocumentNode, Any, Any) -> Any
hub = Hub.current
if hub.get_integration(GQLIntegration) is None:
return real_execute(self, document, *args, **kwargs)

with Hub.current.configure_scope() as scope:
scope.add_event_processor(_make_gql_event_processor(self, document))
scope = Scope.get_isolation_scope()
scope.add_event_processor(_make_gql_event_processor(self, document))

Check warning on line 98 in sentry_sdk/integrations/gql.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/integrations/gql.py#L97-L98

Added lines #L97 - L98 were not covered by tests

try:
return real_execute(self, document, *args, **kwargs)
except TransportQueryError as e:
event, hint = event_from_exception(
e,
client_options=hub.client.options if hub.client is not None else None,
szokeasaurusrex marked this conversation as resolved.
Show resolved Hide resolved
client_options=sentry_sdk.get_client().options,
mechanism={"type": "gql", "handled": False},
)

hub.capture_event(event, hint)
sentry_sdk.capture_event(event, hint)

Check warning on line 109 in sentry_sdk/integrations/gql.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/integrations/gql.py#L109

Added line #L109 was not covered by tests
raise e

gql.Client.execute = sentry_patched_execute
Expand All @@ -126,7 +129,7 @@
}
)

if _should_send_default_pii():
if should_send_default_pii():
request["data"] = _data_from_document(document)
contexts = event.setdefault("contexts", {})
response = contexts.setdefault("response", {})
Expand Down
Loading