Skip to content

Commit

Permalink
Fix(serverless): Add "SENTRY_" prefix to env variables in serverless …
Browse files Browse the repository at this point in the history
…init script + added traces_sample_rate (#1025)

* Added SENTRY_ prefix to serverless env variables and added traces sample rate env variable

* Linting reformat
  • Loading branch information
ahmedetefy authored Feb 18, 2021
1 parent 25125b5 commit 3be779a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions scripts/init_serverless_sdk.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
For manual instrumentation,
The Handler function string of an aws lambda function should be added as an
environment variable with a key of 'INITIAL_HANDLER' along with the 'DSN'
environment variable with a key of 'SENTRY_INITIAL_HANDLER' along with the 'DSN'
Then the Handler function sstring should be replaced with
'sentry_sdk.integrations.init_serverless_sdk.sentry_lambda_handler'
"""
Expand All @@ -17,19 +17,20 @@

# Configure Sentry SDK
sentry_sdk.init(
dsn=os.environ["DSN"],
dsn=os.environ["SENTRY_DSN"],
integrations=[AwsLambdaIntegration(timeout_warning=True)],
traces_sample_rate=float(os.environ["SENTRY_TRACES_SAMPLE_RATE"])
)


def sentry_lambda_handler(event, context):
# type: (Any, Any) -> None
"""
Handler function that invokes a lambda handler which path is defined in
environment vairables as "INITIAL_HANDLER"
environment vairables as "SENTRY_INITIAL_HANDLER"
"""
try:
module_name, handler_name = os.environ["INITIAL_HANDLER"].rsplit(".", 1)
module_name, handler_name = os.environ["SENTRY_INITIAL_HANDLER"].rsplit(".", 1)
except ValueError:
raise ValueError("Incorrect AWS Handler path (Not a path)")
lambda_function = __import__(module_name)
Expand Down
5 changes: 3 additions & 2 deletions tests/integrations/aws_lambda/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ def build_no_code_serverless_function_and_layer(
Timeout=timeout,
Environment={
"Variables": {
"INITIAL_HANDLER": "test_lambda.test_handler",
"DSN": "https://[email protected]/123",
"SENTRY_INITIAL_HANDLER": "test_lambda.test_handler",
"SENTRY_DSN": "https://[email protected]/123",
"SENTRY_TRACES_SAMPLE_RATE": "1.0",
}
},
Role=os.environ["SENTRY_PYTHON_TEST_AWS_IAM_ROLE"],
Expand Down

0 comments on commit 3be779a

Please sign in to comment.