From c42c04b10bed333307fed43961acc4e9ac520b6a Mon Sep 17 00:00:00 2001 From: Sven Marnach Date: Tue, 21 Jun 2022 17:01:59 +0200 Subject: [PATCH] Add option to set a Sentry environment. (#1395) * Add option to set a Sentry environment. --- README.md | 6 ++++-- aws_lambda.py | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f2e73344..08357229 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,10 @@ A collection of scripts related to the Remote Settings service. ## Sentry -All commands use Sentry to report any unexpected errors. The `SENTRY_DSN` -environment variable is not required but is recommended. +All commands use Sentry to report any unexpected errors. Sentry can be configured with these environment variables, which are recommended, but not required: + +- `SENTRY_DSN`: The DSN from the "Client Keys" section in the project settings in Sentry. +- `SENTRY_ENV`: The environment to use for Sentry, e.g. dev, stage or prod. ## Commands diff --git a/aws_lambda.py b/aws_lambda.py index 5917392b..82d4c522 100755 --- a/aws_lambda.py +++ b/aws_lambda.py @@ -9,12 +9,16 @@ from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration SENTRY_DSN = config("SENTRY_DSN", default=None) +SENTRY_ENV = config("SENTRY_ENV", default=None) if SENTRY_DSN: # Note! If you don't do `sentry_sdk.init(DSN)` it will still work # to do things like calling `sentry_sdk.capture_exception(exception)` # It just means it's a noop. - sentry_sdk.init(SENTRY_DSN, integrations=[AwsLambdaIntegration()]) + env_option = {} + if SENTRY_ENV: + env_option = {"environment": SENTRY_ENV} + sentry_sdk.init(SENTRY_DSN, integrations=[AwsLambdaIntegration()], **env_option) def help_(**kwargs):