Module aws_smithy_http_server::request::request_id
source · request-id
only.Expand description
§Request IDs
aws-smithy-http-server
provides the ServerRequestId
.
§ServerRequestId
A ServerRequestId
is an opaque random identifier generated by the server every time it receives a request.
It uniquely identifies the request within that service instance. It can be used to collate all logs, events and
data related to a single operation.
Use ServerRequestIdProviderLayer::new
to use ServerRequestId
in your handler.
The ServerRequestId
can be returned to the caller, who can in turn share the ServerRequestId
to help the service owner in troubleshooting issues related to their usage of the service.
Use ServerRequestIdProviderLayer::new_with_response_header
to use ServerRequestId
in your handler and add it to the response headers.
The ServerRequestId
is not meant to be propagated to downstream dependencies of the service. You should rely on a distributed tracing implementation for correlation purposes (e.g. OpenTelemetry).
§Examples
Your handler can now optionally take as input a ServerRequestId
.
pub async fn handler(
_input: Input,
server_request_id: ServerRequestId,
) -> Output {
/* Use server_request_id */
todo!()
}
let config = ServiceConfig::builder()
// Generate a server request ID and add it to the response header.
.layer(ServerRequestIdProviderLayer::new_with_response_header(HeaderName::from_static("x-request-id")))
.build();
let app = Service::builder(config)
.operation(handler)
.build().unwrap();
let bind: std::net::SocketAddr = format!("{}:{}", args.address, args.port)
.parse()
.expect("unable to parse the server bind address and port");
let server = hyper::Server::bind(&bind).serve(app.into_make_service());
Structs§
- The server request ID has not been added to the
Request
or has been previously removed. - Opaque type for Server Request IDs.
- A layer that provides services with a unique request ID instance