getsentry / sentry-python

The official Python SDK for Sentry.io
https://sentry.io/for/python/
MIT License
1.88k stars 494 forks source link

Raised exception not forwarded when debug not set to True (Python, AWS Lambda) #1371

Open nadasaiyed opened 2 years ago

nadasaiyed commented 2 years ago

How do you use Sentry?

Self-hosted/on-premise

Version

0.20.3

Steps to Reproduce

I am trying to forward raised exceptions from python code which runs in AWS Lambda but it only gets sent when debug is set to True. Are raised exceptions only supported when debug = True when initializing sentry?

logging_integration = LoggingIntegration(level=logging.INFO, event_level=logging.ERROR)
lambda_integration = AwsLambdaIntegration(timeout_warning=True)
sentry_sdk.init(  # pylint: disable=abstract-class-instantiated
            dsn=dsn,
            attach_stacktrace=True,
            integrations=[lambda_integration, logging_integration],
            traces_sample_rate=1.0,
        )
try:
        my_dict = {"a" : "test"}
        value = my_dict["b"] # This should raise exception
except:
        logging.exception("Key Does not Exists")
        raise

This raised exception does not get captured in Sentry. However, if i set debug = True for the same code, the exception gets forwarded to sentry. I don't want to set debug = True explicitly as it generated lots of loglines which isn't something i would want in prod

Expected Result

Raised exception should get forwarded to sentry even if debug is not set to True.

Actual Result

Raised exception not captured in Sentry for Python version 3.8 in running in AWS Lambda

antonpirker commented 2 years ago

Hey @nadasaiyed

Thanks for reporting this! I will try to reproduce this and will then get back to you!

sentrivana commented 11 months ago

@nadasaiyed Could you please try with a newer SDK version? We've recently released 1.33.0 which includes a number of improvements to our AWS Lambda integration.

hartleybrody commented 7 months ago

I'm having this same issue, using sentry SDK version 1.40.4 (can't go higher since I need python 3.7 support).

Errors are only reported to sentry if I call sentry_sdk.init(... debug=True). If I remove debug, then no errors are sent.

antonpirker commented 7 months ago

Hey @hartleybrody ! Are you also using the logging integration with the same settings as above are doing a logging.exception()? If now could you please post a minimal code example on how to reproduce this? Thanks!