make_request_spanner

Macro make_request_spanner 

Source
macro_rules! make_request_spanner {
    ($fn:ident($name:literal, $level:expr)) => { ... };
    ($fn:ident($name:literal, $level:expr, $($fields:tt)*)) => { ... };
}
Expand description

Declares fn function compatible with MakeSpan using provided parameters

§Span fields

Following fields are declared when span is created:

  • http.request.method
  • url.path
  • url.query
  • url.scheme
  • http.request_id - Inherited from request ‘X-Request-Id’ or random uuid
  • user_agent.original - Only populated if user agent header is present
  • http.headers - Optional. Populated if more than 1 header specified via layer config
  • network.protocol.name - Either http or grpc depending on content-type
  • network.protocol.version - Set to HTTP version in case of plain http protocol.
  • client.address - Optionally added if IP extractor is specified via layer config
  • http.response.status_code - Semantics of this code depends on protocol
  • error.type - Populated with core::any::type_name value of error type used by the service.
  • error.message - Populated with Display content of the error, returned by underlying service, after processing request.

Loosely follows https://opentelemetry.io/docs/specs/semconv/http/http-spans/#http-server

§Additional fields

Additional fields can be declared by passing extra arguments after level in the same way as you would pass it to tracing::span! macro

Note that you need to use tracing::field::Empty if you want to add value later

§Usage

use tower_http_tracing::make_request_spanner;

make_request_spanner!(make_my_request_span("my_request", tracing::Level::INFO));
make_request_spanner!(make_my_service_request_span("my_request", tracing::Level::INFO, service_name = "<your name>"));

let span = make_my_request_span();
span.record("url.path", "I can override span field");