This tag should be used for the Rust tracing library and related crates.
Questions tagged [rust-tracing]
41 questions
18
votes
2 answers
How to use the tracing library?
I have a very simple code example here which just wants to get the first item of a list I pass in. I have been trying to instrument the code with tracing to help debug the application but frankly the documentation is too sophisticated for me to…

Gunty
- 1,841
- 1
- 15
- 27
8
votes
0 answers
How can I reduce noise when tracing with Rust Warp?
When using warp with tracing enabled, I find the tracing output to be noisy. This is because a set of tracing events is emitted by every route, i.e., filter, that is attempted on each request.
So following the tracing example from the warp repo, if…

the_morrok
- 83
- 5
7
votes
0 answers
Why does a Rust macro re-exported from another crate work unless there's a dependency conflict
I'm writing a Rust crate for internal company use that wraps the excellent Tokio tracing crate, with a bit of additional functionality. Not only do I re-export the macros in tracing, but I also add a few of my own that internally invoke the tracing…

anelson
- 2,569
- 1
- 19
- 30
6
votes
1 answer
How can I log span duration with Rust tracing?
Rust has a tracing library that seems quite popular. It uses a building block called "span":
Spans represent periods of time in the execution of a program.
Now that I've set spans all throughout my app, how can I actually log their duration?
I've…

alextes
- 1,817
- 2
- 15
- 22
6
votes
1 answer
How to turn off tracing events emitted by other crates?
I use tracing, and I only want to see my own debug events. However, some crates I depend on also have tracing support, and they litter the event stream. So when I increase verbosity to DEBUG, I see a lot of these in my…

aedm
- 5,596
- 2
- 32
- 36
6
votes
2 answers
How can I change the log level on the fly with tracing?
As a developer I would like to adjust the log level on the fly. For example, I don't want to log debug! events when everything is going fine, but when something happens, I would like to adjust the log level without restarting the application to…

Sean
- 2,990
- 1
- 21
- 31
6
votes
1 answer
How to access the value of a field in a tracing span?
I'm using the tracing library in my project and there is one thing I'm not able to figure out: How can I access a value (that I set in my span when I create it) in my Layer?
My layer looks like this:
impl Layer for CustomLayer where S:…

Boss Man
- 587
- 2
- 12
6
votes
1 answer
How to combine a collection of tracing subscribers in one?
Let's say I have a function that returns a Vec> and I want to combine them into a single one to be set as the default subscriber.
How to do this?
I'm trying to do something like this, but I cannot make the types match:
pub fn…

Netwave
- 40,134
- 6
- 50
- 93
6
votes
2 answers
How to use a dynamic span name with tracing?
I need to instrument spans with different names dynamically. How can I create a tracing span with dynamic naming?
use tracing; // 0.1.22
fn main() {
let name: &'static str = "foo bar";
let span = tracing::span!(tracing::Level::TRACE,…

Netwave
- 40,134
- 6
- 50
- 93
5
votes
1 answer
How do I limit log levels when multiple logging destinations are used with the rust tracing library?
I have the following code that works for my rust application to write logs to stdout and to a rolling json file.
let appender = tracing_appender::rolling::hourly(app_log_path.clone(), "application.log");
let (non_blocking, _guard) =…

KallDrexx
- 27,229
- 33
- 143
- 254
4
votes
3 answers
How to print tracing output in tests?
My application is using the tracing Rust crate to create log output. How do I print these log messages when I'm running my tests?

Thorkil Værge
- 2,727
- 5
- 32
- 48
4
votes
2 answers
How to avoid text coloring when using tracing-appender?
When I write logs to a file with tracing-appender, I get output with terminal color artifacts which do not render when viewing them as a text file:
[2mOct 02 23:44:57.484[0m [34mDEBUG[0m
Is there a way to drop these artifacts?

Viktor Kulikov
- 53
- 6
3
votes
1 answer
How can I instrument async-graphql functions with tracing?
Copying the starwars example for actix-web I'm having issues understanding these errors when trying to instrument:
#[derive(Debug)] // adding this
struct AppState {
gql_schema: Schema, // errors here…

Fred Hors
- 3,258
- 3
- 25
- 71
3
votes
1 answer
How to show line number and file on tracing events?
How to print what source line! and file! a trace log originated from with tracing and tracing-subscriber?
The code I'm working with is well prepared and contains lots of log prints, which is good, but most of them are not very descriptive:
#…

Simson
- 3,373
- 2
- 24
- 38
3
votes
1 answer
How to write logs to multiple destinations conditionally with tracing?
I'm try to implement some centralized logging with the tracing crate. I can write to a rolling file with the tracing-appender crate or to a Graylog application with the following code:
let mut guards = Vec::new();
if let Some(log) = config.logs {
…

TheGr8_Nik
- 3,080
- 4
- 18
- 33