Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tracing: disable regular expression matching in log filters #1580

Merged
merged 1 commit into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2632,9 +2632,9 @@ dependencies = [

[[package]]
name = "tracing-subscriber"
version = "0.3.9"
version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e0ab7bdc962035a87fba73f3acca9b8a8d0034c2e6f60b84aeaaddddc155dce"
checksum = "b9df98b037d039d03400d9dd06b0f8ce05486b5f25e9a2d7d36196e142ebbc52"
dependencies = [
"ansi_term",
"lazy_static",
Expand Down
2 changes: 1 addition & 1 deletion linkerd/tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ tracing = "0.1"
tracing-log = "0.1"

[dependencies.tracing-subscriber]
version = "0.3"
version = "0.3.10"
default-features = false
features = ["env-filter", "fmt", "smallvec", "tracing-log", "json", "parking_lot", "registry"]
17 changes: 15 additions & 2 deletions linkerd/tracing/src/level.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
use linkerd_error::Error;
use tracing::trace;
use tracing_subscriber::{reload, EnvFilter, Registry};
use tracing_subscriber::{
filter::{self, EnvFilter, LevelFilter},
reload, Registry,
};

#[derive(Clone)]
pub struct Handle(reload::Handle<EnvFilter, Registry>);

/// Returns an `EnvFilter` builder with the configuration used for parsing new
/// filter strings.
pub(crate) fn filter_builder() -> filter::Builder {
EnvFilter::builder()
.with_default_directive(LevelFilter::WARN.into())
// Disable regular expression matching for `fmt::Debug` fields, use
// exact string matching instead.
.with_regex(false)
}

impl Handle {
pub(crate) fn new(handle: reload::Handle<EnvFilter, Registry>) -> Self {
Self(handle)
Expand All @@ -18,7 +31,7 @@ impl Handle {

pub fn set_level(&self, level: impl AsRef<str>) -> Result<(), Error> {
let level = level.as_ref();
let filter = level.parse::<EnvFilter>()?;
let filter = filter_builder().parse(level)?;
self.0.reload(filter)?;
tracing::info!(%level, "set new log level");
Ok(())
Expand Down
9 changes: 6 additions & 3 deletions linkerd/tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use linkerd_error::Error;
use std::str;
use tracing::{Dispatch, Subscriber};
use tracing_subscriber::{
filter::{EnvFilter, FilterFn},
filter::{FilterFn, LevelFilter},
fmt::format,
prelude::*,
registry::LookupSpan,
Expand Down Expand Up @@ -60,7 +60,6 @@ pub fn init() -> Result<Handle, Error> {

#[inline]
pub(crate) fn update_max_level() {
use tracing::level_filters::LevelFilter;
use tracing_log::{log, AsLog};
log::set_max_level(LevelFilter::current().as_log());
}
Expand Down Expand Up @@ -167,7 +166,11 @@ impl Settings {
pub fn build(self) -> (Dispatch, Handle) {
let log_level = self.filter.as_deref().unwrap_or(DEFAULT_LOG_LEVEL);

let mut filter = EnvFilter::new(log_level);
let mut filter = level::filter_builder()
// When parsing the initial filter configuration from the
// environment variable, use `parse_lossy` to skip any invalid
// filter directives and print an error.
.parse_lossy(log_level);

// If access logging is enabled, build the access log layer.
let access_log = if let Some(format) = self.access_log {
Expand Down