stackable_telemetry::instrumentation::axum

Trait SpanExt

Source
pub trait SpanExt {
    // Required methods
    fn from_request(req: &Request, opt_in: bool) -> Self;
    fn add_header_fields(&self, headers: &HeaderMap);
    fn finalize_with_response(&self, response: &mut Response);
    fn finalize_with_error<E>(&self, error: &mut E)
       where E: Error;

    // Provided method
    fn finalize<E>(&self, result: &mut Result<Response, E>)
       where E: Error { ... }
}
Expand description

This trait provides various helper functions to create a [Span] out of an HTTP [Request].

Required Methods§

Source

fn from_request(req: &Request, opt_in: bool) -> Self

Create a span according to the semantic conventions for HTTP spans from an Axum [Request].

The individual fields are defined in this specification. Some of them are:

  • http.request.method
  • http.response.status_code
  • network.protocol.version

Setting the opt_in parameter to true enables various fields marked as opt-in by the specification. This will require more computing power and will increase the latency.

Source

fn add_header_fields(&self, headers: &HeaderMap)

Adds HTTP request headers to the span as a http.request.header.<key> field.

NOTE: This is currently not supported, because [tracing] doesn’t support recording dynamic fields.

Source

fn finalize_with_response(&self, response: &mut Response)

Finalize the [Span] with an Axum [Response].

Source

fn finalize_with_error<E>(&self, error: &mut E)
where E: Error,

Finalize the [Span] with an error.

Provided Methods§

Source

fn finalize<E>(&self, result: &mut Result<Response, E>)
where E: Error,

Finalize the [Span] with a result.

The default implementation internally calls:

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl SpanExt for Span

Source§

fn from_request(req: &Request, opt_in: bool) -> Self

Source§

fn add_header_fields(&self, headers: &HeaderMap)

Source§

fn finalize_with_response(&self, response: &mut Response)

Source§

fn finalize_with_error<E>(&self, error: &mut E)
where E: Error,

Implementors§