Skip to content

fix: read the request id baggage key at runtime - #2616

Open
Indian-boult wants to merge 2 commits into
supabase:mainfrom
Indian-boult:fix/request-id-baggage-key-at-runtime
Open

Indian-boult wants to merge 2 commits into
supabase:mainfrom
Indian-boult:fix/request-id-baggage-key-at-runtime

Conversation

@Indian-boult

Copy link
Copy Markdown

Why

REQUEST_ID_BAGGAGE_KEY has no effect. config/runtime.exs reads it at boot, but the endpoint passed BaggageRequestId.baggage_key() as a plug option, and Plug.Builder evaluates plug options when the module compiles. A release built from the Dockerfile compiles with only config/config.exs and config/prod.exs, so the endpoint always reads the request-id baggage entry.

What changed

  • The endpoint calls BaggageRequestId from a function plug that looks up the key on each request.
  • A test in endpoint_test.exs sets request_id_baggage_key the way config/runtime.exs does at boot and sends a request with that baggage entry through the endpoint.

Scope

BaggageRequestId and its tests are unchanged, and so is the default key request-id. A request without a matching baggage entry still gets an id from Plug.RequestId.

Verification

  • The new test fails on main because x-request-id comes back as a generated id instead of 1234567890. It passes with the fix.
  • With the fix, endpoint_test.exs, the tests under test/realtime_web/plugs, tracing_test.exs and page_controller_test.exs pass, 68 tests with one excluded by its :failing tag. The tests under test/realtime_web/controllers pass, 191 tests.
  • On Elixir 1.19.5 and OTP 28.5, mix compile --force --warnings-as-errors passes, and mix format --check-formatted and mix credo --strict pass on the changed files. I did not run Dialyzer or the full suite.

Fixes #2615

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.
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

No deployments
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.

REQUEST_ID_BAGGAGE_KEY has no effect because the endpoint reads the key at compile time

2 participants