Skip to content

fix: emit correlation_id; drain queue on close (#6, #9) - #14

Merged
nyorf merged 1 commit into
masterfrom
fix/correlation-id-and-close-drain
Jun 14, 2026
Merged

fix: emit correlation_id; drain queue on close (#6, #9)#14
nyorf merged 1 commit into
masterfrom
fix/correlation-id-and-close-drain

Conversation

@nyorf

@nyorf nyorf commented Jun 14, 2026

Copy link
Copy Markdown
Member

Two log-integrity fixes surfaced by the test suite.

#9 — upstream request id was captured but never logged. TraceMiddleware stores the inbound X-Request-Id in a contextvar, but the formatter never emitted it, so logs couldn't be correlated to the caller. `_JsonFormatter` now injects it under the index's canonical `correlation_id` field (confirmed against the live wisepay-ym-api mapping). An explicit app-set `correlation_id` (via `extra=`) still wins.

#6 — close() could drop queued records. It flushed a single batch_size chunk; a burst queued right before shutdown was lost. close() now drains the full queue (terminates even if OpenSearch is unreachable, since _flush() always consumes what it pulls — to stderr on error).

Tests: the former strict-xfail for #9 is now a passing test, plus app-precedence / absence cases and a close-drains-everything case. 41 passed, ruff clean, 98% coverage.

Closes #6
Closes #9

@nyorf
nyorf merged commit f77ff2e into master Jun 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upstream X-Request-Id is captured but never emitted to log records OpenSearchHandler.close() can drop queued log records on shutdown

1 participant