Skip to content

Decorator on lambda handler causes flaky crash #839

@fafrd

Description

@fafrd

I'm trying to use Sentry alongside Serverless and having a pretty bad time. Getting flaky failures when calling sentry_sdk.init:

[ERROR] KeyError: 'sentry_sdk.integrations.asgi'
Traceback (most recent call last):
  File "/opt/python/serverless_aws_lambda_sdk/instrument/__init__.py", line 590, in stub
    return self._handler(user_handler, event, context)
  File "/opt/python/serverless_aws_lambda_sdk/instrument/__init__.py", line 572, in _handler
    result = user_handler(event, context)
  File "/var/task/serverless_sdk/__init__.py", line 144, in wrapped_handler
    return user_handler(event, context)
  File "/var/task/lib/services/utils.py", line 22, in wrapper
    sentry_sdk.init(
  File "/var/task/sentry_sdk/hub.py", line 132, in _init
    client = Client(*args, **kwargs)  # type: ignore
  File "/var/task/sentry_sdk/client.py", line 143, in __init__
    self._init_impl()
  File "/var/task/sentry_sdk/client.py", line 223, in _init_impl
    self.integrations = setup_integrations(
  File "/var/task/sentry_sdk/integrations/__init__.py", line 110, in setup_integrations
    for integration_cls in iter_default_integrations(
  File "/var/task/sentry_sdk/integrations/__init__.py", line 41, in iter_default_integrations
    yield getattr(import_module(module), cls)
  File "/var/lang/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/var/task/sentry_sdk/integrations/starlette.py", line 16, in <module>
    from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 682, in _load_unlocked

Multiple different components of the library seem to cause this:

[ERROR] KeyError: 'sentry_sdk._werkzeug'
Traceback (most recent call last):
  File "/opt/python/serverless_aws_lambda_sdk/instrument/__init__.py", line 590, in stub
    return self._handler(user_handler, event, context)
[ERROR] ImportError: cannot import name 'SentryWsgiMiddleware' from 'sentry_sdk.integrations.wsgi' (/var/task/sentry_sdk/integrations/wsgi.py)
Traceback (most recent call last):
  File "/opt/python/serverless_aws_lambda_sdk/instrument/__init__.py", line 590, in stub
    return self._handler(user_handler, event, context)

point of failure is here: https://github.com/serverless/console/blob/main/python/packages/aws-lambda-sdk/serverless_aws_lambda_sdk/instrument/__init__.py#L590

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions