Skip to content

Commit

Permalink
Add option to force failure to test Sentry SDK (fixes #617) (#1398)
Browse files Browse the repository at this point in the history
* Add option to force failure to test Sentry SDK (fixes #617)

* Update aws_lambda.py

Co-authored-by: Sven Marnach <[email protected]>

Co-authored-by: Sven Marnach <[email protected]>
  • Loading branch information
leplatrem and smarnach authored Jul 5, 2022
1 parent 3feee6d commit 2ad63e6
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions aws_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}

Expand All @@ -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)


Expand Down

0 comments on commit 2ad63e6

Please sign in to comment.