From 8777d2c925d8ab5625ef95944758587eb7e74c46 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Fri, 22 Oct 2021 11:04:20 -0700 Subject: [PATCH] subscriber: rename `Layer::new_span` to `on_new_span` (#1674) While we're breaking things, we may as well do this as well. Closes #630 Closes #662 --- tracing-error/src/layer.rs | 2 +- tracing-journald/src/lib.rs | 2 +- tracing-opentelemetry/benches/trace.rs | 4 ++-- tracing-opentelemetry/src/layer.rs | 2 +- tracing-subscriber/src/filter/env/mod.rs | 2 +- tracing-subscriber/src/filter/layer_filters.rs | 4 ++-- tracing-subscriber/src/fmt/fmt_layer.rs | 2 +- tracing-subscriber/src/layer/layered.rs | 8 ++++---- tracing-subscriber/src/layer/mod.rs | 10 +++++----- tracing-subscriber/src/registry/sharded.rs | 2 +- tracing-subscriber/src/reload.rs | 4 ++-- tracing-subscriber/tests/support.rs | 2 +- 12 files changed, 22 insertions(+), 22 deletions(-) diff --git a/tracing-error/src/layer.rs b/tracing-error/src/layer.rs index 8a26e8cbea..321a660fda 100644 --- a/tracing-error/src/layer.rs +++ b/tracing-error/src/layer.rs @@ -40,7 +40,7 @@ where { /// Notifies this layer that a new span was constructed with the given /// `Attributes` and `Id`. - fn new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: layer::Context<'_, S>) { + fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: layer::Context<'_, S>) { let span = ctx.span(id).expect("span must already exist!"); if span.extensions().get::>().is_some() { return; diff --git a/tracing-journald/src/lib.rs b/tracing-journald/src/lib.rs index 530e68ddf9..356cbd3af8 100644 --- a/tracing-journald/src/lib.rs +++ b/tracing-journald/src/lib.rs @@ -122,7 +122,7 @@ impl tracing_subscriber::Layer for Layer where S: Subscriber + for<'span> LookupSpan<'span>, { - fn new_span(&self, attrs: &Attributes, id: &Id, ctx: Context) { + fn on_new_span(&self, attrs: &Attributes, id: &Id, ctx: Context<'_, S>) { let span = ctx.span(id).expect("unknown span"); let mut buf = Vec::with_capacity(256); diff --git a/tracing-opentelemetry/benches/trace.rs b/tracing-opentelemetry/benches/trace.rs index 9752b17f3d..298527f32f 100644 --- a/tracing-opentelemetry/benches/trace.rs +++ b/tracing-opentelemetry/benches/trace.rs @@ -60,7 +60,7 @@ impl tracing_subscriber::Layer for RegistryAccessLayer where S: tracing_core::Subscriber + for<'span> tracing_subscriber::registry::LookupSpan<'span>, { - fn new_span( + fn on_new_span( &self, _attrs: &tracing_core::span::Attributes<'_>, id: &tracing::span::Id, @@ -87,7 +87,7 @@ impl tracing_subscriber::Layer for OtelDataLayer where S: tracing_core::Subscriber + for<'span> tracing_subscriber::registry::LookupSpan<'span>, { - fn new_span( + fn on_new_span( &self, attrs: &tracing_core::span::Attributes<'_>, id: &tracing::span::Id, diff --git a/tracing-opentelemetry/src/layer.rs b/tracing-opentelemetry/src/layer.rs index ac67d2fae0..87068d405e 100644 --- a/tracing-opentelemetry/src/layer.rs +++ b/tracing-opentelemetry/src/layer.rs @@ -410,7 +410,7 @@ where /// /// [OpenTelemetry `Span`]: opentelemetry::trace::Span /// [tracing `Span`]: tracing::Span - fn new_span(&self, attrs: &Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) { + fn on_new_span(&self, attrs: &Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) { let span = ctx.span(id).expect("Span not found, this is a bug"); let mut extensions = span.extensions_mut(); diff --git a/tracing-subscriber/src/filter/env/mod.rs b/tracing-subscriber/src/filter/env/mod.rs index edaa8e7ef0..81fe0e62de 100644 --- a/tracing-subscriber/src/filter/env/mod.rs +++ b/tracing-subscriber/src/filter/env/mod.rs @@ -443,7 +443,7 @@ impl Layer for EnvFilter { false } - fn new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, _: Context<'_, S>) { + fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, _: Context<'_, S>) { let by_cs = try_lock!(self.by_cs.read()); if let Some(cs) = by_cs.get(&attrs.metadata().callsite()) { let span = cs.to_span_match(attrs); diff --git a/tracing-subscriber/src/filter/layer_filters.rs b/tracing-subscriber/src/filter/layer_filters.rs index 7515080676..e77fd3751d 100644 --- a/tracing-subscriber/src/filter/layer_filters.rs +++ b/tracing-subscriber/src/filter/layer_filters.rs @@ -320,9 +320,9 @@ where } } - fn new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, cx: Context<'_, S>) { + fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, cx: Context<'_, S>) { self.did_enable(|| { - self.layer.new_span(attrs, id, cx.with_filter(self.id())); + self.layer.on_new_span(attrs, id, cx.with_filter(self.id())); }) } diff --git a/tracing-subscriber/src/fmt/fmt_layer.rs b/tracing-subscriber/src/fmt/fmt_layer.rs index e889853048..631c586bd5 100644 --- a/tracing-subscriber/src/fmt/fmt_layer.rs +++ b/tracing-subscriber/src/fmt/fmt_layer.rs @@ -557,7 +557,7 @@ where E: FormatEvent + 'static, W: for<'writer> MakeWriter<'writer> + 'static, { - fn new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) { + fn on_new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) { let span = ctx.span(id).expect("Span not found, this is a bug"); let mut extensions = span.extensions_mut(); diff --git a/tracing-subscriber/src/layer/layered.rs b/tracing-subscriber/src/layer/layered.rs index 9e8fd206fa..c690764add 100644 --- a/tracing-subscriber/src/layer/layered.rs +++ b/tracing-subscriber/src/layer/layered.rs @@ -97,7 +97,7 @@ where fn new_span(&self, span: &span::Attributes<'_>) -> span::Id { let id = self.inner.new_span(span); - self.layer.new_span(span, &id, self.ctx()); + self.layer.on_new_span(span, &id, self.ctx()); id } @@ -233,9 +233,9 @@ where } #[inline] - fn new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) { - self.inner.new_span(attrs, id, ctx.clone()); - self.layer.new_span(attrs, id, ctx); + fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) { + self.inner.on_new_span(attrs, id, ctx.clone()); + self.layer.on_new_span(attrs, id, ctx); } #[inline] diff --git a/tracing-subscriber/src/layer/mod.rs b/tracing-subscriber/src/layer/mod.rs index e509b3f234..f3f994490f 100644 --- a/tracing-subscriber/src/layer/mod.rs +++ b/tracing-subscriber/src/layer/mod.rs @@ -650,7 +650,7 @@ where /// Notifies this layer that a new span was constructed with the given /// `Attributes` and `Id`. - fn new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) { + fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) { let _ = (attrs, id, ctx); } @@ -1089,9 +1089,9 @@ where } #[inline] - fn new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) { + fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) { if let Some(ref inner) = self { - inner.new_span(attrs, id, ctx) + inner.on_new_span(attrs, id, ctx) } } @@ -1190,8 +1190,8 @@ feature! { } #[inline] - fn new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) { - self.deref().new_span(attrs, id, ctx) + fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) { + self.deref().on_new_span(attrs, id, ctx) } #[inline] diff --git a/tracing-subscriber/src/registry/sharded.rs b/tracing-subscriber/src/registry/sharded.rs index cfafef6d1c..a6311cb718 100644 --- a/tracing-subscriber/src/registry/sharded.rs +++ b/tracing-subscriber/src/registry/sharded.rs @@ -598,7 +598,7 @@ mod tests { where S: Subscriber + for<'a> LookupSpan<'a>, { - fn new_span(&self, _: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) { + fn on_new_span(&self, _: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) { let span = ctx.span(id).expect("Missing span; this is a bug"); let mut lock = self.inner.lock().unwrap(); let is_removed = Arc::new(()); diff --git a/tracing-subscriber/src/reload.rs b/tracing-subscriber/src/reload.rs index 6dacf9db87..b8ec67dfa7 100644 --- a/tracing-subscriber/src/reload.rs +++ b/tracing-subscriber/src/reload.rs @@ -77,8 +77,8 @@ where } #[inline] - fn new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: layer::Context<'_, S>) { - try_lock!(self.inner.read()).new_span(attrs, id, ctx) + fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: layer::Context<'_, S>) { + try_lock!(self.inner.read()).on_new_span(attrs, id, ctx) } #[inline] diff --git a/tracing-subscriber/tests/support.rs b/tracing-subscriber/tests/support.rs index af96cea9f5..848ebdc639 100644 --- a/tracing-subscriber/tests/support.rs +++ b/tracing-subscriber/tests/support.rs @@ -271,7 +271,7 @@ where // TODO: it should be possible to expect spans to follow from other spans } - fn new_span(&self, span: &Attributes<'_>, id: &Id, cx: Context<'_, S>) { + fn on_new_span(&self, span: &Attributes<'_>, id: &Id, cx: Context<'_, S>) { let meta = span.metadata(); println!( "[{}] new_span: name={:?}; target={:?}; id={:?};",