Created
October 15, 2020 16:18
-
-
Save mandarvaze/1acf9e133e2ecc94306c7d377623d25f to your computer and use it in GitHub Desktop.
Honeybadger integration with hug framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Code written to test integration of Honeybadger | |
with hug. | |
You need to : | |
pip install honeybadger | |
pip install hug | |
Have a trial/free account for Honeybadger | |
Set the Honeybadger API key as an environment variable | |
HONEYBADGER_API_KEY | |
Also set | |
export HONEYBADGER_FORCE_REPORT_DATA=True | |
else Exception may not be reported to Honeybadger | |
Read their documentation to know why | |
""" | |
import hug | |
import os | |
from honeybadger import Honeybadger | |
# Optional Honeybadger integration. It will kick in | |
# only if HONEYBADGER_API_KEY environment variable is set | |
API_KEY = os.environ.get('HONEYBADGER_API_KEY', None) | |
if API_KEY: | |
print("Setting up Honeybadger") | |
hb = Honeybadger() | |
hb.configure(api_key=API_KEY) | |
@hug.exception(Exception) | |
def handle_exception(exception): | |
hb.notify(exception) | |
raise exception | |
else: | |
print("Honeybadger not set, because not API_KEY was set.") | |
@hug.get('/happy_birthday') | |
def happy_birthday(name, age: hug.types.number = 1): | |
"""Says happy birthday to a user""" | |
return "Happy {age} Birthday {name}!".format(**locals()) | |
@hug.get('/exception') | |
def raise_exception(): | |
raise Exception("This will be reported") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment