Skip to content

Commit

Permalink
subscriber: rename Layer::new_span to on_new_span (#1674)
Browse files Browse the repository at this point in the history
While we're breaking things, we may as well do this as well.

Closes #630
Closes #662
  • Loading branch information
hawkw committed Oct 22, 2021
1 parent c62dac9 commit 8777d2c
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion tracing-error/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<FormattedFields<F>>().is_some() {
return;
Expand Down
2 changes: 1 addition & 1 deletion tracing-journald/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<S> tracing_subscriber::Layer<S> for Layer
where
S: Subscriber + for<'span> LookupSpan<'span>,
{
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("unknown span");
let mut buf = Vec::with_capacity(256);

Expand Down
4 changes: 2 additions & 2 deletions tracing-opentelemetry/benches/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<S> tracing_subscriber::Layer<S> 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,
Expand All @@ -87,7 +87,7 @@ impl<S> tracing_subscriber::Layer<S> 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,
Expand Down
2 changes: 1 addition & 1 deletion tracing-opentelemetry/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion tracing-subscriber/src/filter/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ impl<S: Subscriber> Layer<S> 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);
Expand Down
4 changes: 2 additions & 2 deletions tracing-subscriber/src/filter/layer_filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
})
}

Expand Down
2 changes: 1 addition & 1 deletion tracing-subscriber/src/fmt/fmt_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ where
E: FormatEvent<S, N> + '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();

Expand Down
8 changes: 4 additions & 4 deletions tracing-subscriber/src/layer/layered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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]
Expand Down
10 changes: 5 additions & 5 deletions tracing-subscriber/src/layer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tracing-subscriber/src/registry/sharded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
Expand Down
4 changes: 2 additions & 2 deletions tracing-subscriber/src/reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tracing-subscriber/tests/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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={:?};",
Expand Down

0 comments on commit 8777d2c

Please sign in to comment.