Skip to content

Commit

Permalink
subscriber: fix Context's LookupSpan method feature flagging (tok…
Browse files Browse the repository at this point in the history
…io-rs#1525)

The `layer::Context` type has additional methods that require the inner
subscriber to implement `LookupSpan`. These currently are only present
when the `registry` feature flag is enabled. However, this isn't
actually necessary --- the `LookupSpan` trait always exists, and doesn't
require the `registry` feature flag; that feature flag only controls
whether the `Registry` _type_, a concrete implementation of
`LookupSpan`, is enabled.

This branch removes the `cfg` attributes from these methods.
  • Loading branch information
hawkw authored and kaffarell committed May 22, 2024
1 parent 8baf491 commit 4a0e16f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
30 changes: 5 additions & 25 deletions tracing-subscriber/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use tracing_core::{
};

#[cfg(feature = "registry")]
use crate::registry::{self, LookupSpan, Registry, SpanRef};
use crate::registry::Registry;
use crate::registry::{self, LookupSpan, SpanRef};
use std::{any::TypeId, marker::PhantomData};

/// A composable handler for `tracing` events.
Expand Down Expand Up @@ -577,15 +578,12 @@ pub struct Identity {
///
/// [stored data]: ../registry/struct.SpanRef.html
/// [`Context::scope`]: struct.Context.html#method.scope
#[cfg(feature = "registry")]
#[cfg_attr(docsrs, doc(cfg(feature = "registry")))]
#[deprecated(note = "renamed to crate::registry::ScopeFromRoot", since = "0.2.19")]
#[derive(Debug)]
pub struct Scope<'a, L>(std::iter::Flatten<std::option::IntoIter<registry::ScopeFromRoot<'a, L>>>)
where
L: LookupSpan<'a>;

#[cfg(feature = "registry")]
#[allow(deprecated)]
impl<'a, L> Iterator for Scope<'a, L>
where
Expand Down Expand Up @@ -915,8 +913,6 @@ where
}
}

#[cfg(feature = "registry")]
#[cfg_attr(docsrs, doc(cfg(feature = "registry")))]
impl<'a, L, S> LookupSpan<'a> for Layered<L, S>
where
S: Subscriber + LookupSpan<'a>,
Expand Down Expand Up @@ -1062,8 +1058,6 @@ where
/// declaration</a> for details.
/// </pre></div>
#[inline]
#[cfg(feature = "registry")]
#[cfg_attr(docsrs, doc(cfg(feature = "registry")))]
pub fn event_span(&self, event: &Event<'_>) -> Option<SpanRef<'_, S>>
where
S: for<'lookup> LookupSpan<'lookup>,
Expand All @@ -1082,8 +1076,6 @@ where
/// If this returns `None`, then no span exists for that ID (either it has
/// closed or the ID is invalid).
#[inline]
#[cfg(feature = "registry")]
#[cfg_attr(docsrs, doc(cfg(feature = "registry")))]
pub fn metadata(&self, id: &span::Id) -> Option<&'static Metadata<'static>>
where
S: for<'lookup> LookupSpan<'lookup>,
Expand All @@ -1107,8 +1099,6 @@ where
///
/// [stored data]: ../registry/struct.SpanRef.html
#[inline]
#[cfg(feature = "registry")]
#[cfg_attr(docsrs, doc(cfg(feature = "registry")))]
pub fn span(&self, id: &span::Id) -> Option<registry::SpanRef<'_, S>>
where
S: for<'lookup> LookupSpan<'lookup>,
Expand All @@ -1126,8 +1116,6 @@ where
/// declaration</a> for details.
/// </pre></div>
#[inline]
#[cfg(feature = "registry")]
#[cfg_attr(docsrs, doc(cfg(feature = "registry")))]
pub fn exists(&self, id: &span::Id) -> bool
where
S: for<'lookup> LookupSpan<'lookup>,
Expand All @@ -1150,8 +1138,6 @@ where
///
/// [stored data]: ../registry/struct.SpanRef.html
#[inline]
#[cfg(feature = "registry")]
#[cfg_attr(docsrs, doc(cfg(feature = "registry")))]
pub fn lookup_current(&self) -> Option<registry::SpanRef<'_, S>>
where
S: for<'lookup> LookupSpan<'lookup>,
Expand Down Expand Up @@ -1183,16 +1169,14 @@ where
/// </pre></div>
///
/// [stored data]: ../registry/struct.SpanRef.html
#[cfg(feature = "registry")]
#[cfg_attr(docsrs, doc(cfg(feature = "registry")))]
#[deprecated(
note = "equivalent to `self.current_span().id().and_then(|id| self.span_scope(id).from_root())` but consider passing an explicit ID instead of relying on the contextual span",
since = "0.2.19"
)]
#[allow(deprecated)]
pub fn scope(&self) -> Scope<'_, S>
where
S: for<'lookup> registry::LookupSpan<'lookup>,
S: for<'lookup> LookupSpan<'lookup>,
{
Scope(
self.lookup_current()
Expand Down Expand Up @@ -1231,11 +1215,9 @@ where
/// </pre></div>
///
/// [stored data]: ../registry/struct.SpanRef.html
#[cfg(feature = "registry")]
#[cfg_attr(docsrs, doc(cfg(feature = "registry")))]
pub fn span_scope(&self, id: &span::Id) -> Option<registry::Scope<'_, S>>
where
S: for<'lookup> registry::LookupSpan<'lookup>,
S: for<'lookup> LookupSpan<'lookup>,
{
Some(self.span(id)?.scope())
}
Expand All @@ -1261,11 +1243,9 @@ where
/// </pre></div>
///
/// [stored data]: ../registry/struct.SpanRef.html
#[cfg(feature = "registry")]
#[cfg_attr(docsrs, doc(cfg(feature = "registry")))]
pub fn event_scope(&self, event: &Event<'_>) -> Option<registry::Scope<'_, S>>
where
S: for<'lookup> registry::LookupSpan<'lookup>,
S: for<'lookup> LookupSpan<'lookup>,
{
Some(self.event_span(event)?.scope())
}
Expand Down
1 change: 1 addition & 0 deletions tracing-subscriber/src/registry/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ impl ExtensionsInner {
/// Create an empty `Extensions`.
#[cfg(any(test, feature = "registry"))]
#[inline]
#[cfg(any(test, feature = "registry"))]
pub(crate) fn new() -> ExtensionsInner {
ExtensionsInner {
map: AnyMap::default(),
Expand Down

0 comments on commit 4a0e16f

Please sign in to comment.