Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .cargo/config.toml

This file was deleted.

3 changes: 2 additions & 1 deletion crates/observe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ axum = { workspace = true, optional = true }
atty = { workspace = true }
async-trait = { workspace = true }
chrono = { workspace = true, features = ["now"] }
console-subscriber = { workspace = true }
console-subscriber = { workspace = true, optional = true }
futures = { workspace = true }
opentelemetry = { workspace = true }
opentelemetry-otlp = { workspace = true, features = ["grpc-tonic"] }
Expand All @@ -37,3 +37,4 @@ workspace = true
default = []
axum-tracing = ["axum"]
jemalloc-profiling = ["dep:jemalloc_pprof"]
tokio-console = ["dep:console-subscriber"]
2 changes: 2 additions & 0 deletions crates/observe/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
fn main() {
// Make build system aware of custom config flags to avoid clippy warnings
// tokio_unstable is only used when explicitly compiled with --cfg
// tokio_unstable (e.g., in the playground environment)
println!("cargo::rustc-check-cfg=cfg(tokio_unstable)");
}
49 changes: 26 additions & 23 deletions crates/observe/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,7 @@ pub fn initialize_reentrant(config: &Config) {
fn set_tracing_subscriber(config: &Config) {
let initial_filter = config.env_filter.to_string();

// The `tracing` APIs are heavily generic to enable zero overhead. Unfortunately
// this leads to very annoying type constraints which can only be satisfied
// by literally copy and pasting the code so the compiler doesn't try to
// infer types that satisfy both the tokio-console and the regular case.
// It's tempting to resolve this mess by first configuring the `fmt_layer` and
// only then the `console_subscriber`. However, this setup was the only way
// I found that:
// 1. actually makes `tokio-console` work
// 2. prints logs if `tokio-console` is disabled
// 3. does NOT skip the next log following a `tracing::event!()`. These calls
// happen for example under the hood in `sqlx`. I don't understand what's
// actually causing that but at this point I'm just happy if all the features
// work correctly.
// The `tracing` APIs are heavily generic to enable zero overhead.

macro_rules! fmt_layer {
($env_filter:expr_2021, $stderr_threshold:expr_2021, $use_json_format:expr_2021) => {{
Expand Down Expand Up @@ -109,11 +97,6 @@ fn set_tracing_subscriber(config: &Config) {
}};
}

let enable_tokio_console: bool = std::env::var("TOKIO_CONSOLE")
.unwrap_or("false".to_string())
.parse()
.unwrap();

let (env_filter, reload_handle) =
tracing_subscriber::reload::Layer::new(EnvFilter::new(&initial_filter));

Expand Down Expand Up @@ -161,13 +144,33 @@ fn set_tracing_subscriber(config: &Config) {
))
.with(tracing_layer);

if cfg!(tokio_unstable) && enable_tokio_console {
subscriber.with(console_subscriber::spawn()).init();
tracing::info!("started program with support for tokio-console");
} else {
#[cfg(all(tokio_unstable, feature = "tokio-console"))]
{
let enable_tokio_console: bool = std::env::var("TOKIO_CONSOLE")
.unwrap_or("false".to_string())
.parse()
.unwrap();
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .unwrap() call could panic if the TOKIO_CONSOLE environment variable is set to an invalid value (e.g., "maybe", "1", "yes"). Consider using .unwrap_or(false) or .unwrap_or_else(|_| false) to handle parsing errors gracefully, defaulting to false when the value cannot be parsed as a boolean.

Suggested change
.unwrap();
.unwrap_or(false);

Copilot uses AI. Check for mistakes.

if enable_tokio_console {
subscriber.with(console_subscriber::spawn()).init();
tracing::info!("started program with support for tokio-console");
} else {
subscriber.init();
tracing::info!(
"started program without support for tokio-console (TOKIO_CONSOLE=false)"
);
}
}

#[cfg(not(all(tokio_unstable, feature = "tokio-console")))]
{
subscriber.init();
tracing::info!("started program without support for tokio-console");
tracing::info!(
"started program without support for tokio-console (not compiled with tokio_unstable \
cfg and tokio-console feature)"
);
}

if cfg!(unix) {
spawn_reload_handler(initial_filter, reload_handle);
}
Expand Down
18 changes: 9 additions & 9 deletions playground/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CMD ["migrate"]
FROM chef AS builder
COPY --from=planner /src/recipe.json recipe.json
COPY --from=chef /.cargo /.cargo
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo chef cook --release --recipe-path recipe.json
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo chef cook --release --features observe/tokio-console --recipe-path recipe.json

# Copy only the library crates for now
COPY --from=chef /.cargo /.cargo
Expand All @@ -48,9 +48,9 @@ COPY ./crates/chain/ ./crates/chain
COPY ./crates/ethrpc/ ./crates/ethrpc
COPY ./crates/observe/ ./crates/observe
COPY ./crates/order-validation/ ./crates/order-validation
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --package shared
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --features observe/tokio-console --package shared
COPY ./crates/solver/ ./crates/solver
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --package solver
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --features observe/tokio-console --package solver

# Create an base image for all the binaries
FROM docker.io/debian:bookworm-slim AS base
Expand All @@ -61,14 +61,14 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked apt-get update && \
FROM builder AS alerter-build
COPY --from=chef /.cargo /.cargo
COPY ./crates/alerter/ ./crates/alerter
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --package alerter
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --features observe/tokio-console --package alerter

FROM base AS alerter
COPY --from=alerter-build /src/target/release/alerter /usr/local/bin/alerter
ENTRYPOINT [ "alerter" ]

FROM builder AS autopilot-build
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --package autopilot
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --features observe/tokio-console --package autopilot

FROM base AS autopilot
COPY --from=chef /.cargo /.cargo
Expand All @@ -78,7 +78,7 @@ ENTRYPOINT [ "autopilot" ]

FROM builder AS driver-build
COPY ./crates/driver/ ./crates/driver
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --package driver
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --features observe/tokio-console --package driver

FROM base AS driver
COPY --from=driver-build /src/target/release/driver /usr/local/bin/driver
Expand All @@ -87,7 +87,7 @@ ENTRYPOINT [ "driver" ]
FROM builder AS orderbook-build
COPY --from=chef /.cargo /.cargo
COPY ./crates/orderbook/ ./crates/orderbook
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --package orderbook
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --features observe/tokio-console --package orderbook

FROM base AS orderbook
COPY --from=orderbook-build /src/target/release/orderbook /usr/local/bin/orderbook
Expand All @@ -96,7 +96,7 @@ ENTRYPOINT [ "orderbook" ]
FROM builder AS refunder-build
COPY --from=chef /.cargo /.cargo
COPY ./crates/refunder/ ./crates/refunder
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --package refunder
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --features observe/tokio-console --package refunder

FROM base AS refunder
COPY --from=refunder-build /src/target/release/refunder /usr/local/bin/refunder
Expand All @@ -105,7 +105,7 @@ ENTRYPOINT [ "refunder" ]
FROM builder AS solvers-build
COPY --from=chef /.cargo /.cargo
COPY ./crates/solvers/ ./crates/solvers
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --package solvers
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --features observe/tokio-console --package solvers

FROM base AS solvers
COPY --from=solvers-build /src/target/release/solvers /usr/local/bin/solvers
Expand Down
Loading