Skip to content

Commit b12823e

Browse files
fix(gcp): Inject scopes in TimeoutThread exception with GCP (#4959)
Restore ServerlessTimeoutWarning isolation and current scope handling, so the scopes are active in a GCP function and breadcrumbs and tags are applied on timeout. The behavior is restored to that before 2d392af. Closes #4958.
1 parent 1ad7163 commit b12823e

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

sentry_sdk/integrations/gcp.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ def sentry_func(functionhandler, gcp_event, *args, **kwargs):
7575
):
7676
waiting_time = configured_time - TIMEOUT_WARNING_BUFFER
7777

78-
timeout_thread = TimeoutThread(waiting_time, configured_time)
78+
timeout_thread = TimeoutThread(
79+
waiting_time,
80+
configured_time,
81+
isolation_scope=scope,
82+
current_scope=sentry_sdk.get_current_scope(),
83+
)
7984

8085
# Starting the thread to raise timeout warning exception
8186
timeout_thread.start()

tests/integrations/gcp/test_gcp.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ def test_timeout_error(run_cloud_function):
196196
functionhandler = None
197197
event = {}
198198
def cloud_function(functionhandler, event):
199+
sentry_sdk.set_tag("cloud_function", "true")
199200
time.sleep(10)
200201
return "3"
201202
"""
@@ -219,6 +220,8 @@ def cloud_function(functionhandler, event):
219220
assert exception["mechanism"]["type"] == "threading"
220221
assert not exception["mechanism"]["handled"]
221222

223+
assert envelope_items[0]["tags"]["cloud_function"] == "true"
224+
222225

223226
def test_performance_no_error(run_cloud_function):
224227
envelope_items, _ = run_cloud_function(

0 commit comments

Comments
 (0)