Skip to content

Commit a354078

Browse files
authored
ref(gcp): Use new scopes API (#2884)
1 parent e3c7873 commit a354078

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

sentry_sdk/integrations/gcp.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
from datetime import datetime, timedelta, timezone
44
from os import environ
55

6+
import sentry_sdk
67
from sentry_sdk.api import continue_trace
78
from sentry_sdk.consts import OP
8-
from sentry_sdk.hub import Hub, _should_send_default_pii
9+
from sentry_sdk.integrations import Integration
10+
from sentry_sdk.integrations._wsgi_common import _filter_headers
11+
from sentry_sdk.scope import should_send_default_pii
912
from sentry_sdk.tracing import TRANSACTION_SOURCE_COMPONENT
1013
from sentry_sdk.utils import (
1114
AnnotatedValue,
@@ -15,8 +18,6 @@
1518
TimeoutThread,
1619
reraise,
1720
)
18-
from sentry_sdk.integrations import Integration
19-
from sentry_sdk.integrations._wsgi_common import _filter_headers
2021

2122
from sentry_sdk._types import TYPE_CHECKING
2223

@@ -39,15 +40,12 @@ def _wrap_func(func):
3940
# type: (F) -> F
4041
def sentry_func(functionhandler, gcp_event, *args, **kwargs):
4142
# type: (Any, Any, *Any, **Any) -> Any
43+
client = sentry_sdk.get_client()
4244

43-
hub = Hub.current
44-
integration = hub.get_integration(GcpIntegration)
45+
integration = client.get_integration(GcpIntegration)
4546
if integration is None:
4647
return func(functionhandler, gcp_event, *args, **kwargs)
4748

48-
# If an integration is there, a client has to be there.
49-
client = hub.client # type: Any
50-
5149
configured_time = environ.get("FUNCTION_TIMEOUT_SEC")
5250
if not configured_time:
5351
logger.debug(
@@ -59,7 +57,7 @@ def sentry_func(functionhandler, gcp_event, *args, **kwargs):
5957

6058
initial_time = datetime.now(timezone.utc)
6159

62-
with hub.push_scope() as scope:
60+
with sentry_sdk.isolation_scope() as scope:
6361
with capture_internal_exceptions():
6462
scope.clear_breadcrumbs()
6563
scope.add_event_processor(
@@ -100,7 +98,7 @@ def sentry_func(functionhandler, gcp_event, *args, **kwargs):
10098
},
10199
"gcp_event": gcp_event,
102100
}
103-
with hub.start_transaction(
101+
with sentry_sdk.start_transaction(
104102
transaction, custom_sampling_context=sampling_context
105103
):
106104
try:
@@ -112,13 +110,13 @@ def sentry_func(functionhandler, gcp_event, *args, **kwargs):
112110
client_options=client.options,
113111
mechanism={"type": "gcp", "handled": False},
114112
)
115-
hub.capture_event(sentry_event, hint=hint)
113+
sentry_sdk.capture_event(sentry_event, hint=hint)
116114
reraise(*exc_info)
117115
finally:
118116
if timeout_thread:
119117
timeout_thread.stop()
120118
# Flush out the event queue
121-
hub.flush()
119+
client.flush()
122120

123121
return sentry_func # type: ignore
124122

@@ -187,7 +185,7 @@ def event_processor(event, hint):
187185
if hasattr(gcp_event, "headers"):
188186
request["headers"] = _filter_headers(gcp_event.headers)
189187

190-
if _should_send_default_pii():
188+
if should_send_default_pii():
191189
if hasattr(gcp_event, "data"):
192190
request["data"] = gcp_event.data
193191
else:

0 commit comments

Comments
 (0)