Output Modes

Choose between console, file (JSONL), and HTTP delivery sinks.

TraceKit supports one output sink per tracekit.init() call, selected by the output string.

What it does

  • "console" (default): Formats one human-readable line per event and writes it to stderr (with ANSI colors when attached to a terminal).
  • "file:<path>": Appends one JSON object per line (JSONL) to <path>. Opens and closes the file on every write so multiple processes can share it safely.
  • "http://..." or "https://...": Batches up to 20 events (or flushes every 2 seconds on the next event) and sends a POST request with JSON data. Failed requests retry up to 3 times with exponential backoff (0.5s, 1.0s), then drop silently.

Minimal example

outputs.py
import tracekit
# 1. Console (default)tracekit.init(output="console")tracekit.capture_message("Written to stderr")
# 2. File (JSONL)tracekit.init(output="file:events.jsonl")tracekit.capture_message("Appended to events.jsonl")
# 3. HTTP (local viewer or custom ingest endpoint)tracekit.init(output="http://127.0.0.1:8765/ingest")tracekit.capture_message("Queued for HTTP POST")tracekit.flush()

Expected output

For "console":

output
[TraceKit 2026-11-28 09:56:01] INFO    Written to stderr

For "file:events.jsonl":

events.jsonl
{"event_id": "...", "type": "message", "timestamp": "2026-11-28T09:56:01.123Z", "level": "info", "environment": "production", "sdk": {"name": "tracekit", "version": "0.1.0"}, "runtime": {"python": "3.14.7", "platform": "Darwin"}, "message": "Appended to events.jsonl"}

Unknown output strings

If you pass an unrecognized output string (such as "redis://..."), TraceKit safely falls back to ConsoleSink instead of crashing your app.

Common mistakes

  • Using "file:" without a path: Passing "file:" with an empty path falls back to ConsoleSink. Always include a filename like "file:events.jsonl".
  • Expecting HTTP events to send immediately for 1 event: HttpSink batches up to 20 events or waits until 2 seconds have passed when the next event arrives.