Skip to content

Commit 3be779a

Browse files
authored
Fix(serverless): Add "SENTRY_" prefix to env variables in serverless init script + added traces_sample_rate (#1025)
* Added SENTRY_ prefix to serverless env variables and added traces sample rate env variable * Linting reformat
1 parent 25125b5 commit 3be779a

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

scripts/init_serverless_sdk.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
For manual instrumentation,
33
The Handler function string of an aws lambda function should be added as an
4-
environment variable with a key of 'INITIAL_HANDLER' along with the 'DSN'
4+
environment variable with a key of 'SENTRY_INITIAL_HANDLER' along with the 'DSN'
55
Then the Handler function sstring should be replaced with
66
'sentry_sdk.integrations.init_serverless_sdk.sentry_lambda_handler'
77
"""
@@ -17,19 +17,20 @@
1717

1818
# Configure Sentry SDK
1919
sentry_sdk.init(
20-
dsn=os.environ["DSN"],
20+
dsn=os.environ["SENTRY_DSN"],
2121
integrations=[AwsLambdaIntegration(timeout_warning=True)],
22+
traces_sample_rate=float(os.environ["SENTRY_TRACES_SAMPLE_RATE"])
2223
)
2324

2425

2526
def sentry_lambda_handler(event, context):
2627
# type: (Any, Any) -> None
2728
"""
2829
Handler function that invokes a lambda handler which path is defined in
29-
environment vairables as "INITIAL_HANDLER"
30+
environment vairables as "SENTRY_INITIAL_HANDLER"
3031
"""
3132
try:
32-
module_name, handler_name = os.environ["INITIAL_HANDLER"].rsplit(".", 1)
33+
module_name, handler_name = os.environ["SENTRY_INITIAL_HANDLER"].rsplit(".", 1)
3334
except ValueError:
3435
raise ValueError("Incorrect AWS Handler path (Not a path)")
3536
lambda_function = __import__(module_name)

tests/integrations/aws_lambda/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ def build_no_code_serverless_function_and_layer(
4545
Timeout=timeout,
4646
Environment={
4747
"Variables": {
48-
"INITIAL_HANDLER": "test_lambda.test_handler",
49-
"DSN": "https://[email protected]/123",
48+
"SENTRY_INITIAL_HANDLER": "test_lambda.test_handler",
49+
"SENTRY_DSN": "https://[email protected]/123",
50+
"SENTRY_TRACES_SAMPLE_RATE": "1.0",
5051
}
5152
},
5253
Role=os.environ["SENTRY_PYTHON_TEST_AWS_IAM_ROLE"],

0 commit comments

Comments
 (0)