bevyengine / bevyengine/bevy

Tracing with bevy_ecs

Open
#8,123 6 comments 0 reactions 0 assignees View on GitHub
A-Diagnostics C-Docs
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## How can Bevy's documentation be improved?

Bevy_ecs has a trace feature https://docs.rs/crate/bevy_ecs/0.10.0/features

With a bit of setup and searching around, I managed to get it to output the spans for every system. *However*, every system is simply named "system", which makes me believe that I'm doing something wrong.

![image](https://user-images.githubusercontent.com/10220080/226102351-19e7e7ac-07b2-4af2-b04c-71338f65bff3.png)

A bit of setup means adding the following in my Cargo.toml
```toml
tracing-chrome = { version = "0.7.1", optional = true }
tracing-subscriber = { version = "0.3.16", optional = true, features = ["registry", "env-filter"] }

[features]
default = ["trace"]
trace = [ "dep:tracing-chrome", "dep:tracing-subscriber", "bevy_ecs/trace" ]
```

And that to my `main.rs`
```rust

#[cfg(feature = "trace")]
use tracing_chrome::ChromeLayerBuilder;
#[cfg(feature = "trace")]
use tracing_subscriber::fmt::{format::DefaultFields, FormattedFields};
#[cfg(feature = "trace")]
use tracing_subscriber::{prelude::*, registry::Registry};

...
#[cfg(feature = "trace")]
fn start_tracing() -> tracing_chrome::FlushGuard {
let (chrome_layer, _guard) = ChromeLayerBuilder::new()
.name_fn(Box::new(|event_or_span| match event_or_span {
tracing_chrome::EventOrSpan::Event(event) => event.metadata().name().into(),
tracing_chrome::EventOrSpan::Span(span) => {
if let Some(fields) = span.extensions().get::>() {
format!("{}: {}", span.metadata().name(), fields.fields.as_str())
} else {
span.metadata().name().into()
}
}
}))
.build();
tracing_subscriber::registry().with(chrome_layer).init();
// Maybe do app.world.insert_non_send_resource(guard); ?
_guard
}

fn main() {
#[cfg(feature = "trace")]
let _guard = start_tracing();
...

}
```

I am inserting the systems the usual way, e.g. `schedule.add_system(update_transform_system.in_set(AppStage::PostUpdate));`. I'm using the single threaded executor. I can also gladly provide the entire source code or a minimal sample if that's helpful for debugging.

Contributor guide

Open the contributing guide

Research direction

Start with the bevy_ecs trace feature documentation and the Cargo.toml and main.rs setup shown in the issue. Reproduce the single-threaded schedule and inspect the emitted system span names, then update the relevant documentation to explain the expected behavior and configuration. Done means the tracing setup and naming behavior are documented clearly with a reproducible example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation, observability
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.