Skip to content

Commit 5417776

Browse files
committed
Fixed capturing of exceptions
1 parent 35b372e commit 5417776

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

sentry_sdk/integrations/anthropic.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,7 @@ def _sentry_patched_create_common(f, *args, **kwargs):
154154
)
155155
span.__enter__()
156156

157-
try:
158-
result = yield f, args, kwargs
159-
except Exception as exc:
160-
_capture_exception(exc)
161-
span.__exit__(None, None, None)
162-
raise exc from None
157+
result = yield f, args, kwargs
163158

164159
# add data to span and finish it
165160
messages = list(kwargs["messages"])
@@ -242,7 +237,12 @@ def _execute_sync(f, *args, **kwargs):
242237
return e.value
243238

244239
try:
245-
result = f(*args, **kwargs)
240+
try:
241+
result = f(*args, **kwargs)
242+
except Exception as exc:
243+
_capture_exception(exc)
244+
raise exc from None
245+
246246
return gen.send(result)
247247
except StopIteration as e:
248248
return e.value
@@ -270,7 +270,12 @@ async def _execute_async(f, *args, **kwargs):
270270
return await e.value
271271

272272
try:
273-
result = await f(*args, **kwargs)
273+
try:
274+
result = await f(*args, **kwargs)
275+
except Exception as exc:
276+
_capture_exception(exc)
277+
raise exc from None
278+
274279
return gen.send(result)
275280
except StopIteration as e:
276281
return e.value

0 commit comments

Comments
 (0)