Skip to content
Snippets Groups Projects
Commit 8f2cfa88 authored by Nicolas Dandrimont's avatar Nicolas Dandrimont
Browse files

gunicorn: disable sentry logging event reporting by default

By default, sentry's logging integration will report any error or
exception-level logging as an event.

Now that we explicitly capture exceptions in the RPC server app, we can
disable this automatic event generation, and only use the logging
integration to generate breadcrumbs.
parent b9b898e3
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,7 @@ def post_fork(
flask=True,
sentry_integrations=None,
extra_sentry_kwargs={},
disable_logging_events=True,
):
# Initializes sentry as soon as possible in gunicorn's worker processes.
......@@ -36,4 +37,5 @@ def post_fork(
default_sentry_dsn,
integrations=sentry_integrations,
extra_kwargs=extra_sentry_kwargs,
disable_logging_events=disable_logging_events,
)
......@@ -20,16 +20,22 @@ def test_post_fork_default():
def test_post_fork_with_dsn_env():
flask_integration = object() # unique object to check for equality
logging_integration = object() # unique object to check for equality
with patch(
"sentry_sdk.integrations.flask.FlaskIntegration", new=lambda: flask_integration
), patch(
"sentry_sdk.integrations.logging.LoggingIntegration",
new=lambda event_level: logging_integration,
), patch(
"sentry_sdk.init"
) as sentry_sdk_init, patch.dict(
os.environ, {"SWH_SENTRY_DSN": "test_dsn"}
):
with patch("sentry_sdk.init") as sentry_sdk_init:
with patch.dict(os.environ, {"SWH_SENTRY_DSN": "test_dsn"}):
gunicorn_config.post_fork(None, None)
gunicorn_config.post_fork(None, None)
sentry_sdk_init.assert_called_once_with(
dsn="test_dsn",
integrations=[flask_integration],
integrations=[flask_integration, logging_integration],
debug=False,
release=None,
environment=None,
......@@ -37,26 +43,31 @@ def test_post_fork_with_dsn_env():
def test_post_fork_with_package_env():
flask_integration = object() # unique object to check for equality
flask_integration = object()
logging_integration = object()
with patch(
"sentry_sdk.integrations.flask.FlaskIntegration", new=lambda: flask_integration
), patch(
"sentry_sdk.integrations.logging.LoggingIntegration",
new=lambda event_level: logging_integration,
), patch(
"sentry_sdk.init"
) as sentry_sdk_init, patch.dict(
os.environ,
{
"SWH_SENTRY_DSN": "test_dsn",
"SWH_SENTRY_ENVIRONMENT": "tests",
"SWH_MAIN_PACKAGE": "swh.core",
},
):
with patch("sentry_sdk.init") as sentry_sdk_init:
with patch.dict(
os.environ,
{
"SWH_SENTRY_DSN": "test_dsn",
"SWH_SENTRY_ENVIRONMENT": "tests",
"SWH_MAIN_PACKAGE": "swh.core",
},
):
gunicorn_config.post_fork(None, None)
gunicorn_config.post_fork(None, None)
version = pkg_resources.get_distribution("swh.core").version
sentry_sdk_init.assert_called_once_with(
dsn="test_dsn",
integrations=[flask_integration],
integrations=[flask_integration, logging_integration],
debug=False,
release="swh.core@" + version,
environment="tests",
......@@ -64,19 +75,24 @@ def test_post_fork_with_package_env():
def test_post_fork_debug():
flask_integration = object() # unique object to check for equality
flask_integration = object()
logging_integration = object()
with patch(
"sentry_sdk.integrations.flask.FlaskIntegration", new=lambda: flask_integration
), patch(
"sentry_sdk.integrations.logging.LoggingIntegration",
new=lambda event_level: logging_integration,
), patch(
"sentry_sdk.init"
) as sentry_sdk_init, patch.dict(
os.environ, {"SWH_SENTRY_DSN": "test_dsn", "SWH_SENTRY_DEBUG": "1"}
):
with patch("sentry_sdk.init") as sentry_sdk_init:
with patch.dict(
os.environ, {"SWH_SENTRY_DSN": "test_dsn", "SWH_SENTRY_DEBUG": "1"}
):
gunicorn_config.post_fork(None, None)
gunicorn_config.post_fork(None, None)
sentry_sdk_init.assert_called_once_with(
dsn="test_dsn",
integrations=[flask_integration],
integrations=[flask_integration, logging_integration],
debug=True,
release=None,
environment=None,
......@@ -84,13 +100,17 @@ def test_post_fork_debug():
def test_post_fork_no_flask():
with patch("sentry_sdk.init") as sentry_sdk_init:
with patch.dict(os.environ, {"SWH_SENTRY_DSN": "test_dsn"}):
gunicorn_config.post_fork(None, None, flask=False)
logging_integration = object()
with patch("sentry_sdk.init") as sentry_sdk_init, patch(
"sentry_sdk.integrations.logging.LoggingIntegration",
new=lambda event_level: logging_integration,
), patch.dict(os.environ, {"SWH_SENTRY_DSN": "test_dsn"}):
gunicorn_config.post_fork(None, None, flask=False)
sentry_sdk_init.assert_called_once_with(
dsn="test_dsn",
integrations=[],
integrations=[logging_integration],
debug=False,
release=None,
environment=None,
......@@ -109,6 +129,7 @@ def test_post_fork_extras():
None,
sentry_integrations=["foo"],
extra_sentry_kwargs={"bar": "baz"},
disable_logging_events=False,
)
sentry_sdk_init.assert_called_once_with(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment