Repository navigation
fix: read the request id baggage key at runtime - #2616
Open
Indian-boult wants to merge 2 commits into
Open
Indian-boult wants to merge 2 commits into
Indian-boult wants to merge 2 commits into
Conversation
REQUEST_ID_BAGGAGE_KEY is read by config/runtime.exs at boot, but the endpoint passed the result of BaggageRequestId.baggage_key/0 as a plug option. Plug.Builder evaluates plug options when the module compiles, so a release always used the request-id baggage entry and ignored the variable. The endpoint now calls BaggageRequestId from a function plug that looks up the key on each request.
edgurgel
reviewed
Nov 18, 2026
Comment on lines
+42
to
+45
| previous = Application.get_env(:realtime, :request_id_baggage_key) | ||
| Application.put_env(:realtime, :request_id_baggage_key, "runtime-request-id") | ||
| on_exit(fn -> Application.put_env(:realtime, :request_id_baggage_key, previous) end) | ||
|
|
Member
There was a problem hiding this comment.
Because of this we need the test to be async: false
The baggage key test changes an application env value, and an async test in another module could read that value while it is set.
This branch has not been deployed
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.
Why
REQUEST_ID_BAGGAGE_KEYhas no effect.config/runtime.exsreads it at boot, but the endpoint passedBaggageRequestId.baggage_key()as aplugoption, andPlug.Builderevaluates plug options when the module compiles. A release built from theDockerfilecompiles with onlyconfig/config.exsandconfig/prod.exs, so the endpoint always reads therequest-idbaggage entry.What changed
BaggageRequestIdfrom a function plug that looks up the key on each request.endpoint_test.exssetsrequest_id_baggage_keythe wayconfig/runtime.exsdoes at boot and sends a request with that baggage entry through the endpoint.Scope
BaggageRequestIdand its tests are unchanged, and so is the default keyrequest-id. A request without a matching baggage entry still gets an id fromPlug.RequestId.Verification
x-request-idcomes back as a generated id instead of1234567890. It passes with the fix.endpoint_test.exs, the tests undertest/realtime_web/plugs,tracing_test.exsandpage_controller_test.exspass, 68 tests with one excluded by its:failingtag. The tests undertest/realtime_web/controllerspass, 191 tests.mix compile --force --warnings-as-errorspasses, andmix format --check-formattedandmix credo --strictpass on the changed files. I did not run Dialyzer or the full suite.Fixes #2615