Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to tracing-subscriber 0.3 #13

Merged
merged 1 commit into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tokio-rustls = { version = "0.23", optional = true }
tokio-util = { version = "0.6", features = ["codec", "net"] }
tracing-core = "0.1"
tracing-futures = "0.2"
tracing-subscriber = "0.2"
tracing-subscriber = "0.3"

[dev-dependencies]
tokio = { version = "1", features = ["macros", "rt", "rt-multi-thread"] }
Expand Down
36 changes: 21 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ impl<S> Layer<S> for Logger
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
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 Expand Up @@ -521,23 +521,29 @@ where

// Get span name
if self.spans {
let span = ctx.scope().fold(String::new(), |mut spans, span| {
// Add span fields to the base object
if let Some(span_object) =
span.extensions().get::<HashMap<Cow<'static, str>, Value>>()
{
object.extend(span_object.clone());
}
if spans != String::new() {
spans = format!("{}:{}", spans, span.name());
} else {
spans = span.name().to_string();
}
let span = ctx.current_span().id().and_then(|id| {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a little jiggle around before 0.6. Do you mind rebasing against lastest master, this should work

            let span = ctx.current_span().id().and_then(|id| {
                ctx.span_scope(id).map(|scope| {
                    scope.from_root().fold(String::new(), |mut spans, span| {
                        // Add span fields to the base object
                        if let Some(span_object) = span.extensions().get::<HashMap<Cow<'static, str>, Value>>() {
                            object.extend(span_object.clone());
                        }
                        if spans != String::new() {
                            spans = format!("{}:{}", spans, span.name());
                        } else {
                            spans = span.name().to_string();
                        }

                        spans
                    })
                })
            });

            if let Some(span) = span {
                object.insert("_span".into(), span.into());
            }

ctx.span_scope(id).map(|scope| {
scope.from_root().fold(String::new(), |mut spans, span| {
// Add span fields to the base object
if let Some(span_object) =
span.extensions().get::<HashMap<Cow<'static, str>, Value>>()
{
object.extend(span_object.clone());
}
if !spans.is_empty() {
spans = format!("{}:{}", spans, span.name());
} else {
spans = span.name().to_string();
}

spans
spans
})
})
});

object.insert("_span".into(), span.into());
if let Some(span) = span {
object.insert("_span".into(), span.into());
}
}

// Extract metadata
Expand Down