Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sentry: support disabling error reporting #2214

Merged
merged 4 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions snapcraft/cli/_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ def _handle_trace_output(


def _is_send_to_sentry() -> bool: # noqa: C901
# Check to see if error reporting has been disabled
if (
distutils.util.strtobool(os.getenv("SNAPCRAFT_ENABLE_ERROR_REPORTING", "y"))
== 0
):
return False

# Check the environment to see if we should allow for silent reporting
if distutils.util.strtobool(os.getenv("SNAPCRAFT_ENABLE_SILENT_REPORT", "n")) == 1:
click.echo(_MSG_SILENT_REPORT)
Expand Down
6 changes: 6 additions & 0 deletions spread.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ environment:
# nothing.
SNAPCRAFT_CHANNEL: "$(HOST: echo ${SNAPCRAFT_CHANNEL})"

# Show error tracebacks
SNAPCRAFT_MANAGED_HOST: "yes"

# Disable all Sentry error reporting
SNAPCRAFT_ENABLE_ERROR_REPORTING: "no"

SETUP_DIR: /snapcraft/tests/spread/setup

backends:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def setUp(self):
# Disable Sentry reporting for tests, otherwise they'll hang waiting
# for input
self.useFixture(
fixtures.EnvironmentVariable("SNAPCRAFT_ENABLE_SENTRY", "false")
fixtures.EnvironmentVariable("SNAPCRAFT_ENABLE_ERROR_REPORTING", "false")
)

# Note that these directories won't exist when the test starts,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def setUp(self):
# Disable Sentry reporting for tests, otherwise they'll hang waiting
# for input
self.useFixture(
fixtures.EnvironmentVariable("SNAPCRAFT_ENABLE_SENTRY", "false")
fixtures.EnvironmentVariable("SNAPCRAFT_ENABLE_ERROR_REPORTING", "false")
Copy link
Collaborator

Choose a reason for hiding this comment

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

oh, the new structure makes this unnecessary, to be honest, I'd remove these lines completely

)

machine = os.environ.get("SNAPCRAFT_TEST_MOCK_MACHINE", None)
Expand Down
18 changes: 16 additions & 2 deletions tests/unit/cli/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ def setUp(self):
self.raven_client_mock = patcher.start()
self.addCleanup(patcher.stop)

self.useFixture(fixtures.EnvironmentVariable("SNAPCRAFT_ENABLE_SENTRY", "yes"))


class SendToSentryIsYesTest(SendToSentryBaseTest):

Expand Down Expand Up @@ -276,3 +274,19 @@ def test_send_with_config_error_does_not_save_always(self):

# Given the corruption, ensure it hasn't been written to
self.assertThat(config_path, FileContains("bad data"))


class SendToSentryDisabledTest(SendToSentryBaseTest):
def test_disabled_no_send(self):
self.prompt_mock.return_value = "yes"
self.useFixture(
fixtures.EnvironmentVariable("SNAPCRAFT_ENABLE_ERROR_REPORTING", "no")
)

try:
self.call_handler(RuntimeError("not a SnapcraftError"), True)
except Exception:
self.fail("Exception unexpectedly raised")

self.assert_exception_traceback_exit_1_with_debug()
self.raven_client_mock.assert_not_called()