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
This commit is contained in:
Eliza Weisman 2021-10-22 11:04:20 -07:00
parent c62dac9f73
commit 8777d2c925
12 changed files with 22 additions and 22 deletions

View File

@ -40,7 +40,7 @@ where
{ {
/// Notifies this layer that a new span was constructed with the given /// Notifies this layer that a new span was constructed with the given
/// `Attributes` and `Id`. /// `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!"); let span = ctx.span(id).expect("span must already exist!");
if span.extensions().get::<FormattedFields<F>>().is_some() { if span.extensions().get::<FormattedFields<F>>().is_some() {
return; return;

View File

@ -122,7 +122,7 @@ impl<S> tracing_subscriber::Layer<S> for Layer
where where
S: Subscriber + for<'span> LookupSpan<'span>, 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 span = ctx.span(id).expect("unknown span");
let mut buf = Vec::with_capacity(256); let mut buf = Vec::with_capacity(256);

View File

@ -60,7 +60,7 @@ impl<S> tracing_subscriber::Layer<S> for RegistryAccessLayer
where where
S: tracing_core::Subscriber + for<'span> tracing_subscriber::registry::LookupSpan<'span>, S: tracing_core::Subscriber + for<'span> tracing_subscriber::registry::LookupSpan<'span>,
{ {
fn new_span( fn on_new_span(
&self, &self,
_attrs: &tracing_core::span::Attributes<'_>, _attrs: &tracing_core::span::Attributes<'_>,
id: &tracing::span::Id, id: &tracing::span::Id,
@ -87,7 +87,7 @@ impl<S> tracing_subscriber::Layer<S> for OtelDataLayer
where where
S: tracing_core::Subscriber + for<'span> tracing_subscriber::registry::LookupSpan<'span>, S: tracing_core::Subscriber + for<'span> tracing_subscriber::registry::LookupSpan<'span>,
{ {
fn new_span( fn on_new_span(
&self, &self,
attrs: &tracing_core::span::Attributes<'_>, attrs: &tracing_core::span::Attributes<'_>,
id: &tracing::span::Id, id: &tracing::span::Id,

View File

@ -410,7 +410,7 @@ where
/// ///
/// [OpenTelemetry `Span`]: opentelemetry::trace::Span /// [OpenTelemetry `Span`]: opentelemetry::trace::Span
/// [tracing `Span`]: tracing::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 span = ctx.span(id).expect("Span not found, this is a bug");
let mut extensions = span.extensions_mut(); let mut extensions = span.extensions_mut();

View File

@ -443,7 +443,7 @@ impl<S: Subscriber> Layer<S> for EnvFilter {
false 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()); let by_cs = try_lock!(self.by_cs.read());
if let Some(cs) = by_cs.get(&attrs.metadata().callsite()) { if let Some(cs) = by_cs.get(&attrs.metadata().callsite()) {
let span = cs.to_span_match(attrs); let span = cs.to_span_match(attrs);

View File

@ -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.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()));
}) })
} }

View File

@ -557,7 +557,7 @@ where
E: FormatEvent<S, N> + 'static, E: FormatEvent<S, N> + 'static,
W: for<'writer> MakeWriter<'writer> + '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 span = ctx.span(id).expect("Span not found, this is a bug");
let mut extensions = span.extensions_mut(); let mut extensions = span.extensions_mut();

View File

@ -97,7 +97,7 @@ where
fn new_span(&self, span: &span::Attributes<'_>) -> span::Id { fn new_span(&self, span: &span::Attributes<'_>) -> span::Id {
let id = self.inner.new_span(span); 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 id
} }
@ -233,9 +233,9 @@ where
} }
#[inline] #[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>) {
self.inner.new_span(attrs, id, ctx.clone()); self.inner.on_new_span(attrs, id, ctx.clone());
self.layer.new_span(attrs, id, ctx); self.layer.on_new_span(attrs, id, ctx);
} }
#[inline] #[inline]

View File

@ -650,7 +650,7 @@ where
/// Notifies this layer that a new span was constructed with the given /// Notifies this layer that a new span was constructed with the given
/// `Attributes` and `Id`. /// `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); let _ = (attrs, id, ctx);
} }
@ -1089,9 +1089,9 @@ where
} }
#[inline] #[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 { 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] #[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>) {
self.deref().new_span(attrs, id, ctx) self.deref().on_new_span(attrs, id, ctx)
} }
#[inline] #[inline]

View File

@ -598,7 +598,7 @@ mod tests {
where where
S: Subscriber + for<'a> LookupSpan<'a>, 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 span = ctx.span(id).expect("Missing span; this is a bug");
let mut lock = self.inner.lock().unwrap(); let mut lock = self.inner.lock().unwrap();
let is_removed = Arc::new(()); let is_removed = Arc::new(());

View File

@ -77,8 +77,8 @@ where
} }
#[inline] #[inline]
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>) {
try_lock!(self.inner.read()).new_span(attrs, id, ctx) try_lock!(self.inner.read()).on_new_span(attrs, id, ctx)
} }
#[inline] #[inline]

View File

@ -271,7 +271,7 @@ where
// TODO: it should be possible to expect spans to follow from other spans // 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(); let meta = span.metadata();
println!( println!(
"[{}] new_span: name={:?}; target={:?}; id={:?};", "[{}] new_span: name={:?}; target={:?}; id={:?};",