Plug.RequestId

Plug.RequestId

A plug for generating a unique request id for each request. A generated request id will in the format “uq8hs30oafhj5vve8ji5pmp7mtopc08f”.

If a request id already exists as the “x-request-id” HTTP request header, then that value will be used assuming it is between 20 and 200 characters. If it is not, a new request id will be generated.

The request id is added to the Logger metadata as :request_id and the response as the “x-request-id” HTTP header. To see the request id in your log output, configure your logger backends to include the :request_id metadata:

config :logger, :console, metadata: [:request_id]

It is recommended to include this metadata configuration in your production configuration file.

To use it, just plug it into the desired module:

plug Plug.RequestId

Options

  • :http_header - The name of the HTTP request header to check for existing request ids. This is also the HTTP response header that will be set with the request id. Default value is “x-request-id”

    plug Plug.RequestId, http_header: “custom-request-id”

Summary

Functions

call(conn, req_id_header)

Callback implementation for Plug.call/2

init(opts)

Callback implementation for Plug.init/1

Functions

call(conn, req_id_header)

Callback implementation for Plug.call/2.

init(opts)

Callback implementation for Plug.init/1.

© 2013 Plataformatec
Licensed under the Apache License, Version 2.0.
https://hexdocs.pm/plug/Plug.RequestId.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部