Stop persisting SDK traces from background tracker polling (or split PERSIST_SDK_TRACING) #1132
minchaminder
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem
On a production self-hosted deployment we traced recurring Postgres CPU alerts to the
tracing-recordtable growing without bound. Root cause: background tracker polling persists full SDK traces on every carrier API call, separate from user-initiated API request tracing.Two write paths exist today:
save_tracing_records(context, tracer)request_log_id,carrier_*, optionalobject_idrequest_log_id)bulk_save_tracing_records(gateway.tracer, context)via_save_tracing()/save_tracing_records(request_batches)connectiononlyIn our prod DB (~5.3M tracing rows, ~11 GB table):
meta ? 'connection'and norequest_log_id)meta ? 'request_log_id')meta.object_idis never populated on tracker traces, so debugging falls back torecord::text ILIKE→ full table scans on multi-million-row tablesSteady-state insert rate from tracker polling alone: ~50k rows/day (1,300 undelivered trackers × ~2h poll interval × request/response/error keys). Catch-up after worker restarts can spike to ~100k rows/hour.
Upstream
tracking.pystill calls_save_tracing()after each batch (seeprocess_carrier_trackers→_process_batch).Why the current global flag is not enough
PERSIST_SDK_TRACINGgates both paths. Turning it off fixes DB pressure but also disables useful API-side traces for shipment/rate/label debugging.Docs even suggest
PERSIST_SDK_TRACING=falsein production for performance — but that throws away the traces operators actually need.Proposal
Pick one (or combine):
PERSIST_TRACKER_TRACING(defaultfalse) — new setting; background Huey tracker job skipsbulk_save_tracing_recordswhile API middleware keeps tracing.tracker_idtoday anyway.meta.object_id/tracker_idon every batch rowerrortraces for known-broken carrier pollsWorkaround today
PERSIST_SDK_TRACING=falseon worker container only (API container keeps tracing)_save_tracing()/save_tracing_records(request_batches)in a forkQuestions for maintainers
bulk_save_tracing_recordswas added?PERSIST_TRACKER_TRACINGflag (default off) be acceptable upstream?delivered=falseand poll count exceeds N?Happy to open a PR if there is agreement on direction. We have a detailed RCA from prod data if useful.
Code refs (upstream):
modules/events/karrio/server/events/task_definitions/base/tracking.py—_save_tracing()modules/core/karrio/server/tracing/utils.py—bulk_save_tracing_records,PERSIST_SDK_TRACINGguardAll reactions