This tag should be used for the Rust tracing library and related crates.
Questions tagged [rust-tracing]
41 questions
2
votes
0 answers
Idiomatic way of tracing an object through your system with `tracing`?
Context: event-driven system where objects go through a bunch of subsystems (Tokio architecture, communication over channels). I want to have spans that track the object through the system, from start to finish. Is the idiomatic way to do this just…

boston
- 95
- 1
- 7
2
votes
0 answers
tracing subscriber which async log function
I was planning on creating a new Layer for logging to gcp LogExplorer. Because we are working in rust, the api for logging is an async function call.
The tracing Layer trait exposes on_event function which is not async, which is where the problem…

Sandeep Kumar Pani
- 31
- 1
2
votes
0 answers
Is tracing intended to be used as I am using it? How can I trace errors chain?
I'm using async-graphql and axum.
This is a reproduction of the issue: https://github.com/frederikhors/iss-async-graphql-error-handling.
To start:
cargo run
If you open the GraphiQL client at http://localhost:8000, you can use the below query to…

Fred Hors
- 3,258
- 3
- 25
- 71
1
vote
0 answers
Tracing, how to filter logs under specified levels for `Layer`?
Consider the following code, I am writing the log into both standard output and a file. This is approached by Layer, while I don't know how to filter based on level.
pub fn trace() -> tracing_appender::non_blocking::WorkerGuard {
let mut log_dir…

realzhujunhao
- 137
- 6
1
vote
0 answers
Format tracing-rs log message with JSON in Subscriber/Layer
I'm using the tracing-rs crate for logging in my Rust application. Currently log messages are just printed to the console but I want them to be appended to a log file conditionally depending on the span. Some of the log messages are related to an…

binarybaron
- 11
- 2
1
vote
1 answer
How to use `tracing-subscriber` Rust crate to build a mult-writer, global filter subscriber
I'm trying to build a logging setup using the tracing and tracing-subscriber. However I'm finding the tracing ecosystem incredibly abstract and hard to work with.
I'm trying to create Subscriber that has -
A top level filter based on the target.…

twitu
- 553
- 6
- 12
1
vote
1 answer
How can I rename fields with the builtin json tracing subscriber?
The tracing json subscriber gives the following stdout out of the box:
fn main() {
tracing_subscriber::fmt()
.json()
.with_max_level(tracing::Level::DEBUG)
.flatten_event(true)
.init();
tracing::debug!("This…

VBar
- 13
- 3
1
vote
1 answer
possible to avoid giant Handle type signature using rust tracing library?
I have a function that initializes a tracing subscriber, and returns a reloading Handle so that I can dynamically control the log level. The type signature works but is a nightmare (I copy-pasted it in from a compiler error message). Is there a…

ajp
- 1,723
- 14
- 22
1
vote
0 answers
How to unify the time in the console and the file when using tracing-appender?
When I try to use tracing-appender, I notice that the time in the console does not match the time in the file. How can I get them to be the same time?
use std::io;
use std::path::Path;
use tracing::{debug, error, info, trace, warn, Level};
use…

3moredays
- 25
- 3
1
vote
1 answer
In Rust I use tracing wirte log to file. the file is created,but it is empty
In Rust I use tracing wirte log to file.While the app sleep, log file be created.the app finish ,the log file is empty.
Code:
pub fn tracing_init() {
let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
…

yan shen
- 41
- 2
1
vote
1 answer
Test if a trace line was emitted
I am writing integration tests for a library and I want to test if in a certain scenario a particular trace line was emitted. I see how tracing-test can capture a trace within a test step, I had a look at tracing-fluent-assertions and test-log, but…

fleetingbytes
- 2,512
- 5
- 16
- 27
1
vote
0 answers
How to send traces from rust + tracing_opentelemetry to Honeycomb?
I've set up a basic subscriber for Rust tracing with OpenTelemetry as follows:
let rust_log = dotenv::var("RUST_LOG").unwrap();
if rust_log == "OTEL" {
// Use OpenTelemetry subscriber
let tracer = stdout::new_pipeline().install_simple();
…

Peteris
- 3,548
- 4
- 28
- 44
1
vote
1 answer
How can I get/store span duration with Rust tracing?
I want to capture the duration of execution of a span in rust tracing and send that as metric.
I have found that fmt() helps in printing that as mentioned here:How can I log span duration with Rust tracing?
I have also tried this example about…

Sameer Shinde
- 21
- 3
1
vote
1 answer
Can't compile since opentelemetry and opentelemetry-jaeger update
I have this function that is working perfectly fine with opentelemetry = { version = "0.17", features = ["tokio"] } and opentelemetry-jaeger = { version = "0.16", features = ["rt-tokio"] }
pub fn get_subscriber(name: String, env_filter: String) ->…

Eric
- 375
- 7
- 19
1
vote
1 answer
Why is nothing printed to the terminal when using tracing-appender?
I do not understand why this code doesn't print anything on my terminal:
use tracing::info;
fn main() {
init();
info!("test me");
println!("i should have info! message before this")
}
pub fn init() {
let (non_blocking, _guard) =…

Fred Hors
- 3,258
- 3
- 25
- 71