""" Basic usage example for the BitReport Python error reporter. Run with: ERROR_REPORTING_TOKEN=your_token python basic_usage.py """ import atexit import os from error_reporter import flush, init_reporter, report_error, report_message init_reporter( token=os.environ.get("ERROR_REPORTING_TOKEN", ""), project_name="My Python App", project_slug="my-python-app", ) # Flush before the process exits so queued events are not lost atexit.register(flush) # Report a plain message report_message("Application started", level="info") # Report a warning with extra context report_message("Cache miss", level="warning", context={"cache_key": "user:42"}) # Report an exception caught in a try/except try: result = 1 / 0 except ZeroDivisionError as e: report_error(e, {"operation": "divide", "numerator": 1, "denominator": 0}) # Flush immediately so the example does not exit before events are sent flush() print("Events sent. Check your errors.bitreport.pt dashboard.")