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
1 change: 1 addition & 0 deletions sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"ignore_errors": [],
"request_bodies": "medium",
"before_send": None,
"debug": False,
}

SDK_INFO = {"name": "sentry-python", "version": VERSION}
8 changes: 6 additions & 2 deletions sentry_sdk/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

from ._compat import with_metaclass
from .scope import Scope
from .utils import exc_info_from_error, event_from_exception, ContextVar
from .utils import exc_info_from_error, event_from_exception, get_logger, ContextVar


_local = ContextVar("sentry_current_hub")

logger = get_logger(__name__)


@contextmanager
def _internal_exceptions():
Expand Down Expand Up @@ -134,7 +136,9 @@ def capture_exception(self, error=None):
def capture_internal_exception(self, exc_info):
"""Capture an exception that is likely caused by a bug in the SDK
itself."""
pass
client = self.client
if client is not None and client.options["debug"]:
logger.debug("Internal error in sentry_sdk", exc_info=exc_info)

def add_breadcrumb(self, *args, **kwargs):
"""Adds a breadcrumb."""
Expand Down
9 changes: 9 additions & 0 deletions sentry_sdk/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import sys
import linecache
import logging

from datetime import datetime
from collections import Mapping, Sequence
Expand Down Expand Up @@ -520,6 +521,14 @@ def strip_string(value, assume_length=None, max_length=512):
return value[:max_length]


def get_logger(name):
rv = logging.getLogger(name)
if not rv.handlers:
rv.addHandler(logging.StreamHandler(sys.stderr))
rv.setLevel(logging.DEBUG)
return rv


try:
from contextvars import ContextVar
except ImportError:
Expand Down
5 changes: 4 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@


@pytest.fixture(autouse=True)
def reraise_internal_exceptions(monkeypatch):
def reraise_internal_exceptions(request, monkeypatch):
if "tests_internal_exceptions" in request.keywords:
return

def capture_internal_exception(exc_info):
reraise(*exc_info)

Expand Down
20 changes: 19 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def callback(scope):
assert not calls


def test_transport_works(sentry_init, httpserver, request, capsys):
def test_transport_works(httpserver, request, capsys):
httpserver.serve_content("ok", 200)

client = Client("http://foobar@{}/123".format(httpserver.url[len("http://") :]))
Expand All @@ -152,3 +152,21 @@ def test_transport_works(sentry_init, httpserver, request, capsys):
out, err = capsys.readouterr()
assert not err and not out
assert httpserver.requests


@pytest.mark.tests_internal_exceptions
def test_client_debug_option_enabled(sentry_init, caplog):
sentry_init(debug=True)

Hub.current.capture_internal_exception((ValueError, ValueError("OK"), None))
assert "OK" in caplog.text


@pytest.mark.tests_internal_exceptions
@pytest.mark.parametrize("with_client", (True, False))
def test_client_debug_option_disabled(with_client, sentry_init, caplog):
if with_client:
sentry_init()

Hub.current.capture_internal_exception((ValueError, ValueError("OK"), None))
assert "OK" not in caplog.text