Zero-dependency clients for errors.bitreport.pt following the same patterns as clients/node and clients/php: batch size 25, 5 s flush interval, 8 s HTTP timeout, fire-and-forget, env-var config. Each client ships with unit tests backed by an embedded HTTP server (no mocks), an example file, and a build manifest (pyproject.toml, go.mod, pom.xml). Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
37 lines
993 B
Python
37 lines
993 B
Python
"""
|
|
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.")
|