Skip to content

Commit

Permalink
tests: thread local tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
chesedo committed Mar 13, 2023
1 parent 4e88558 commit 6c699ae
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
11 changes: 7 additions & 4 deletions common/src/backends/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ impl<MakeSpan> TraceLayer<MakeSpan> {
///
/// # Example
/// ```
/// use shuttle_common::{request_span, backends::metrics::TraceLayer};
/// use tracing::field;
///
/// TraceLayer::new(|request| {
/// request_span!(
/// request,
Expand Down Expand Up @@ -206,7 +209,7 @@ mod tests {
use tower::ServiceExt;
use tracing::field;
use tracing_fluent_assertions::{AssertionRegistry, AssertionsLayer};
use tracing_subscriber::{layer::SubscriberExt, Registry};
use tracing_subscriber::layer::SubscriberExt;

use super::{Metrics, TraceLayer};

Expand All @@ -221,9 +224,9 @@ mod tests {
#[tokio::test]
async fn trace_layer() {
let assertion_registry = AssertionRegistry::default();
let base_subscriber = Registry::default();
let subscriber = base_subscriber.with(AssertionsLayer::new(&assertion_registry));
tracing::subscriber::set_global_default(subscriber).unwrap();
let subscriber =
tracing_subscriber::registry().with(AssertionsLayer::new(&assertion_registry));
let _guard = tracing::subscriber::set_default(subscriber);

// Put in own block to make sure assertion to not interfere with the next test
{
Expand Down
4 changes: 2 additions & 2 deletions common/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ where
}

#[cfg(test)]
mod test {
mod tests {
use cap_std::os::unix::net::UnixStream;
use serde_json::json;
use std::io::{Read, Write};
Expand Down Expand Up @@ -499,7 +499,7 @@ mod test {
(message, log.level)
};

tracing_subscriber::registry().with(logger).init();
let _guard = tracing_subscriber::registry().with(logger).set_default();

tracing::debug!("this is");
tracing::info!("hi");
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ mod tests {

let logger = Logger::new(s, Default::default());

tracing_subscriber::registry().with(logger).init();
let _guard = tracing_subscriber::registry().with(logger).set_default();

tracing::debug!("this is");
tracing::info!("hi");
Expand Down

0 comments on commit 6c699ae

Please sign in to comment.