deps(udp): make tracing optional and add optional log

This commit makes the `tracing` dependency in `quinn-udp` optional, but enabled
by default. In additional it adds optional logging via the `log` crate, enabled
through the `direct-log` feature. `tracing` takes precedence over `native-log`.
This commit is contained in:
Max Inden
2024-07-18 12:01:07 +02:00
committed by Benjamin Saunders
parent 349dcd6017
commit 8712910a4c
6 changed files with 24 additions and 7 deletions
+1
View File
@@ -18,6 +18,7 @@ futures-io = "0.3.19"
hdrhistogram = { version = "7.2", default-features = false } hdrhistogram = { version = "7.2", default-features = false }
hex-literal = "0.4" hex-literal = "0.4"
lazy_static = "1" lazy_static = "1"
log = "0.4"
once_cell = "1.19" once_cell = "1.19"
pin-project-lite = "0.2" pin-project-lite = "0.2"
rand = "0.8" rand = "0.8"
+1 -1
View File
@@ -20,7 +20,7 @@ ring = ["dep:ring"]
# Enable rustls ring provider and direct ring usage # Enable rustls ring provider and direct ring usage
# Provides `ClientConfig::with_platform_verifier()` convenience method # Provides `ClientConfig::with_platform_verifier()` convenience method
platform-verifier = ["dep:rustls-platform-verifier"] platform-verifier = ["dep:rustls-platform-verifier"]
# Write logs via the `log` crate when no `tracing` subscriber exists # Configure `tracing` to log events via `log` if no `tracing` subscriber exists.
log = ["tracing/log"] log = ["tracing/log"]
[dependencies] [dependencies]
+5 -3
View File
@@ -14,14 +14,16 @@ workspace = ".."
all-features = true all-features = true
[features] [features]
default = ["log"] default = ["tracing", "log"]
# Write logs via the `log` crate when no `tracing` subscriber exists # Configure `tracing` to log events via `log` if no `tracing` subscriber exists.
log = ["tracing/log"] log = ["tracing/log"]
direct-log = ["dep:log"]
[dependencies] [dependencies]
libc = "0.2.113" libc = "0.2.113"
log = { workspace = true, optional = true }
socket2 = { workspace = true } socket2 = { workspace = true }
tracing = { workspace = true } tracing = { workspace = true, optional = true }
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
once_cell = { workspace = true } once_cell = { workspace = true }
+8
View File
@@ -37,6 +37,9 @@ use std::{
time::{Duration, Instant}, time::{Duration, Instant},
}; };
#[cfg(all(feature = "direct-log", not(feature = "tracing")))]
use log::warn;
#[cfg(feature = "tracing")]
use tracing::warn; use tracing::warn;
#[cfg(any(unix, windows))] #[cfg(any(unix, windows))]
@@ -126,6 +129,7 @@ const IO_ERROR_LOG_INTERVAL: Duration = std::time::Duration::from_secs(60);
/// ///
/// Logging will only be performed if at least [`IO_ERROR_LOG_INTERVAL`] /// Logging will only be performed if at least [`IO_ERROR_LOG_INTERVAL`]
/// has elapsed since the last error was logged. /// has elapsed since the last error was logged.
#[cfg(any(feature = "tracing", feature = "direct-log"))]
fn log_sendmsg_error( fn log_sendmsg_error(
last_send_error: &Mutex<Instant>, last_send_error: &Mutex<Instant>,
err: impl core::fmt::Debug, err: impl core::fmt::Debug,
@@ -141,6 +145,10 @@ fn log_sendmsg_error(
} }
} }
// No-op
#[cfg(not(any(feature = "tracing", feature = "direct-log")))]
fn log_sendmsg_error(_: &Mutex<Instant>, _: impl core::fmt::Debug, _: &Transmit) {}
/// A borrowed UDP socket /// A borrowed UDP socket
/// ///
/// On Unix, constructible via `From<T: AsFd>`. On Windows, constructible via `From<T: /// On Unix, constructible via `From<T: AsFd>`. On Windows, constructible via `From<T:
+7 -1
View File
@@ -12,7 +12,10 @@ use std::{
time::Instant, time::Instant,
}; };
#[cfg(all(feature = "direct-log", not(feature = "tracing")))]
use log::{debug, error};
use socket2::SockRef; use socket2::SockRef;
#[cfg(feature = "tracing")]
use tracing::{debug, error}; use tracing::{debug, error};
use super::{ use super::{
@@ -86,9 +89,11 @@ impl UdpSocketState {
// older macos versions also don't have the flag and will error out if we don't ignore it // older macos versions also don't have the flag and will error out if we don't ignore it
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))] #[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))]
if is_ipv4 || !io.only_v6()? { if is_ipv4 || !io.only_v6()? {
#[allow(unused_variables)]
if let Err(err) = set_socket_option(&*io, libc::IPPROTO_IP, libc::IP_RECVTOS, OPTION_ON) if let Err(err) = set_socket_option(&*io, libc::IPPROTO_IP, libc::IP_RECVTOS, OPTION_ON)
{ {
debug!("Ignoring error setting IP_RECVTOS on socket: {err:?}",); #[cfg(any(feature = "tracing", feature = "direct-log"))]
debug!("Ignoring error setting IP_RECVTOS on socket: {err:?}");
} }
} }
@@ -284,6 +289,7 @@ fn send(
// Prevent new transmits from being scheduled using GSO. Existing GSO transmits // Prevent new transmits from being scheduled using GSO. Existing GSO transmits
// may already be in the pipeline, so we need to tolerate additional failures. // may already be in the pipeline, so we need to tolerate additional failures.
if state.max_gso_segments() > 1 { if state.max_gso_segments() > 1 {
#[cfg(any(feature = "tracing", feature = "direct-log"))]
error!("got transmit error, halting segmentation offload"); error!("got transmit error, halting segmentation offload");
state state
.max_gso_segments .max_gso_segments
+2 -2
View File
@@ -27,7 +27,7 @@ runtime-tokio = ["tokio/time", "tokio/rt", "tokio/net"]
runtime-async-std = ["async-io", "async-std"] runtime-async-std = ["async-io", "async-std"]
runtime-smol = ["async-io", "smol"] runtime-smol = ["async-io", "smol"]
# Write logs via the `log` crate when no `tracing` subscriber exists # Configure `tracing` to log events via `log` if no `tracing` subscriber exists.
log = ["tracing/log", "proto/log", "udp/log"] log = ["tracing/log", "proto/log", "udp/log"]
[dependencies] [dependencies]
@@ -45,7 +45,7 @@ socket2 = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }
tracing = { workspace = true } tracing = { workspace = true }
tokio = { workspace = true } tokio = { workspace = true }
udp = { package = "quinn-udp", path = "../quinn-udp", version = "0.5", default-features = false } udp = { package = "quinn-udp", path = "../quinn-udp", version = "0.5", default-features = false, features = ["tracing"] }
[dev-dependencies] [dev-dependencies]
anyhow = { workspace = true } anyhow = { workspace = true }