Skip to content

Commit a0b8ffc

Browse files
add test
1 parent 2ff1ba2 commit a0b8ffc

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Need to add some ignore rules in this directory, because the unit tests will add the Sentry SDK and its dependencies
2+
# into this directory to create a Lambda function package that contains everything needed to instrument a Lambda function using Sentry.
3+
4+
# Ignore everything
5+
*
6+
7+
# But not index.py
8+
!index.py
9+
10+
# And not .gitignore itself
11+
!.gitignore
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import os
2+
import time
3+
4+
import sentry_sdk
5+
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration
6+
7+
sentry_sdk.init(
8+
dsn=os.environ.get("SENTRY_DSN"),
9+
traces_sample_rate=1.0,
10+
integrations=[AwsLambdaIntegration(timeout_warning=True)],
11+
)
12+
13+
14+
def handler(event, context):
15+
sentry_sdk.set_tag("custom_tag", "custom_value")
16+
time.sleep(15)
17+
return {
18+
"event": event,
19+
}

tests/integrations/aws_lambda/test_aws_lambda.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,31 @@ def test_timeout_error(lambda_client, test_environment):
223223
assert exception["mechanism"]["type"] == "threading"
224224

225225

226+
def test_timeout_error_scope_modified(lambda_client, test_environment):
227+
lambda_client.invoke(
228+
FunctionName="TimeoutErrorScopeModified",
229+
Payload=json.dumps({}),
230+
)
231+
envelopes = test_environment["server"].envelopes
232+
233+
(error_event,) = envelopes
234+
235+
assert error_event["level"] == "error"
236+
assert (
237+
error_event["extra"]["lambda"]["function_name"] == "TimeoutErrorScopeModified"
238+
)
239+
240+
(exception,) = error_event["exception"]["values"]
241+
assert not exception["mechanism"]["handled"]
242+
assert exception["type"] == "ServerlessTimeoutWarning"
243+
assert exception["value"].startswith(
244+
"WARNING : Function is expected to get timed out. Configured timeout duration ="
245+
)
246+
assert exception["mechanism"]["type"] == "threading"
247+
248+
assert error_event["tags"]["custom_tag"] == "custom_value"
249+
250+
226251
@pytest.mark.parametrize(
227252
"aws_event, has_request_data, batch_size",
228253
[

0 commit comments

Comments
 (0)