From ef33494672ee29cccd064d2c74e5063796ee062e Mon Sep 17 00:00:00 2001 From: Adam Sussman Date: Wed, 13 Jan 2021 21:03:22 -0800 Subject: [PATCH 1/2] fix detection of bootstrap when it lives under __main__ instead of being __main__ --- sentry_sdk/integrations/aws_lambda.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sentry_sdk/integrations/aws_lambda.py b/sentry_sdk/integrations/aws_lambda.py index 6cb42a9790..9502f47590 100644 --- a/sentry_sdk/integrations/aws_lambda.py +++ b/sentry_sdk/integrations/aws_lambda.py @@ -294,6 +294,8 @@ def get_lambda_bootstrap(): if "bootstrap" in sys.modules: return sys.modules["bootstrap"] elif "__main__" in sys.modules: + if hasattr(sys.modules["__main__"], "bootstrap"): + return sys.modules["__main__"].bootstrap # type: ignore return sys.modules["__main__"] else: return None From 3472e17e4f7abf735d290bdbc5856c61f56a6a02 Mon Sep 17 00:00:00 2001 From: Adam Sussman Date: Thu, 14 Jan 2021 15:23:27 -0800 Subject: [PATCH 2/2] add comment describing awslambdaric case of bootstrap discovery --- sentry_sdk/integrations/aws_lambda.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sentry_sdk/integrations/aws_lambda.py b/sentry_sdk/integrations/aws_lambda.py index 9502f47590..d4892121ba 100644 --- a/sentry_sdk/integrations/aws_lambda.py +++ b/sentry_sdk/integrations/aws_lambda.py @@ -290,11 +290,15 @@ def get_lambda_bootstrap(): # sys.modules['__main__'].__file__ == sys.modules['bootstrap'].__file__ # sys.modules['__main__'] is not sys.modules['bootstrap'] # + # On container builds using the `aws-lambda-python-runtime-interface-client` + # (awslamdaric) module, bootstrap is located in sys.modules['__main__'].bootstrap + # # Such a setup would then make all monkeypatches useless. if "bootstrap" in sys.modules: return sys.modules["bootstrap"] elif "__main__" in sys.modules: if hasattr(sys.modules["__main__"], "bootstrap"): + # awslambdaric python module in container builds return sys.modules["__main__"].bootstrap # type: ignore return sys.modules["__main__"] else: