expose generate_id function and make it configurable in RequestId#1294
Merged
josevalim merged 1 commit intoelixir-plug:mainfrom Jan 14, 2026
Merged
Conversation
whatyouhide
reviewed
Jan 7, 2026
lib/plug/request_id.ex
Outdated
|
|
||
| plug Plug.RequestId, logger_metadata_key: :my_request_id | ||
|
|
||
| * `:generate_request_id` - The function used to generate the request ID, defaults to Plug.RequestId.generate_request_id/0. |
Member
There was a problem hiding this comment.
Suggested change
| * `:generate_request_id` - The function used to generate the request ID, defaults to Plug.RequestId.generate_request_id/0. | |
| * `:generate_request_id` - The function used to generate the request ID, defaults to `generate_request_id/0`. |
lib/plug/request_id.ex
Outdated
|
|
||
| * `:generate_request_id` - The function used to generate the request ID, defaults to Plug.RequestId.generate_request_id/0. | ||
|
|
||
| plug Plug.RequestId, generate_request_id: fn -> "myapp-" <> Plug.RequestId.generate_request_id end |
Member
There was a problem hiding this comment.
Suggested change
| plug Plug.RequestId, generate_request_id: fn -> "myapp-" <> Plug.RequestId.generate_request_id end | |
| plug Plug.RequestId, generate_request_id: fn -> "myapp-" <> Plug.RequestId.generate_request_id() end | |
lib/plug/request_id.ex
Outdated
| Keyword.get(opts, :assign_as), | ||
| Keyword.get(opts, :logger_metadata_key, :request_id) | ||
| Keyword.get(opts, :logger_metadata_key, :request_id), | ||
| Keyword.get(opts, :generate_request_id, &generate_request_id/0) |
Member
There was a problem hiding this comment.
@josevalim since this is such a frequently-called thing, is it better to do
Suggested change
| Keyword.get(opts, :generate_request_id, &generate_request_id/0) | |
| Keyword.get(opts, :generate_request_id, &__MODULE__.generate_request_id/0) |
here?
| end | ||
|
|
||
| defp generate_request_id do | ||
| def generate_request_id do |
Member
There was a problem hiding this comment.
If we expose this we'll have to document it and spec it.
35eabd5 to
c103756
Compare
Contributor
Author
|
@whatyouhide Thanks for the review, I've amended the requested changes! |
Contributor
Author
|
Hey @josevalim and @whatyouhide are there still something you want me to address here? |
Member
|
WIll review and merge it tomorrow. |
Member
|
💚 💙 💜 💛 ❤️ |
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.
This PR supersedes #1293