penumbra_sdk_tower_trace/
lib.rs

1#![deny(clippy::unwrap_used)]
2#![cfg_attr(docsrs, feature(doc_auto_cfg))]
3
4/// A vendored copy of the unpublished `tracing-tower` crate.
5pub mod trace;
6
7use std::net::SocketAddr;
8
9// Extracted from tonic's remote_addr implementation; we'd like to instrument
10// spans with the remote addr at the server level rather than at the individual
11// request level, but the hook available to do that gives us an http::Request
12// rather than a tonic::Request, so the tonic::Request::remote_addr method isn't
13// available.
14pub fn remote_addr<B>(req: &http::Request<B>) -> Option<SocketAddr> {
15    use tonic::transport::server::TcpConnectInfo;
16    // NOTE: needs to also check TlsConnectInfo if we use TLS
17    req.extensions()
18        .get::<TcpConnectInfo>()
19        .and_then(|i| i.remote_addr())
20}
21
22pub mod v034 {
23    mod request_ext;
24    pub use request_ext::RequestExt;
25}
26
27pub mod v037 {
28    mod request_ext;
29    pub use request_ext::RequestExt;
30}
31
32pub mod v038 {
33    mod request_ext;
34    pub use request_ext::RequestExt;
35}