# Do LLM traces survive a container stop? SIGTERM vs normal exit (4 Nov 2026, IST)

A short Python script makes one OpenAI chat call through each tool's auto-instrumentation, then either exits normally or receives SIGTERM (what `docker stop`, Kubernetes and most process managers send) about 1 second later. Spans go to a local OTLP/HTTP sink (`sink.py`, logs every request it receives). The "model" is a local OpenAI-compatible stand-in (`fake_openai.py`). No vendor account, dummy keys, no spend.
Box: Linux, Python 3.13 venvs (uv). Run on the morning of 4 Nov 2026 (last run 11:33 IST). 3 runs per tool and mode, plus 1 run of the handler fix.

Versions: traceloop-sdk 0.62.4 (OpenLLMetry), arize-phoenix-otel 0.17.2 + openinference-instrumentation-openai 0.1.69, openlit 1.45.0, langfuse 5.1.0, opentelemetry-sdk 1.45.2, openai 3.45.0 (openlit venv: 2.54.0).

Setup (`app.py`):
- OpenLLMetry: `Traceloop.init(app_name=..., api_endpoint=<sink>, telemetry_enabled=False)`; explicit flush `TracerWrapper().flush()`
- Phoenix: `phoenix.otel.register(endpoint=<sink>/v1/traces, auto_instrument=True)`
- OpenLIT: `openlit.init(otlp_endpoint=<sink>)`
- Langfuse: `from langfuse.openai import OpenAI`, host = sink; explicit flush `get_client().flush()`

Modes: `exit` = script ends normally; `sigterm` = SIGTERM ~1 s after the call returned; `flush` = explicit flush, then SIGTERM; `handler` = `signal.signal(signal.SIGTERM, lambda s, f: sys.exit(0))` installed, then SIGTERM.

## Results: spans received by the sink (summary.txt, raw/)

| Tool | normal exit | SIGTERM | flush, then SIGTERM | SIGTERM handler |
|---|---|---|---|---|
| OpenLLMetry (traceloop-sdk 0.62.4) | 1, 1, 1 | 0, 0, 0 | 1, 1, 1 | 1 |
| Arize Phoenix (phoenix.otel 0.17.2) | 1, 1, 1 | 1, 1, 1 | 1, 1, 1 | 1 |
| OpenLIT 1.45.0 | 2, 2, 2 | 0, 0, 0 | 2, 2, 2 | 2 |
| Langfuse 5.1.0 | 1, 1, 1 | 0, 0, 0 | 1, 1, 1 | 1 |

Exit code was 0 on normal exit and with the handler, 143 on plain SIGTERM. OpenLIT also posts /v1/metrics and /v1/logs.

Why: OpenTelemetry's BatchSpanProcessor holds spans in memory and exports them on a timer or at shutdown, and the shutdown hook runs from Python's `atexit`. Python's default SIGTERM action kills the process without running `atexit`, so the batch is lost. `phoenix.otel.register()` defaults to `batch=False` (a SimpleSpanProcessor that exports each span as it ends), which is why Phoenix kept its span; that costs a blocking export per span.

Fix that worked for all four: install a SIGTERM handler that calls `sys.exit(0)` (so `atexit` and the SDK's shutdown run), or call the SDK's flush before the process ends.

## Caveats
- One short call per run; the sink accepts everything instantly. A slow or unreachable backend changes timing.
- We waited ~1 s before SIGTERM; with a long-running server, spans older than the batch delay (OpenTelemetry default 5 s) will usually have been exported already. The loss hits the last few seconds before a stop, and short jobs (CLI, cron, serverless) most.
- Behaviour is for these versions and defaults.

Files: `app.py`, `sink.py`, `fake_openai.py`, `run.sh`, `summary.txt`, `raw/` (per-run stdout/stderr and sink logs).
