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
7 changes: 7 additions & 0 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ def _get_options(*args, **kwargs):
if rv["environment"] is None:
rv["environment"] = os.environ.get("SENTRY_ENVIRONMENT") or "production"

if rv["debug"] is None:
rv["debug"] = os.environ.get("SENTRY_DEBUG", "False").lower() in (
"true",
"1",
"t",
)
Comment on lines +113 to +117

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda remember that we added a helper for determining if a config option was set to something truthy. Can't find it off the top of my head but will look a bit more 👀


if rv["server_name"] is None and hasattr(socket, "gethostname"):
rv["server_name"] = socket.gethostname()

Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def __init__(
max_request_body_size="medium", # type: str
before_send=None, # type: Optional[EventProcessor]
before_breadcrumb=None, # type: Optional[BreadcrumbProcessor]
debug=False, # type: bool
debug=None, # type: Optional[bool]
attach_stacktrace=False, # type: bool
ca_certs=None, # type: Optional[str]
propagate_traces=True, # type: bool
Expand Down
60 changes: 60 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,3 +1136,63 @@ def test_max_value_length_option(
capture_message("a" * 2000)

assert len(events[0]["message"]) == expected_data_length


@pytest.mark.parametrize(
"client_option,env_var_value,debug_output_expected",
[
(None, "", False),
(None, "t", True),
(None, "1", True),
(None, "True", True),
(None, "true", True),
(None, "f", False),
(None, "0", False),
(None, "False", False),
(None, "false", False),
(None, "xxx", False),
(True, "", True),
(True, "t", True),
(True, "1", True),
(True, "True", True),
(True, "true", True),
(True, "f", True),
(True, "0", True),
(True, "False", True),
(True, "false", True),
(True, "xxx", True),
(False, "", False),
(False, "t", False),
(False, "1", False),
(False, "True", False),
(False, "true", False),
(False, "f", False),
(False, "0", False),
(False, "False", False),
(False, "false", False),
(False, "xxx", False),
],
)
@pytest.mark.tests_internal_exceptions
def test_debug_option(
sentry_init,
monkeypatch,
caplog,
client_option,
env_var_value,
debug_output_expected,
):
monkeypatch.setenv("SENTRY_DEBUG", env_var_value)

if client_option is None:
sentry_init()
else:
sentry_init(debug=client_option)

Hub.current._capture_internal_exception(
(ValueError, ValueError("something is wrong"), None)
)
if debug_output_expected:
assert "something is wrong" in caplog.text
else:
assert "something is wrong" not in caplog.text