Skip to content

Commit

Permalink
make tokio console optional
Browse files Browse the repository at this point in the history
  • Loading branch information
carneiro-cw committed May 24, 2024
1 parent 520ec90 commit 211b1b4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ pub struct CommonConfig {
/// Url to the tracing collector (Opentelemetry over gRPC)
#[arg(long = "tracing-collector-url", env = "TRACING_COLLECTOR_URL")]
pub tracing_url: Option<String>,

/// Enables tokio-console.
#[arg(long = "enable-tokio-console", env = "ENABLE_TOKIO_CONSOLE", default_value="true")]
pub enable_tokio_console: bool,
}

impl WithCommonConfig for CommonConfig {
Expand Down
2 changes: 1 addition & 1 deletion src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ where
runtime.block_on(spawn_signal_handler())?;

// init tracing
runtime.block_on(infra::init_tracing(config.common().tracing_url.as_ref()));
runtime.block_on(infra::init_tracing(config.common().tracing_url.as_ref(), config.common().enable_tokio_console));

Ok(Self {
config,
Expand Down
33 changes: 17 additions & 16 deletions src/infra/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::ext::not;
use crate::ext::spawn_named;

/// Init application global tracing.
pub async fn init_tracing(url: Option<&String>) {
pub async fn init_tracing(url: Option<&String>, enable_console: bool) {
println!("starting tracing");

// configure stdout layer
Expand All @@ -42,10 +42,6 @@ pub async fn init_tracing(url: Option<&String>) {
.boxed()
};

// configure tokio console layer
println!("tracing enabling tokio console");
//let (console_layer, console_server) = ConsoleLayer::builder().with_default_env().build();

// configure opentelemetry layer
let opentelemetry_layer = match url {
Some(url) => {
Expand All @@ -63,18 +59,23 @@ pub async fn init_tracing(url: Option<&String>) {
};

// init registry
tracing_subscriber::registry()
.with(stdout_layer)
//.with(console_layer)
.with(opentelemetry_layer)
.init();
let registry = tracing_subscriber::registry().with(stdout_layer).with(opentelemetry_layer);

if enable_console {
// configure tokio console layer
println!("tracing enabling tokio console");
let (console_layer, console_server) = ConsoleLayer::builder().with_default_env().build();
registry.with(console_layer).init();

/* // init tokio console server
spawn_named("console::grpc-server", async move {
if let Err(e) = console_server.serve().await {
tracing::error!(reason = ?e, "failed to start tokio-console server");
};
});*/
// init tokio console server
spawn_named("console::grpc-server", async move {
if let Err(e) = console_server.serve().await {
tracing::error!(reason = ?e, "failed to start tokio-console server");
};
});
} else {
registry.init()
}

tracing::info!("started tracing");
}
Expand Down

0 comments on commit 211b1b4

Please sign in to comment.