Logging Integration
Route Python's standard logging module into TraceKit events and breadcrumbs.
TraceKit provides TraceKitHandler, a subclass of Python's logging.Handler.
What it does
ERRORandCRITICALwithexc_info: Captured viacapture_exception().ERRORandCRITICALwithoutexc_info: Captured viacapture_message(..., level="error").WARNING,INFO, andDEBUG: Added as breadcrumbs viaadd_breadcrumb()withcategoryset to the logger name andlevelset to the log level.
Minimal example
log_demo.py
import loggingimport tracekitfrom tracekit.integrations.logging import TraceKitHandler
tracekit.init(output="console", environment="production")
handler = TraceKitHandler()logging.getLogger().addHandler(handler)logging.getLogger().setLevel(logging.INFO)
logger = logging.getLogger("checkout")logger.info("Starting payment step")logger.warning("Gateway latency high")logger.error("Payment failed without exception")
tracekit.flush()Expected output
output
[TraceKit 2026-11-28 09:56:01] ERROR Payment failed without exceptionNotice that INFO and WARNING logs did not print on their own — they were stored as breadcrumbs on the current context and will appear on the ERROR event (visible in file: or http:// outputs).
Common mistakes
- Forgetting
logger.setLevel(logging.INFO): Python's root logger defaults toWARNING, soINFObreadcrumbs won't reachTraceKitHandlerunless you lower the logger level. - Attaching
TraceKitHandlerbeforeinit(): That is safe (it becomes a no-op untilinit()is called), but events logged beforeinit()are skipped.