8000 fix: New scope for each serverless func · etherscan-io/sentry-python@0a20f09 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a20f09

Browse files
committed
fix: New scope for each serverless func
1 parent b2a03b6 commit 0a20f09

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

sentry_sdk/integrations/serverless.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ def serverless_function(f=None, flush=True):
1010
def wrapper(f):
1111
@functools.wraps(f)
1212
def inner(*args, **kwargs):
13-
try:
14-
return f(*args, **kwargs)
15-
except Exception:
16-
_capture_and_reraise()
17-
finally:
18-
if flush:
19-
_flush_client()
13+
with Hub(Hub.current):
14+
try:
15+
return f(*args, **kwargs)
16+
except Exception:
17+
_capture_and_reraise()
18+
finally:
19+
if flush:
20+
_flush_client()
2021

2122
return inner
2223

tests/integrations/serverless/test_serverless.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ def test_basic(sentry_init, capture_exceptions, monkeypatch):
99

1010
flush_calls = []
1111

12-
monkeypatch.setattr("sentry_sdk.Hub.current.flush", lambda: flush_calls.append(1))
13-
1412
@serverless_function
1513
def foo():
14+
monkeypatch.setattr(
15+
"sentry_sdk.Hub.current.flush", lambda: flush_calls.append(1)
16+
)
1617
1 / 0
1718

1819
with pytest.raises(ZeroDivisionError):

0 commit comments

Comments
 (0)
0