fix: emit correlation_id; drain queue on close (#6, #9) - #14
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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