Skip to content

Commit

Permalink
Putting tracing behind a feature (with default on)
Browse files Browse the repository at this point in the history
  • Loading branch information
FemLolStudio committed May 16, 2024
1 parent f45a580 commit 8268cf3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions s3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ hyper-timeout = "0.5"
# hyper-tls = { version = "0.6", default-features = false }
rustls = { version = "0.23", default-features = false, features = ["std"] }
# hyper-native-tls = { version = "0.3", default-features = false }
tracing = { version="0.1", default-features = false }
tracing = { version="0.1", default-features = false, optional = true }
md5 = "0.7"
percent-encoding = "2"
serde = { version = "1", features = ["derive"]}
Expand All @@ -83,9 +83,10 @@ bytes = { version = "1" }
strum_macros = "0.26"

[features]
default = ["fail-on-err"]
default = ["fail-on-err", "tracing"]
no-verify-ssl = []
fail-on-err = []
tracing = ["dep:tracing"]

[dev-dependencies]
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros", "fs"] }
Expand Down
4 changes: 4 additions & 0 deletions s3/src/request/tokio_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub use crate::request::tokio_backend::HyperRequest as RequestImpl;
pub use tokio::io::AsyncWriteExt;
pub use tokio_stream::Stream;

#[cfg(feature = "tracing")]
use tracing::{event, span, Level};

use crate::request::request_trait::ResponseDataStream;
Expand Down Expand Up @@ -63,6 +64,7 @@ impl<'a> Request for HyperRequest<'a> {
}
request.body(Full::from(Bytes::from(self.request_body())))?
};
#[cfg(feature = "tracing")]
let span = span!(
Level::DEBUG,
"rust-s3-async",
Expand All @@ -76,9 +78,11 @@ impl<'a> Request for HyperRequest<'a> {
month = self.datetime.month() as u8,
year = self.datetime.year()
);
#[cfg(feature = "tracing")]
let _enter = span.enter();
let response = client.request(request).await?;

#[cfg(feature = "tracing")]
event!(Level::DEBUG, status_code = response.status().as_u16(),);

if cfg!(feature = "fail-on-err") && !response.status().is_success() {
Expand Down

0 comments on commit 8268cf3

Please sign in to comment.