Upgrade tracing-subscriber

… and remove EnvFilterClone workaround.
This commit is contained in:
Jonas Platte 2025-09-16 10:48:45 +02:00
parent b5bc53bb2d
commit 412aaae106
No known key found for this signature in database
GPG key ID: 7D261D771D915378
6 changed files with 34 additions and 131 deletions

70
Cargo.lock generated
View file

@ -329,7 +329,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "234113d19d0d7d613b40e86fb654acf958910802bcceab913a4f9e7cda03b1a4"
dependencies = [
"memchr",
"regex-automata 0.4.9",
"regex-automata",
"serde",
]
@ -1610,11 +1610,11 @@ checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
[[package]]
name = "matchers"
version = "0.1.0"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9"
dependencies = [
"regex-automata 0.1.10",
"regex-automata",
]
[[package]]
@ -1709,12 +1709,11 @@ checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be"
[[package]]
name = "nu-ansi-term"
version = "0.46.0"
version = "0.50.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
checksum = "d4a28e057d01f97e61255210fcff094d74ed0466038633e95017f5beb68e4399"
dependencies = [
"overload",
"winapi",
"windows-sys 0.52.0",
]
[[package]]
@ -1869,12 +1868,6 @@ dependencies = [
"tokio-stream",
]
[[package]]
name = "overload"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "parking_lot"
version = "0.12.4"
@ -2344,17 +2337,8 @@ checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata 0.4.9",
"regex-syntax 0.8.5",
]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
dependencies = [
"regex-syntax 0.6.29",
"regex-automata",
"regex-syntax",
]
[[package]]
@ -2365,15 +2349,9 @@ checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax 0.8.5",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.6.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
[[package]]
name = "regex-syntax"
version = "0.8.5"
@ -3556,14 +3534,14 @@ dependencies = [
[[package]]
name = "tracing-subscriber"
version = "0.3.19"
version = "0.3.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008"
checksum = "2054a14f5307d601f88daf0553e1cbf472acc4f2c51afab632431cdcd72124d5"
dependencies = [
"matchers",
"nu-ansi-term",
"once_cell",
"regex",
"regex-automata",
"serde",
"serde_json",
"sharded-slab",
@ -3882,28 +3860,6 @@ version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68ce1ab1f8c62655ebe1350f589c61e505cf94d385bc6a12899442d9081e71fd"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-link"
version = "0.1.3"

View file

@ -139,7 +139,7 @@ tower-http = { version = "0.6.6", features = ["add-extension", "cors", "sensitiv
tracing = { version = "0.1.41", features = [] }
tracing-flame = "0.2.0"
tracing-opentelemetry = "0.25.0"
tracing-subscriber = { version = "0.3.19", features = ["env-filter", "json"] }
tracing-subscriber = { version = "0.3.20", features = ["env-filter", "json"] }
trust-dns-resolver = "0.23.2"
xdg = "2.5.2"

View file

@ -6,9 +6,10 @@
use std::path::PathBuf;
use clap::{Parser, Subcommand};
use tracing_subscriber::EnvFilter;
use crate::{
config::{default_tracing_filter, EnvFilterClone, LogFormat},
config::{default_tracing_filter, LogFormat},
error, observability,
};
@ -86,7 +87,7 @@ struct ObservabilityArgs {
/// For information about the syntax, see here:
/// <https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>
#[clap(long, default_value_t = default_tracing_filter())]
log_filter: EnvFilterClone,
log_filter: EnvFilter,
}
#[derive(clap::Args)]
@ -98,7 +99,7 @@ pub(crate) struct ServeArgs {
impl Args {
pub(crate) async fn run(self) -> Result<(), error::Main> {
if let Some((format, filter)) = self.command.cli_observability_args() {
observability::init_for_cli(format, filter.into())?;
observability::init_for_cli(format, filter)?;
}
match self.command {
@ -110,7 +111,7 @@ impl Args {
}
impl Command {
fn cli_observability_args(&self) -> Option<(LogFormat, EnvFilterClone)> {
fn cli_observability_args(&self) -> Option<(LogFormat, EnvFilter)> {
// All subcommands other than `serve` should return `Some`. Keep these
// match arms sorted by the enum variant name.
match self {

View file

@ -14,13 +14,12 @@ use ruma::{
};
use serde::Deserialize;
use strum::{Display, EnumIter, IntoEnumIterator};
use tracing_subscriber::EnvFilter;
use crate::{error, utils::partial_canonicalize};
mod env_filter_clone;
mod proxy;
pub(crate) use env_filter_clone::EnvFilterClone;
use proxy::ProxyConfig;
/// The default configuration file path
@ -364,7 +363,8 @@ pub(crate) struct MetricsConfig {
#[serde(default)]
pub(crate) struct OtelTraceConfig {
pub(crate) enable: bool,
pub(crate) filter: EnvFilterClone,
#[serde(deserialize_with = "crate::utils::deserialize_from_str")]
pub(crate) filter: EnvFilter,
pub(crate) endpoint: Option<String>,
pub(crate) service_name: String,
}
@ -385,7 +385,8 @@ impl Default for OtelTraceConfig {
#[serde(default)]
pub(crate) struct FlameConfig {
pub(crate) enable: bool,
pub(crate) filter: EnvFilterClone,
#[serde(deserialize_with = "crate::utils::deserialize_from_str")]
pub(crate) filter: EnvFilter,
pub(crate) filename: String,
}
@ -403,7 +404,8 @@ impl Default for FlameConfig {
#[serde(deny_unknown_fields)]
#[serde(default)]
pub(crate) struct LogConfig {
pub(crate) filter: EnvFilterClone,
#[serde(deserialize_with = "crate::utils::deserialize_from_str")]
pub(crate) filter: EnvFilter,
pub(crate) colors: bool,
pub(crate) format: LogFormat,
pub(crate) timestamp: bool,
@ -510,7 +512,7 @@ fn default_max_request_size() -> UInt {
(20_u32 * 1024 * 1024).into()
}
pub(crate) fn default_tracing_filter() -> EnvFilterClone {
pub(crate) fn default_tracing_filter() -> EnvFilter {
"info,ruma_state_res=warn"
.parse()
.expect("hardcoded env filter should be valid")

View file

@ -1,57 +0,0 @@
//! A workaround for [`EnvFilter`] not directly implementing [`Clone`]
//!
//! This will be unnecessary after [tokio-rs/tracing#2956][0] is merged.
//!
//! [0]: https://github.com/tokio-rs/tracing/pull/2956
#![warn(missing_docs, clippy::missing_docs_in_private_items)]
use std::{fmt, str::FromStr};
use serde::{de, Deserialize, Deserializer};
use tracing_subscriber::EnvFilter;
/// A workaround for [`EnvFilter`] not directly implementing [`Clone`]
///
/// Use [`FromStr`] or [`Deserialize`] to construct this type, then [`From`] or
/// [`Into`] to convert it into an [`EnvFilter`] when needed.
#[derive(Debug, Clone)]
pub(crate) struct EnvFilterClone(pub(crate) String);
impl FromStr for EnvFilterClone {
type Err = <EnvFilter as FromStr>::Err;
fn from_str(s: &str) -> Result<Self, Self::Err> {
EnvFilter::from_str(s)?;
Ok(Self(s.to_owned()))
}
}
impl fmt::Display for EnvFilterClone {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl From<&EnvFilterClone> for EnvFilter {
fn from(other: &EnvFilterClone) -> Self {
EnvFilter::from_str(&other.0)
.expect("env filter syntax should have been validated already")
}
}
impl From<EnvFilterClone> for EnvFilter {
fn from(other: EnvFilterClone) -> Self {
EnvFilter::from_str(&other.0)
.expect("env filter syntax should have been validated already")
}
}
impl<'de> Deserialize<'de> for EnvFilterClone {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
Self::from_str(&s).map_err(de::Error::custom)
}
}

View file

@ -33,7 +33,7 @@ use tracing_subscriber::{
};
use crate::{
config::{Config, EnvFilterClone, LogFormat},
config::{Config, LogFormat},
error,
utils::error::Result,
};
@ -105,13 +105,14 @@ impl FilterReloadHandle {
/// Creates a new [`FilterReloadHandle`] from a filter string, returning the
/// filter layer itself and the handle that can be used to modify it.
pub(crate) fn new<S: tracing::Subscriber>(
filter: EnvFilterClone,
filter: EnvFilter,
) -> (impl tracing_subscriber::layer::Filter<S>, Self) {
let (layer, handle) = reload::Layer::new(EnvFilter::from(&filter));
let filter_s = filter.to_string();
let (layer, handle) = reload::Layer::new(filter);
let handle = Self {
inner: Box::new(handle),
current_filter: filter.0.clone(),
initial_filter: filter.0,
current_filter: filter_s.clone(),
initial_filter: filter_s,
};
(layer, handle)
}
@ -198,7 +199,7 @@ pub(crate) enum FoundIn {
/// filter to the layer.
fn make_backend<S, L, T>(
enable: bool,
filter: &EnvFilterClone,
filter: &EnvFilter,
init: impl FnOnce() -> Result<(L, T), error::Observability>,
) -> Result<
(impl Layer<S>, Option<FilterReloadHandle>, Option<T>),