feat: Makes the tracing dependency optional.#30
Conversation
|
I've made it off by default now, but that can be changed if preferred. |
There was a problem hiding this comment.
Pull request overview
This PR makes the tracing dependency optional for the httpsig crate by removing the internal trace re-export module and gating all logging usage behind a new tracing feature.
Changes:
- Introduces a
tracingCargo feature and marks thetracingdependency asoptional. - Removes
httpsig::tracemodule usage and switches call sites to conditionaluse tracing::{...}imports. - Wraps logging calls with
#[cfg(feature = "tracing")]to allow building withouttracing.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| httpsig/src/trace.rs | Removes the internal re-export layer for tracing macros. |
| httpsig/src/signature_params.rs | Drops trace::* and conditionally logs invalid params via tracing::error. |
| httpsig/src/message_component/component.rs | Drops trace::* and conditionally logs req parameter handling via tracing::debug. |
| httpsig/src/lib.rs | Removes the mod trace; module declaration. |
| httpsig/src/crypto/symmetric.rs | Drops trace::* and conditionally logs symmetric signing/verification steps. |
| httpsig/src/crypto/asymmetric.rs | Drops trace::* and conditionally logs asymmetric key parsing/signing/verification (some RSA branches need fixes). |
| httpsig/Cargo.toml | Adds tracing feature and makes the tracing dependency optional. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| AlgorithmName::Ed25519 => { | ||
| #[cfg(feature = "tracing")] | ||
| debug!("Read Ed25519 private key"); | ||
| let mut seed = [0u8; 32]; | ||
| seed.copy_from_slice(bytes); |
| Self::Ed25519(sk) => { | ||
| #[cfg(feature = "tracing")] | ||
| debug!("Sign Ed25519"); | ||
| let sig = sk.sign(data, Some(ed25519_compact::Noise::default())); | ||
| Ok(sig.as_ref().to_vec()) |
| AlgorithmName::Ed25519 => { | ||
| #[cfg(feature = "tracing")] | ||
| debug!("Read Ed25519 public key"); | ||
| let pk = ed25519_compact::PublicKey::from_slice(bytes).map_err(|e| HttpSigError::ParsePublicKeyError(e.to_string()))?; | ||
| Ok(Self::Ed25519(pk)) |
| #[cfg(feature = "rsa-signature")] | ||
| Self::RsaV1_5Sha256(pk) => { | ||
| #[cfg(feature = "tracing")] | ||
| debug!("Verify RsaV1_5Sha256"); | ||
| let sig = pkcs1v15::Signature::try_from(signature).map_err(|e| HttpSigError::ParseSignatureError(e.to_string()))?; | ||
| pk.verify(data, &sig) |
There was a problem hiding this comment.
omg. it must be unacceptable.
junkurihara
left a comment
There was a problem hiding this comment.
Thanks for the PR! Making tracing optional is acceptable, but I'd like to request two changes before merging.
- Keep the feature enabled by default (commented inline)
- Keep the
trace.rsfacade instead of scattering#[cfg]attributes (commented inline) - Rebase needed
The branch currently conflicts with develop (httpsig/Cargo.tomlandsrc/signature_params.rs) after the recent dependency updates, so please rebase as well.
| [features] | ||
| default = [] | ||
| rsa-signature = ["rsa"] | ||
| tracing = ["dep:tracing"] |
There was a problem hiding this comment.
Log output of existing users should not silently disappear, so the current behavior must be preserved.
[features]
default = ["tracing"]
tracing = ["dep:tracing"]
There was a problem hiding this comment.
Adding #[cfg(feature = "tracing")] to ~20 individual call sites is hard to maintain: every future log line would need to remember the guard, and a single forgotten one breaks the --no-default-features build. Please keep src/trace.rs and make it provide no-op macros when the feature is disabled, so that all call sites stay untouched:
#[cfg(feature = "tracing")]
#[allow(unused)]
pub(crate) use tracing::{debug, error, info, trace, warn};
/// No-op macros used when the `tracing` feature is disabled.
/// They expand to `()` so that they are usable both in statement and
/// expression positions, like the original `tracing` macros.
/// `warn` is defined as `warn_` and re-exported, since a macro named
/// `warn` conflicts with the built-in `warn` attribute (E0659).
#[cfg(not(feature = "tracing"))]
mod noop {
#![allow(unused_macros)]
macro_rules! debug { ($($arg:tt)*) => { () }; }
macro_rules! error { ($($arg:tt)*) => { () }; }
macro_rules! info { ($($arg:tt)*) => { () }; }
macro_rules! trace { ($($arg:tt)*) => { () }; }
macro_rules! warn_ { ($($arg:tt)*) => { () }; }
#[allow(unused_imports)]
pub(crate) use {debug, error, info, trace, warn_ as warn};
}
#[cfg(not(feature = "tracing"))]
#[allow(unused)]
pub(crate) use noop::*;
I have verified locally that this compiles with the feature both on and off. Two gotchas encoded in the snippet:
- a
macro_rules!macro namedwarncannot be re-exported because it collides with the built-in warn attribute (E0659), hence thewarn_definition re-exported under the name warn; - the no-op macros must expand to () rather than to nothing, because some call sites use them in expression position (e.g. the
_ => { error!(...) }arm insignature_params.rs).
With this approach the diff shrinks to Cargo.toml and trace.rs only. Please revert the changes to the other five files.
|
Note that Copilot's four comments above are all valid. I confirmed that building with Since fixing this requires rewriting the diff almost entirely, I have debugged and reimplemented the change on my side using the facade approach, and verified it across the full feature matrix (default / |
No description provided.