Merge pull request #2952 from influxdata/dependabot/cargo/tracing-subscriber-0.3.0

chore(deps): bump tracing-subscriber from 0.2.25 to 0.3.0
pull/24376/head
kodiakhq[bot] 2021-10-25 15:10:12 +00:00 committed by GitHub
commit a498e2aa3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 52 additions and 31 deletions

9
Cargo.lock generated
View File

@ -2035,9 +2035,9 @@ checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
[[package]]
name = "matchers"
version = "0.0.1"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1"
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
dependencies = [
"regex-automata",
]
@ -4659,12 +4659,11 @@ dependencies = [
[[package]]
name = "tracing-subscriber"
version = "0.2.25"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71"
checksum = "5cf865b5ddc38e503a29c41c4843e616a73028ae18c637bc3eb2afaef4909c84"
dependencies = [
"ansi_term 0.12.1",
"chrono",
"lazy_static",
"matchers",
"regex",

View File

@ -26,7 +26,7 @@ snafu = "0.6.8"
tokio = { version = "1.11", features = ["macros", "rt-multi-thread"] }
toml = "0.5.6"
tracing = "0.1"
tracing-subscriber = "0.2.25"
tracing-subscriber = "0.3.0"
uuid = { version = "0.8.1", default_features = false }
[dev-dependencies]

View File

@ -7,9 +7,10 @@ edition = "2021"
[dependencies] # In alphabetical order
observability_deps = { path = "../observability_deps" }
tracing-subscriber = "0.2"
tracing-subscriber = "0.3"
[dev-dependencies] # In alphabetical order
once_cell = { version = "1.4.0", features = ["parking_lot"] }
parking_lot = "0.11.2"
regex = "1.4.3"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

View File

@ -19,12 +19,18 @@ use tracing_subscriber::{fmt::MakeWriter, layer::Context, registry::LookupSpan,
/// looked very small and did not (obviously) work with the tracing subscriber
///
/// [logfmt]: https://brandur.org/logfmt
pub struct LogFmtLayer<W: MakeWriter> {
pub struct LogFmtLayer<W>
where
W: for<'writer> MakeWriter<'writer>,
{
writer: W,
display_target: bool,
}
impl<W: MakeWriter> LogFmtLayer<W> {
impl<W> LogFmtLayer<W>
where
W: for<'writer> MakeWriter<'writer>,
{
/// Create a new logfmt Layer to pass into tracing_subscriber
///
/// Note this layer simply formats and writes to the specified writer. It
@ -68,7 +74,7 @@ impl<W: MakeWriter> LogFmtLayer<W> {
impl<S, W> Layer<S> for LogFmtLayer<W>
where
W: MakeWriter + 'static,
W: for<'writer> MakeWriter<'writer> + 'static,
S: Subscriber + for<'a> LookupSpan<'a>,
{
fn register_callsite(
@ -78,7 +84,7 @@ where
Interest::always()
}
fn new_span(&self, attrs: &tracing::span::Attributes<'_>, id: &Id, ctx: Context<'_, S>) {
fn on_new_span(&self, attrs: &tracing::span::Attributes<'_>, id: &Id, ctx: Context<'_, S>) {
let writer = self.writer.make_writer();
let metadata = ctx.metadata(id).expect("span should have metadata");
let mut p = FieldPrinter::new(writer, metadata.level(), self.display_target);

View File

@ -363,7 +363,7 @@ impl std::io::Write for CapturedWriter {
}
}
impl MakeWriter for CapturedWriter {
impl MakeWriter<'_> for CapturedWriter {
type Writer = Self;
fn make_writer(&self) -> Self::Writer {

View File

@ -8,5 +8,5 @@ edition = "2021"
dotenv = "0.15.0"
parking_lot = "0.11.2"
tempfile = "3.1.0"
tracing-subscriber = "0.2"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
observability_deps = { path = "../observability_deps" }

View File

@ -12,7 +12,7 @@ logfmt = { path = "../logfmt" }
observability_deps = { path = "../observability_deps" }
thiserror = "1.0.30"
tracing-log = "0.1"
tracing-subscriber = "0.2"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
structopt = { version = "0.3.25", optional = true }
[dev-dependencies]

View File

@ -105,7 +105,7 @@ impl LoggingConfig {
pub fn with_builder<W>(&self, builder: Builder<W>) -> Builder<BoxMakeWriter>
where
W: MakeWriter + Send + Sync + Clone + 'static,
W: for<'writer> MakeWriter<'writer> + Send + Sync + Clone + 'static,
{
builder
.with_log_filter(&self.log_filter)
@ -129,7 +129,7 @@ pub trait LoggingConfigBuilderExt {
impl<W> LoggingConfigBuilderExt for Builder<W>
where
W: MakeWriter + Send + Sync + Clone + 'static,
W: for<'writer> MakeWriter<'writer> + Send + Sync + Clone + 'static,
{
fn with_logging_config(self, config: &LoggingConfig) -> Builder<BoxMakeWriter> {
config.with_builder(self)

View File

@ -86,7 +86,7 @@ impl Builder {
impl<W> Builder<W> {
pub fn with_writer<W2>(self, make_writer: W2) -> Builder<W2>
where
W2: MakeWriter + Send + Sync + 'static,
W2: for<'writer> MakeWriter<'writer> + Send + Sync + 'static,
{
Builder::<W2> {
make_writer,
@ -103,7 +103,7 @@ impl<W> Builder<W> {
// This needs to be a separate impl block because they place different bounds on the type parameters.
impl<W> Builder<W>
where
W: MakeWriter + Send + Sync + 'static,
W: for<'writer> MakeWriter<'writer> + Send + Sync + 'static,
{
pub const DEFAULT_LOG_FILTER: &'static str = "warn";
@ -277,17 +277,30 @@ impl Drop for TroggingGuard {
fn make_writer<M>(m: M) -> BoxMakeWriter
where
M: MakeWriter + Send + Sync + 'static,
M: for<'writer> MakeWriter<'writer> + Send + Sync + 'static,
{
fmt::writer::BoxMakeWriter::new(move || {
std::io::LineWriter::with_capacity(
MAX_LINE_LENGTH,
LimitedWriter(MAX_LINE_LENGTH, m.make_writer()),
)
BoxMakeWriter::new(MakeWriterHelper {
inner: BoxMakeWriter::new(m),
})
}
struct MakeWriterHelper {
inner: BoxMakeWriter,
}
impl<'a> MakeWriter<'a> for MakeWriterHelper {
type Writer = Box<dyn Write + 'a>;
fn make_writer(&'a self) -> Self::Writer {
Box::new(std::io::LineWriter::with_capacity(
MAX_LINE_LENGTH,
LimitedWriter(MAX_LINE_LENGTH, self.inner.make_writer()),
))
}
}
struct LimitedWriter<W: Write>(usize, W);
impl<W: Write> Write for LimitedWriter<W> {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
if buf.is_empty() {
@ -341,7 +354,7 @@ pub mod test_util {
}
}
impl MakeWriter for TestWriter {
impl MakeWriter<'_> for TestWriter {
type Writer = SynchronizedWriter<Vec<u8>>;
fn make_writer(&self) -> Self::Writer {
@ -356,9 +369,9 @@ pub mod test_util {
/// Removes non-determinism by removing timestamps from the log lines.
/// It supports the built-in tracing timestamp format and the logfmt timestamps.
pub fn without_timestamps(&self) -> String {
// logfmt or fmt::layer() time format
// logfmt (e.g. `time=12345`) or fmt::layer() (e.g. `2021-10-25T13:48:50.555258`) time format
let timestamp = regex::Regex::new(
r"(?m)( ?time=[0-9]+|^([A-Z][a-z]{2}) \d{1,2} \d{2}:\d{2}:\d{2}.\d{3} *)",
r"(?m)( ?time=[0-9]+|^(\d{4})-\d{1,2}-\d{1,2}T\d{2}:\d{2}:\d{2}.\d+Z *)",
)
.unwrap();
timestamp.replace_all(&self.to_string(), "").to_string()
@ -379,7 +392,7 @@ pub mod test_util {
/// the logging macros invoked by the function.
pub fn log_test<W, F>(builder: Builder<W>, f: F) -> Captured
where
W: MakeWriter + Send + Sync + 'static,
W: for<'writer> MakeWriter<'writer> + Send + Sync + 'static,
F: Fn(),
{
let (writer, output) = TestWriter::new();
@ -401,7 +414,7 @@ pub mod test_util {
/// and returns the captured output.
pub fn simple_test<W>(builder: Builder<W>) -> Captured
where
W: MakeWriter + Send + Sync + 'static,
W: for<'writer> MakeWriter<'writer> + Send + Sync + 'static,
{
log_test(builder, || {
error!("foo");
@ -598,7 +611,8 @@ ERROR foo
#[test]
fn line_buffering() {
let (test_writer, captured) = TestWriter::new();
let mut writer = make_writer(test_writer).make_writer();
let mw = make_writer(test_writer);
let mut writer = mw.make_writer();
writer.write_all("foo".as_bytes()).unwrap();
// wasn't flushed yet because there was no newline yet
assert_eq!(captured.to_string(), "");
@ -611,7 +625,8 @@ ERROR foo
// another case when the line buffer flushes even before a newline is when the internal buffer limit
let (test_writer, captured) = TestWriter::new();
let mut writer = make_writer(test_writer).make_writer();
let mw = make_writer(test_writer);
let mut writer = mw.make_writer();
let long = std::iter::repeat(b'X')
.take(MAX_LINE_LENGTH)
.collect::<Vec<u8>>();