From 2ad63e6261a788cf2116870b5c7009265e304a63 Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Tue, 5 Jul 2022 14:54:10 +0200 Subject: [PATCH] Add option to force failure to test Sentry SDK (fixes #617) (#1398) * Add option to force failure to test Sentry SDK (fixes #617) * Update aws_lambda.py Co-authored-by: Sven Marnach Co-authored-by: Sven Marnach --- aws_lambda.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/aws_lambda.py b/aws_lambda.py index 20313b2e..d019d94a 100755 --- a/aws_lambda.py +++ b/aws_lambda.py @@ -10,6 +10,7 @@ SENTRY_DSN = config("SENTRY_DSN", default=None) SENTRY_ENV = config("SENTRY_ENV", default=None) +SERVER_URL = os.getenv("SERVER", "http://localhost:8888/v1") if SENTRY_DSN: # Note! If you don't do `sentry_sdk.init(DSN)` it will still work @@ -61,7 +62,7 @@ def white_bold(s): def run(command, event=None, context=None): if event is None: - event = {"server": os.getenv("SERVER", "http://localhost:8888/v1")} + event = {"server": SERVER_URL} if context is None: context = {"sentry_sdk": sentry_sdk} @@ -70,10 +71,15 @@ def run(command, event=None, context=None): mod = importlib.import_module(f"commands.{command}") command = getattr(mod, command) - # Note! If the sentry_sdk was initialized with - # the AwsLambdaIntegration integration, it is now ready to automatically - # capture all and any unexpected exceptions. - # See https://docs.sentry.io/platforms/python/aws_lambda/ + # Note! If the sentry_sdk was initialized with the platform integration, + # it is now ready to automatically capture all and any unexpected exceptions. + # See https://docs.sentry.io/platforms/python/guides/aws-lambda/ + # See https://docs.sentry.io/platforms/python/guides/gcp-functions/ + + # Option to test failure to test Sentry integration. + if event.get("force_fail") or os.getenv("FORCE_FAIL"): + raise Exception("Found forced failure flag") + command(event, context)