elixir-plug / plug

Compose web applications with functions
https://hex.pm/packages/plug
Other
2.84k stars 582 forks source link

feat: make `Plug.RequestId.generate_request_id/0` a public function #1124

Closed bceskavich closed 1 year ago

bceskavich commented 1 year ago

We love Plug over at Knock!

Recently we've encountered a couple cases where we wish to generate an ad hoc request id outside of our Plug pipelines. To do so, we've copied logic in Plug.RequestId.generate_request_id/0 into a utility function in our own codebase. We think it would be quite useful to expose the function publicly via Plug itself.

Gazler commented 1 year ago

Thanks for the PR.

I think that if you require using this function, vendoring it into your own codebase is definitely the correct approach. Generating a request_id is internal to plug, and probably not something the plug team should be maintaining as a public API for generating unique id.

josevalim commented 1 year ago

The problem with making it public is that people can then start assuming it remains within a certain size or with a certain criteria, none of which we want to guarantee, so my suggestion is to copy and paste it around indeed. :) Thanks for the PR and the nice words! :heart:

bceskavich commented 1 year ago

Thanks @Gazler + @josevalim for the quick response and the reasoning, cheers!