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

  • ERROR and CRITICAL with exc_info: Captured via capture_exception().
  • ERROR and CRITICAL without exc_info: Captured via capture_message(..., level="error").
  • WARNING, INFO, and DEBUG: Added as breadcrumbs via add_breadcrumb() with category set to the logger name and level set 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 exception

Notice 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 to WARNING, so INFO breadcrumbs won't reach TraceKitHandler unless you lower the logger level.
  • Attaching TraceKitHandler before init(): That is safe (it becomes a no-op until init() is called), but events logged before init() are skipped.