|
4 | 4 | import sentry_sdk
|
5 | 5 | from sentry_sdk.ai.monitoring import record_token_usage
|
6 | 6 | from sentry_sdk.ai.utils import set_data_normalized, get_start_span_function
|
7 |
| -from sentry_sdk.consts import OP, SPANDATA |
| 7 | +from sentry_sdk.consts import OP, SPANDATA, SPANSTATUS |
8 | 8 | from sentry_sdk.integrations import _check_minimum_version, DidNotEnable, Integration
|
9 | 9 | from sentry_sdk.scope import should_send_default_pii
|
| 10 | +from sentry_sdk.tracing_utils import set_span_errored |
10 | 11 | from sentry_sdk.utils import (
|
11 | 12 | capture_internal_exceptions,
|
12 | 13 | event_from_exception,
|
@@ -52,6 +53,8 @@ def setup_once():
|
52 | 53 |
|
53 | 54 | def _capture_exception(exc):
|
54 | 55 | # type: (Any) -> None
|
| 56 | + set_span_errored() |
| 57 | + |
55 | 58 | event, hint = event_from_exception(
|
56 | 59 | exc,
|
57 | 60 | client_options=sentry_sdk.get_client().options,
|
@@ -357,7 +360,13 @@ def _sentry_patched_create_sync(*args, **kwargs):
|
357 | 360 | integration = sentry_sdk.get_client().get_integration(AnthropicIntegration)
|
358 | 361 | kwargs["integration"] = integration
|
359 | 362 |
|
360 |
| - return _execute_sync(f, *args, **kwargs) |
| 363 | + try: |
| 364 | + return _execute_sync(f, *args, **kwargs) |
| 365 | + finally: |
| 366 | + span = sentry_sdk.get_current_span() |
| 367 | + if span is not None and span.status == SPANSTATUS.ERROR: |
| 368 | + with capture_internal_exceptions(): |
| 369 | + span.__exit__(None, None, None) |
361 | 370 |
|
362 | 371 | return _sentry_patched_create_sync
|
363 | 372 |
|
@@ -390,6 +399,12 @@ async def _sentry_patched_create_async(*args, **kwargs):
|
390 | 399 | integration = sentry_sdk.get_client().get_integration(AnthropicIntegration)
|
391 | 400 | kwargs["integration"] = integration
|
392 | 401 |
|
393 |
| - return await _execute_async(f, *args, **kwargs) |
| 402 | + try: |
| 403 | + return await _execute_async(f, *args, **kwargs) |
| 404 | + finally: |
| 405 | + span = sentry_sdk.get_current_span() |
| 406 | + if span is not None and span.status == SPANSTATUS.ERROR: |
| 407 | + with capture_internal_exceptions(): |
| 408 | + span.__exit__(None, None, None) |
394 | 409 |
|
395 | 410 | return _sentry_patched_create_async
|
0 commit comments