2025-12-01
This commit is contained in:
+12
-11
@@ -1,5 +1,6 @@
|
||||
import functools
|
||||
import hashlib
|
||||
import warnings
|
||||
from inspect import isawaitable
|
||||
|
||||
import sentry_sdk
|
||||
@@ -7,7 +8,7 @@ from sentry_sdk.consts import OP
|
||||
from sentry_sdk.integrations import _check_minimum_version, Integration, DidNotEnable
|
||||
from sentry_sdk.integrations.logging import ignore_logger
|
||||
from sentry_sdk.scope import should_send_default_pii
|
||||
from sentry_sdk.tracing import TRANSACTION_SOURCE_COMPONENT
|
||||
from sentry_sdk.tracing import TransactionSource
|
||||
from sentry_sdk.utils import (
|
||||
capture_internal_exceptions,
|
||||
ensure_integration_enabled,
|
||||
@@ -95,17 +96,19 @@ def _patch_schema_init():
|
||||
|
||||
extensions = kwargs.get("extensions") or []
|
||||
|
||||
should_use_async_extension = None # type: Optional[bool]
|
||||
if integration.async_execution is not None:
|
||||
should_use_async_extension = integration.async_execution
|
||||
else:
|
||||
# try to figure it out ourselves
|
||||
should_use_async_extension = _guess_if_using_async(extensions)
|
||||
|
||||
logger.info(
|
||||
"Assuming strawberry is running %s. If not, initialize it as StrawberryIntegration(async_execution=%s).",
|
||||
"async" if should_use_async_extension else "sync",
|
||||
"False" if should_use_async_extension else "True",
|
||||
)
|
||||
if should_use_async_extension is None:
|
||||
warnings.warn(
|
||||
"Assuming strawberry is running sync. If not, initialize the integration as StrawberryIntegration(async_execution=True).",
|
||||
stacklevel=2,
|
||||
)
|
||||
should_use_async_extension = False
|
||||
|
||||
# remove the built in strawberry sentry extension, if present
|
||||
extensions = [
|
||||
@@ -208,7 +211,7 @@ class SentryAsyncExtension(SchemaExtension):
|
||||
transaction = self.graphql_span.containing_transaction
|
||||
if transaction and self.execution_context.operation_name:
|
||||
transaction.name = self.execution_context.operation_name
|
||||
transaction.source = TRANSACTION_SOURCE_COMPONENT
|
||||
transaction.source = TransactionSource.COMPONENT
|
||||
transaction.op = op
|
||||
|
||||
self.graphql_span.finish()
|
||||
@@ -382,12 +385,10 @@ def _make_response_event_processor(response_data):
|
||||
|
||||
|
||||
def _guess_if_using_async(extensions):
|
||||
# type: (List[SchemaExtension]) -> bool
|
||||
# type: (List[SchemaExtension]) -> Optional[bool]
|
||||
if StrawberrySentryAsyncExtension in extensions:
|
||||
return True
|
||||
elif StrawberrySentrySyncExtension in extensions:
|
||||
return False
|
||||
|
||||
return bool(
|
||||
{"starlette", "starlite", "litestar", "fastapi"} & set(_get_installed_modules())
|
||||
)
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user