honeybadger-io / honeybadger-python

Send Python and Django errors to Honeybadger.
https://www.honeybadger.io/
MIT License
15 stars 26 forks source link

AWS Lambda/Chalice: Honeybadger API key missing from configuration: cannot report errors. #99

Closed bradsgreen closed 2 years ago

bradsgreen commented 3 years ago

(venv) xxx % python --version Python 3.8.2

hb_handler = HoneybadgerHandler(api_key='--my api key--') hb_handler.setLevel(logging.ERROR) app.log.addHandler(hb_handler)

@app.lambda_function() def honeybadger_error_test(event, context): app.log.error('Something went wrong!!!') app.log.info('But this is OK!') raise AssertionError("BOOM!")

results in "Something went wrong!!!" being reportied to HB but 'BOOM!' is not. Data attached. LMK if you'd prefer to reopen the old issue or I can create a new one.

Screen Shot 2021-09-14 at 1 54 32 PM

CloudWatch logs indicate something odd:

[ERROR] 2021-09-13T22:16:55.509Z 133de542-7f45-4168-88a2-8924ad6fbbe2 Honeybadger API key missing from configuration: cannot report errors.

Full log:

2021-09-13T22:16:55.438Z    START RequestId: 133de542-7f45-4168-88a2-8924ad6fbbe2 Version: $LATEST

2021-09-13T22:16:55.439Z    kds - ERROR - Something went wrong!!!

2021-09-13T22:16:55.509Z    kds - INFO - But this is OK!

2021-09-13T22:16:55.510Z    [ERROR] 2021-09-13T22:16:55.509Z 133de542-7f45-4168-88a2-8924ad6fbbe2 Honeybadger API key missing from configuration: cannot report errors.

2021-09-13T22:16:55.510Z    [ERROR] AssertionError: BOOM! Traceback (most recent call last):   File "/opt/python/lib/python3.8/site-packages/honeybadger/contrib/aws_lambda.py", line 76, in wrapped_handler     reraise(*exc_info)   File "/opt/python/lib/python3.8/site-packages/honeybadger/contrib/aws_lambda.py", line 45, in reraise     raise value   File "/opt/python/lib/python3.8/site-packages/honeybadger/contrib/aws_lambda.py", line 68, in wrapped_handler     return handler(aws_event, aws_context, *args, **kwargs)   File "/var/task/chalice/app.py", line 1564, in __call__     return self.handler(event_obj)   File "/var/task/chalice/app.py", line 1517, in __call__     return self._original_func(event.to_dict(), event.context)   File "/var/task/app.py", line 25, in honeybadger_error_test     raise AssertionError("BOOM!")

2021-09-13T22:16:55.513Z    END RequestId: 133de542-7f45-4168-88a2-8924ad6fbbe2

Front logo Front conversations

bradsgreen commented 3 years ago

NOT A BUG!!!!

from honeybadger import honeybadger
honeybadger.configure(api_key='hbp_copoB504geiDXuwKF1rOwZimtN9APN3lqnKE')

# Install a honeybadger handler to report 'error' logs to HB
from honeybadger.contrib import HoneybadgerHandler

hb_handler = HoneybadgerHandler(api_key='hbp_copoB504geiDXuwKF1rOwZimtN9APN3lqnKE')
hb_handler.setLevel(logging.ERROR)
app.log.addHandler(hb_handler)

works -- you have to configure honeybadger to get the wrapping, creating the log handler doesn't do it for you. You might want to consider clarifying this in the documentation. but this is not a bug and can be closed.

Thanks!