Package: humbug
Humbug PythonThe Humbug Python library.InstallationUsing pippipinstallhumbugFrom sourceClone this repository and enter this directory. Make sure you are in your desired Python environment
and then run:pythonsetup.pyinstallIntegrationTo add Humbug to your project, first create a Bugout access token and journalfollowing these
instructions.You can follow the recipes below to integrate Humbug into your codebase:Error reportingSystem reportingAll reports are generated (and published) by a Humbug reporter. By default, Humbug publishes all
reports asynchronously and in the background. If you would like to publish selected reports
synchronously, all reporter methods take await=Trueargument.If you plan toonlyuse a reporter synchronously or to do your own thread management, you can
instantiate the reporter in synchronous mode:fromhumbug.reportimportReporter,Modesreporter=Reporter("<name>",client_id="<client_id>",session_id="<session_id>",bugout_token="<bugout_token>",bugout_journal_id="<bugout_journal_id>",mode=Modes.SYNCHRONOUS,)Using Modes.SYNCHRONOUS in this manner skips the creation of the thread from which the reporter
publishes reports.ConsentHumbug cares deeply about consent. The innocuousHumbugConsentfrom the snippet above supports
a wide range of consent flows.Opting in with environment variablesFor example, if you would like your users to be able to opt in by setting an environment variableMY_APP_CONSENT=true:fromhumbug.consentimportenvironment_variable_opt_in,HumbugConsentfromhumbug.reportimportReporterconsent=HumbugConsent(environment_variable_opt_in("MY_APP_CONSENT",["true"]))reporter=Reporter("<name of your project>",consent,bugout_token="<your Bugout token>",bugout_journal_id="<your Bugout journal ID>",)If you use this configuration, unless your user uses your tool withMY_APP_CONSENT=true, no
reports will ever get sent to your knowledge base.Opting out with environment variablesIf,likehomebrew, you would like users to be able to
opt out by setting an environment variableMY_APP_NO_CONSENT=1:fromhumbug.consentimportenvironment_variable_opt_out,HumbugConsentfromhumbug.reportimportReporterconsent=HumbugConsent(environment_variable_opt_out("MY_APP_NO_CONSENT",["1"]))reporter=Reporter("<name of your project>",consent,bugout_token="<your Bugout access token>",bugout_journal_id="<your Bugout journal ID>",)In this case, reports are sent by default unless the user setsMY_APP_NO_CONSENT=1in which
case reports will never be sent.Composing consent mechanismsHumbug allows you to combine multiple consent mechanisms. For example:fromhumbug.consentimportenvironment_variable_opt_in,environment_variable_opt_out,HumbugConsentfromhumbug.reportimportReporterconsent=HumbugConsent(environment_variable_opt_in("MY_APP_CONSENT",["true"]),environment_variable_opt_out("MY_APP_NO_CONSENT",["1"]),)reporter=Reporter("<name of your project>",consent,bugout_token="<your Bugout access token>",bugout_journal_id="<your Bugout journal ID>",)If your users do not setMY_APP_CONSENTor give it a value other thantrue, Humbug won't even
bother to send you any reports. IfMY_APP_CONSENTis indeed set totrue, but the user has
setMY_APP_NO_CONSENT=1, then again no reports will get sent back.On the other hand, if the user has setMY_APP_CONSENT=trueand leftMY_APP_NO_CONSENTunset or
set to a value other than1, Humbug will send you any reports you have configured.Blacklisting parameters in feature reportsArguments to functions and other callables can sometimes contain sensitive information which you may
not want to include in Humbug reports.Blacklist functions allow you to specify which parameters from an argument list to filter out of your
feature reports.blacklist.generate_filter_parameters_by_key_fnIf you would just like to filter out all paramters with a given name, you can use theblacklist.generate_filter_parameters_by_key_fn.For example, to ignore all parameters namedtoken(case insensitive), you would instantiate yourHumbugReporteras follows:reporter=HumbugReporter(...,blacklist_fn=blacklist.generate_filter_parameters_by_key_fn(["token"]),)Custom blacklist functionsYou could also implement a custom blacklist function to remove all parameters that contained the substringtoken(case insensitive):defblacklist_token_parameters_fn(params:Dict[str,Any])->Dict[str,Any]:admissible_params={k:vfork,vinparams.items()if"token"notink}returnadmissible_paramsreporter=HumbugReporter(...,blacklist_fn=blacklist_token_parameters_fn)Case study: activeloopai/deeplakeThis pull requestshows howActiveloopintegrated Humbug into their populardeeplaketool.This example shows how to use Humbug to record consent in a configuration file that the user
can modify at will. It also shows how to add custom tags to your Humbug reports.