Skip to content

Commit 2452113

Browse files
authored
Auto-enable more integrations (getsentry#2671)
1 parent d600037 commit 2452113

6 files changed

Lines changed: 33 additions & 12 deletions

File tree

MIGRATION_GUIDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- The `reraise` function was moved from `sentry_sdk._compat` to `sentry_sdk.utils`.
1111
- Moved the contents of `tracing_utils_py3.py` to `tracing_utils.py`. The `start_child_span_decorator` is now in `sentry_sdk.tracing_utils`.
1212
- The actual implementation of `get_current_span` was moved to `sentry_sdk.tracing_utils`. `sentry_sdk.get_current_span` is still accessible as part of the top-level API.
13+
- Additional integrations will now be activated automatically if the SDK detects the respective package is installed: Ariadne, ARQ, asyncpg, Chalice, clickhouse-driver, GQL, Graphene, huey, Loguru, PyMongo, Quart, Starlite, Strawberry.
1314

1415
## Removed
1516

sentry_sdk/integrations/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,33 @@ def iter_default_integrations(with_auto_enabling_integrations):
6868

6969
_AUTO_ENABLING_INTEGRATIONS = [
7070
"sentry_sdk.integrations.aiohttp.AioHttpIntegration",
71+
"sentry_sdk.integrations.ariadne.AriadneIntegration",
72+
"sentry_sdk.integrations.arq.ArqIntegration",
73+
"sentry_sdk.integrations.asyncpg.AsyncPGIntegration",
7174
"sentry_sdk.integrations.boto3.Boto3Integration",
7275
"sentry_sdk.integrations.bottle.BottleIntegration",
7376
"sentry_sdk.integrations.celery.CeleryIntegration",
77+
"sentry_sdk.integrations.chalice.ChaliceIntegration",
78+
"sentry_sdk.integrations.clickhouse_driver.ClickhouseDriverIntegration",
7479
"sentry_sdk.integrations.django.DjangoIntegration",
7580
"sentry_sdk.integrations.falcon.FalconIntegration",
7681
"sentry_sdk.integrations.fastapi.FastApiIntegration",
7782
"sentry_sdk.integrations.flask.FlaskIntegration",
83+
"sentry_sdk.integrations.gql.GQLIntegration",
84+
"sentry_sdk.integrations.graphene.GrapheneIntegration",
7885
"sentry_sdk.integrations.httpx.HttpxIntegration",
86+
"sentry_sdk.integrations.huey.HueyIntegration",
87+
"sentry_sdk.integrations.loguru.LoguruIntegration",
88+
"sentry_sdk.integrations.pymongo.PyMongoIntegration",
7989
"sentry_sdk.integrations.pyramid.PyramidIntegration",
90+
"sentry_sdk.integrations.quart.QuartIntegration",
8091
"sentry_sdk.integrations.redis.RedisIntegration",
8192
"sentry_sdk.integrations.rq.RqIntegration",
8293
"sentry_sdk.integrations.sanic.SanicIntegration",
8394
"sentry_sdk.integrations.sqlalchemy.SqlalchemyIntegration",
8495
"sentry_sdk.integrations.starlette.StarletteIntegration",
96+
"sentry_sdk.integrations.starlite.StarliteIntegration",
97+
"sentry_sdk.integrations.strawberry.StrawberryIntegration",
8598
"sentry_sdk.integrations.tornado.TornadoIntegration",
8699
]
87100

sentry_sdk/integrations/asyncpg.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import contextlib
33
from typing import Any, TypeVar, Callable, Awaitable, Iterator
44

5-
from asyncpg.cursor import BaseCursor # type: ignore
6-
75
from sentry_sdk import Hub
86
from sentry_sdk.consts import OP, SPANDATA
97
from sentry_sdk.integrations import Integration, DidNotEnable
@@ -13,6 +11,7 @@
1311

1412
try:
1513
import asyncpg # type: ignore[import-not-found]
14+
from asyncpg.cursor import BaseCursor # type: ignore
1615

1716
except ImportError:
1817
raise DidNotEnable("asyncpg not installed.")

sentry_sdk/integrations/chalice.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
)
1414
from sentry_sdk._types import TYPE_CHECKING
1515

16-
import chalice # type: ignore
17-
from chalice import Chalice, ChaliceViewError
18-
from chalice.app import EventSourceHandler as ChaliceEventSourceHandler # type: ignore
16+
try:
17+
import chalice # type: ignore
18+
from chalice import __version__ as CHALICE_VERSION
19+
from chalice import Chalice, ChaliceViewError
20+
from chalice.app import EventSourceHandler as ChaliceEventSourceHandler # type: ignore
21+
except ImportError:
22+
raise DidNotEnable("Chalice is not installed")
1923

2024
if TYPE_CHECKING:
2125
from typing import Any
@@ -25,11 +29,6 @@
2529

2630
F = TypeVar("F", bound=Callable[..., Any])
2731

28-
try:
29-
from chalice import __version__ as CHALICE_VERSION
30-
except ImportError:
31-
raise DidNotEnable("Chalice is not installed")
32-
3332

3433
class EventSourceHandler(ChaliceEventSourceHandler): # type: ignore
3534
def __call__(self, event, context):

sentry_sdk/integrations/starlite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from typing import TYPE_CHECKING
22

3-
from pydantic import BaseModel # type: ignore
43
from sentry_sdk.consts import OP
54
from sentry_sdk.hub import Hub, _should_send_default_pii
65
from sentry_sdk.integrations import DidNotEnable, Integration
@@ -15,6 +14,7 @@
1514
from starlite.plugins.base import get_plugin_for_value # type: ignore
1615
from starlite.routes.http import HTTPRoute # type: ignore
1716
from starlite.utils import ConnectionDataExtractor, is_async_callable, Ref # type: ignore
17+
from pydantic import BaseModel # type: ignore
1818

1919
if TYPE_CHECKING:
2020
from typing import Any, Dict, List, Optional, Union

sentry_sdk/integrations/strawberry.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import hashlib
2-
from functools import cached_property
32
from inspect import isawaitable
3+
44
from sentry_sdk import configure_scope, start_span
55
from sentry_sdk.consts import OP
66
from sentry_sdk.integrations import Integration, DidNotEnable
@@ -15,6 +15,15 @@
1515
)
1616
from sentry_sdk._types import TYPE_CHECKING
1717

18+
try:
19+
from functools import cached_property
20+
except ImportError:
21+
# The strawberry integration requires Python 3.8+. functools.cached_property
22+
# was added in 3.8, so this check is technically not needed, but since this
23+
# is an auto-enabling integration, we might get to executing this import in
24+
# lower Python versions, so we need to deal with it.
25+
raise DidNotEnable("strawberry-graphql integration requires Python 3.8 or newer")
26+
1827
try:
1928
import strawberry.schema.schema as strawberry_schema # type: ignore
2029
from strawberry import Schema

0 commit comments

Comments
 (0)