Append a completed record to the local buffer.
(record: TelemetryRecord)
| 229 | |
| 230 | |
| 231 | def buffer_record(record: TelemetryRecord) -> None: |
| 232 | """Append a completed record to the local buffer.""" |
| 233 | if not is_enabled(): |
| 234 | return |
| 235 | try: |
| 236 | buf = _buffer_path() |
| 237 | buf.parent.mkdir(parents=True, exist_ok=True) |
| 238 | with open(buf, "a", encoding="utf-8") as f: |
| 239 | f.write(json.dumps(record.to_dict(), ensure_ascii=False) + "\n") |
| 240 | |
| 241 | # NO auto-flush here — flush only on explicit command or shutdown |
| 242 | # This keeps telemetry off the hot routing path (no blocking network calls) |
| 243 | except Exception as e: |
| 244 | logger.debug("Telemetry buffer failed: %s", e) |
| 245 | |
| 246 | |
| 247 | def flush() -> int: |
nothing calls this directly
no test coverage detected