dbrgn / tracing-test

Access and evaluate tracing logs in async and sync tests.
Apache License 2.0
62 stars 27 forks source link

how does tracing-test work with targeted spans? #2

Closed mooreniemi closed 3 years ago

mooreniemi commented 3 years ago

Hello again. 😅

In my application I use targets like:

tracing::error!(target: "my_cool_app", "failure: {:?}", b);

I am finding that any logs I emit from targeted span appear in my logs as expected when running the application, but logs_contain can't see them.

So:

tracing::debug!("content_length: {:?}", resp.content_length()); // tests pass
tracing::error!(target: "my_cool_app", "failure: {:?}", b); // tests don't pass

Are targets supported or not? If so, what do I need to do to see them?

mooreniemi commented 3 years ago

I figure it is down to the env_filter somehow? Means the subscriber can't "see" anything in a target?

let env_filter = format!("{}=trace", crate_name);
let mock_writer = tracing_test::internal::MockWriter::new(&tracing_test::internal::GLOBAL_BUF);
let subscriber = tracing_test::internal::get_subscriber(mock_writer, &env_filter);

From https://github.com/dbrgn/tracing-test/blob/main/tracing-test-macro/src/lib.rs#L67

dbrgn commented 3 years ago

Sorry for late reply. In #4 there's another report of the same issue. I'll close this one since the other issue has a slightly better description, feel free to add more information there in case you found out what the reason for this behavior is.