Skip to content

Commit 3d61930

Browse files
fix(anthropic): Only finish relevant spans in .create() patches
1 parent f228d7e commit 3d61930

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

sentry_sdk/integrations/anthropic.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ def _sentry_patched_create_sync(f: "Any", *args: "Any", **kwargs: "Any") -> "Any
633633
exc_info = sys.exc_info()
634634
with capture_internal_exceptions():
635635
_capture_exception(exc)
636+
span.__exit__(None, None, None)
636637
reraise(*exc_info)
637638

638639
if isinstance(result, Stream):
@@ -720,6 +721,7 @@ async def _sentry_patched_create_async(
720721
exc_info = sys.exc_info()
721722
with capture_internal_exceptions():
722723
_capture_exception(exc)
724+
span.__exit__(None, None, None)
723725
reraise(*exc_info)
724726

725727
if isinstance(result, AsyncStream):
@@ -778,13 +780,7 @@ def _sentry_wrapped_create_sync(*args: "Any", **kwargs: "Any") -> "Any":
778780
integration = sentry_sdk.get_client().get_integration(AnthropicIntegration)
779781
kwargs["integration"] = integration
780782

781-
try:
782-
return _sentry_patched_create_sync(f, *args, **kwargs)
783-
finally:
784-
span = sentry_sdk.get_current_span()
785-
if span is not None and span.status == SPANSTATUS.INTERNAL_ERROR:
786-
with capture_internal_exceptions():
787-
span.__exit__(None, None, None)
783+
return _sentry_patched_create_sync(f, *args, **kwargs)
788784

789785
return _sentry_wrapped_create_sync
790786

0 commit comments

Comments
 (0)