diff --git a/sentry_sdk/integrations/__init__.py b/sentry_sdk/integrations/__init__.py index 777c363e14..114a3a1f41 100644 --- a/sentry_sdk/integrations/__init__.py +++ b/sentry_sdk/integrations/__init__.py @@ -62,6 +62,8 @@ def iter_default_integrations(with_auto_enabling_integrations): "sentry_sdk.integrations.aiohttp.AioHttpIntegration", "sentry_sdk.integrations.tornado.TornadoIntegration", "sentry_sdk.integrations.sqlalchemy.SqlalchemyIntegration", + "sentry_sdk.integrations.redis.RedisIntegration", + "sentry_sdk.integrations.pyramid.PyramidIntegration", "sentry_sdk.integrations.boto3.Boto3Integration", ) diff --git a/sentry_sdk/integrations/pyramid.py b/sentry_sdk/integrations/pyramid.py index a974d297a9..980d56bb6f 100644 --- a/sentry_sdk/integrations/pyramid.py +++ b/sentry_sdk/integrations/pyramid.py @@ -4,17 +4,20 @@ import sys import weakref -from pyramid.httpexceptions import HTTPException -from pyramid.request import Request - from sentry_sdk.hub import Hub, _should_send_default_pii from sentry_sdk.utils import capture_internal_exceptions, event_from_exception from sentry_sdk._compat import reraise, iteritems -from sentry_sdk.integrations import Integration +from sentry_sdk.integrations import Integration, DidNotEnable from sentry_sdk.integrations._wsgi_common import RequestExtractor from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware +try: + from pyramid.httpexceptions import HTTPException + from pyramid.request import Request +except ImportError: + raise DidNotEnable("Pyramid not installed") + from sentry_sdk._types import MYPY if MYPY: @@ -64,7 +67,6 @@ def __init__(self, transaction_style="route_name"): def setup_once(): # type: () -> None from pyramid import router - from pyramid.request import Request old_call_view = router._call_view diff --git a/sentry_sdk/integrations/redis.py b/sentry_sdk/integrations/redis.py index 6475d15bf6..df7cbae7bb 100644 --- a/sentry_sdk/integrations/redis.py +++ b/sentry_sdk/integrations/redis.py @@ -2,7 +2,7 @@ from sentry_sdk import Hub from sentry_sdk.utils import capture_internal_exceptions, logger -from sentry_sdk.integrations import Integration +from sentry_sdk.integrations import Integration, DidNotEnable from sentry_sdk._types import MYPY @@ -40,7 +40,10 @@ class RedisIntegration(Integration): @staticmethod def setup_once(): # type: () -> None - import redis + try: + import redis + except ImportError: + raise DidNotEnable("Redis client not installed") patch_redis_client(redis.StrictRedis) diff --git a/tests/integrations/celery/test_celery.py b/tests/integrations/celery/test_celery.py index bdf1706c59..a77ac1adb1 100644 --- a/tests/integrations/celery/test_celery.py +++ b/tests/integrations/celery/test_celery.py @@ -171,14 +171,14 @@ def dummy_task(x, y): assert execution_event["spans"] == [] assert submission_event["spans"] == [ { - u"description": u"dummy_task", - u"op": "celery.submit", - u"parent_span_id": submission_event["contexts"]["trace"]["span_id"], - u"same_process_as_parent": True, - u"span_id": submission_event["spans"][0]["span_id"], - u"start_timestamp": submission_event["spans"][0]["start_timestamp"], - u"timestamp": submission_event["spans"][0]["timestamp"], - u"trace_id": text_type(transaction.trace_id), + "description": "dummy_task", + "op": "celery.submit", + "parent_span_id": submission_event["contexts"]["trace"]["span_id"], + "same_process_as_parent": True, + "span_id": submission_event["spans"][0]["span_id"], + "start_timestamp": submission_event["spans"][0]["start_timestamp"], + "timestamp": submission_event["spans"][0]["timestamp"], + "trace_id": text_type(transaction.trace_id), } ] @@ -338,7 +338,11 @@ def dummy_task(self): submit_transaction = events.read_event() assert submit_transaction["type"] == "transaction" assert submit_transaction["transaction"] == "submit_celery" - (span,) = submit_transaction["spans"] + + assert len( + submit_transaction["spans"] + ), 4 # Because redis integration was auto enabled + span = submit_transaction["spans"][0] assert span["op"] == "celery.submit" assert span["description"] == "dummy_task" diff --git a/tests/test_basics.py b/tests/test_basics.py index 7991a58f75..e9ae6465c9 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -50,10 +50,16 @@ def error_processor(event, exc_info): def test_auto_enabling_integrations_catches_import_error(sentry_init, caplog): caplog.set_level(logging.DEBUG) + REDIS = 10 # noqa: N806 sentry_init(auto_enabling_integrations=True, debug=True) for import_string in _AUTO_ENABLING_INTEGRATIONS: + # Ignore redis in the test case, because it is installed as a + # dependency for running tests, and therefore always enabled. + if _AUTO_ENABLING_INTEGRATIONS[REDIS] == import_string: + continue + assert any( record.message.startswith( "Did not import default integration {}:".format(import_string)