pub struct Info<'a> { /* private fields */ }
Expand description
Information about the request/response that can be used to prepare log lines.
Implementations
sourceimpl<'a> Info<'a>
impl<'a> Info<'a>
sourcepub fn remote_addr(&self) -> Option<SocketAddr>
pub fn remote_addr(&self) -> Option<SocketAddr>
View the remote SocketAddr
of the request.
Examples found in repository?
src/filters/trace.rs (line 55)
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
pub fn request() -> Trace<impl Fn(Info) -> Span + Clone> {
use tracing::field::{display, Empty};
trace(|info: Info| {
let span = tracing::info_span!(
"request",
remote.addr = Empty,
method = %info.method(),
path = %info.path(),
version = ?info.route.version(),
referer = Empty,
);
// Record optional fields.
if let Some(remote_addr) = info.remote_addr() {
span.record("remote.addr", &display(remote_addr));
}
if let Some(referer) = info.referer() {
span.record("referer", &display(referer));
}
tracing::debug!(parent: &span, "received request");
span
})
}
sourcepub fn method(&self) -> &Method
pub fn method(&self) -> &Method
View the http::Method
of the request.
Examples found in repository?
src/filters/trace.rs (line 48)
≺ ≻
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
pub fn request() -> Trace<impl Fn(Info) -> Span + Clone> {
use tracing::field::{display, Empty};
trace(|info: Info| {
let span = tracing::info_span!(
"request",
remote.addr = Empty,
method = %info.method(),
path = %info.path(),
version = ?info.route.version(),
referer = Empty,
);
// Record optional fields.
if let Some(remote_addr) = info.remote_addr() {
span.record("remote.addr", &display(remote_addr));
}
if let Some(referer) = info.referer() {
span.record("referer", &display(referer));
}
tracing::debug!(parent: &span, "received request");
span
})
}
sourcepub fn path(&self) -> &str
pub fn path(&self) -> &str
View the URI path of the request.
Examples found in repository?
src/filters/trace.rs (line 49)
≺ ≻
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
pub fn request() -> Trace<impl Fn(Info) -> Span + Clone> {
use tracing::field::{display, Empty};
trace(|info: Info| {
let span = tracing::info_span!(
"request",
remote.addr = Empty,
method = %info.method(),
path = %info.path(),
version = ?info.route.version(),
referer = Empty,
);
// Record optional fields.
if let Some(remote_addr) = info.remote_addr() {
span.record("remote.addr", &display(remote_addr));
}
if let Some(referer) = info.referer() {
span.record("referer", &display(referer));
}
tracing::debug!(parent: &span, "received request");
span
})
}
More examples
examples/tracing.rs (line 49)
≺ ≻
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
async fn main() {
// Filter traces based on the RUST_LOG env var, or, if it's not set,
// default to show the output of the example.
let filter = std::env::var("RUST_LOG").unwrap_or_else(|_| "tracing=info,warp=debug".to_owned());
// Configure the default `tracing` subscriber.
// The `fmt` subscriber from the `tracing-subscriber` crate logs `tracing`
// events to stdout. Other subscribers are available for integrating with
// distributed tracing systems such as OpenTelemetry.
tracing_subscriber::fmt()
// Use the filter we built above to determine which traces to record.
.with_env_filter(filter)
// Record an event when each span closes. This can be used to time our
// routes' durations!
.with_span_events(FmtSpan::CLOSE)
.init();
let hello = warp::path("hello")
.and(warp::get())
// When the `hello` route is called, emit a `tracing` event.
.map(|| {
tracing::info!("saying hello...");
"Hello, World!"
})
// Wrap the route in a `tracing` span to add the route's name as context
// to any events that occur inside it.
.with(warp::trace::named("hello"));
let goodbye = warp::path("goodbye")
.and(warp::get())
.map(|| {
tracing::info!("saying goodbye...");
"So long and thanks for all the fish!"
})
// We can also provide our own custom `tracing` spans to wrap a route.
.with(warp::trace(|info| {
// Construct our own custom span for this route.
tracing::info_span!("goodbye", req.path = ?info.path())
}));
let routes = hello
.or(goodbye)
// Wrap all the routes with a filter that creates a `tracing` span for
// each request we receive, including data about the request.
.with(warp::trace::request());
warp::serve(routes).run(([127, 0, 0, 1], 3030)).await;
}
sourcepub fn referer(&self) -> Option<&str>
pub fn referer(&self) -> Option<&str>
View the referer of the request.
Examples found in repository?
src/filters/trace.rs (line 59)
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
pub fn request() -> Trace<impl Fn(Info) -> Span + Clone> {
use tracing::field::{display, Empty};
trace(|info: Info| {
let span = tracing::info_span!(
"request",
remote.addr = Empty,
method = %info.method(),
path = %info.path(),
version = ?info.route.version(),
referer = Empty,
);
// Record optional fields.
if let Some(remote_addr) = info.remote_addr() {
span.record("remote.addr", &display(remote_addr));
}
if let Some(referer) = info.referer() {
span.record("referer", &display(referer));
}
tracing::debug!(parent: &span, "received request");
span
})
}
sourcepub fn user_agent(&self) -> Option<&str>
pub fn user_agent(&self) -> Option<&str>
View the user agent of the request.
sourcepub fn request_headers(&self) -> &HeaderMap
pub fn request_headers(&self) -> &HeaderMap
View the request headers.
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Info<'a>
impl<'a> Send for Info<'a>
impl<'a> Sync for Info<'a>
impl<'a> Unpin for Info<'a>
impl<'a> !UnwindSafe for Info<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self