Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sentry_sdk/integrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down
12 changes: 7 additions & 5 deletions sentry_sdk/integrations/pyramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions sentry_sdk/integrations/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down
22 changes: 13 additions & 9 deletions tests/integrations/celery/test_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
]

Expand Down Expand Up @@ -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"

Expand Down
6 changes: 6 additions & 0 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down