Skip to content

Plug.RequestId: put the request_id in :private or :assigns? #1171

@halostatue

Description

@halostatue

This may not be possible because it might collide with existing private or assigns assignments, but trying to use the :request_id right now is a bit of a pain:

  def sentry_request_id(conn) do
    if request_id = Keyword.get(Logger.metadata(), :request_id) do
      Sentry.Context.set_request_context(%{request_id: request_id})
    end

    conn
  end

This would be much easier if Plug.RequestId also wrote the retrieved or generated request_id in either :private or :assigns (I know that:private is the correct place). It need not be called request_id (plug_request_id seems unlikely to have been used by anyone), but it could also be a configurable option.

plug Plug.RequestId, store_as: :request_id

If it were set up that way, the current behaviour would hold unless store_as (someone please give me a better name) and would do Conn.put_private(store_as_key, request_id or something similar.

I’d be happy to create a PR for this, but I wanted to gauge the temperature and get feedback before developing this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions