Skip to content

Commit 6e12ccd

Browse files
authored
Replace eprintln with tracing (#37)
1 parent 92401b2 commit 6e12ccd

File tree

16 files changed

+119
-36
lines changed

16 files changed

+119
-36
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ serde_with = "3.16.1"
4242
tempfile = "3.24.0"
4343
thiserror = "2.0.9"
4444
tokio = "1.48.0"
45+
tracing = "0.1.44"
46+
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
4547
url = "2.5.7"
4648
reqwest = { version = "0.13.1", default-features = false, features = ["json", "rustls", "stream"] }
4749

cli/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ miette = { workspace = true, features = ["fancy"] }
1919
serde_json = { workspace = true }
2020
serde_yaml = { workspace = true }
2121
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
22-
tracing = "0.1.44"
22+
tracing = { workspace = true }
2323
tracing-error = "0.2.1"
24-
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
24+
tracing-subscriber = { workspace = true }
2525
url = { workspace = true }
2626

2727
[dev-dependencies]

cli/src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ async fn proxy(args: ProxyArgs) -> Result<()> {
494494
println!("registered slot {slot} via router control ({control_endpoint})");
495495
}
496496
Err(ControlUpdateError::Retryable) => {
497-
eprintln!("waiting for router control at {control_endpoint}...");
497+
tracing::warn!("waiting for router control at {control_endpoint}...");
498498
let control_endpoint = control_endpoint.clone();
499499
let slot = slot.to_string();
500500
let mesh_url = mesh_url.clone();
@@ -505,7 +505,7 @@ async fn proxy(args: ProxyArgs) -> Result<()> {
505505
});
506506
}
507507
Err(ControlUpdateError::Fatal(err)) => {
508-
eprintln!(
508+
tracing::error!(
509509
"failed to register slot via router control ({}): {err}\nfallback: set \
510510
{env_var}={mesh_url} before starting the scenario",
511511
control_endpoint
@@ -557,7 +557,7 @@ async fn resolve_router_identity(
557557
));
558558
}
559559
if !warned {
560-
eprintln!("waiting for router control at {control_endpoint}...");
560+
tracing::warn!("waiting for router control at {control_endpoint}...");
561561
warned = true;
562562
}
563563
sleep(CONTROL_UPDATE_RETRY_INTERVAL).await;
@@ -985,7 +985,7 @@ async fn register_control_with_retry(
985985
sleep(CONTROL_UPDATE_RETRY_INTERVAL).await;
986986
}
987987
Err(ControlUpdateError::Fatal(err)) => {
988-
eprintln!(
988+
tracing::error!(
989989
"failed to register slot via router control ({}): {err}\nfallback: set \
990990
{env_var}={url} before starting the scenario",
991991
endpoint
@@ -1014,7 +1014,7 @@ async fn register_export_with_retry(
10141014
return Err(ExportRegistrationError::Timeout(timeout));
10151015
}
10161016
if !warned {
1017-
eprintln!("waiting for router control at {endpoint}...");
1017+
tracing::warn!("waiting for router control at {endpoint}...");
10181018
warned = true;
10191019
}
10201020
sleep(CONTROL_UPDATE_RETRY_INTERVAL).await;

images/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ publish = false
88
semver = "1.0.27"
99
serde = { workspace = true, features = ["derive"] }
1010
serde_json = { workspace = true }
11+
tracing = { workspace = true }
12+
tracing-subscriber = { workspace = true }
1113

1214
[build-dependencies]
1315
semver = "1.0.27"

images/src/bin/version_tags.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{
55
};
66

77
use serde::{Deserialize, Serialize};
8+
use tracing_subscriber::EnvFilter;
89

910
#[path = "../versioning.rs"]
1011
mod versioning;
@@ -35,6 +36,8 @@ struct ImageVersionTags {
3536
}
3637

3738
fn main() {
39+
init_tracing();
40+
3841
let manifest_path = match env::args().nth(1) {
3942
Some(path) => PathBuf::from(path),
4043
None => default_manifest_path(),
@@ -43,7 +46,7 @@ fn main() {
4346
let manifest = match read_manifest(&manifest_path) {
4447
Ok(manifest) => manifest,
4548
Err(err) => {
46-
eprintln!("{err}");
49+
tracing::error!("{err}");
4750
process::exit(1);
4851
}
4952
};
@@ -55,16 +58,17 @@ fn main() {
5558
};
5659
let version = version.trim();
5760
if version.is_empty() {
58-
eprintln!("image {} has an empty version", image.name);
61+
tracing::error!("image {} has an empty version", image.name);
5962
process::exit(1);
6063
}
6164

6265
let parsed = match versioning::parse_manifest_version(version) {
6366
Ok(parsed) => parsed,
6467
Err(err) => {
65-
eprintln!(
68+
tracing::error!(
6669
"image {} has invalid version {}: {err}",
67-
image.name, version
70+
image.name,
71+
version
6872
);
6973
process::exit(1);
7074
}
@@ -82,12 +86,21 @@ fn main() {
8286
match serde_json::to_string(&out) {
8387
Ok(json) => println!("{json}"),
8488
Err(err) => {
85-
eprintln!("failed to serialize version tag metadata: {err}");
89+
tracing::error!("failed to serialize version tag metadata: {err}");
8690
process::exit(1);
8791
}
8892
}
8993
}
9094

95+
fn init_tracing() {
96+
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("warn"));
97+
tracing_subscriber::fmt()
98+
.with_env_filter(filter)
99+
.with_target(false)
100+
.without_time()
101+
.init();
102+
}
103+
91104
fn default_manifest_path() -> PathBuf {
92105
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
93106
.parent()

runtime/docker-gateway/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ serde_urlencoded = "0.7.1"
1818
serde_with = { workspace = true }
1919
thiserror = { workspace = true }
2020
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "net", "io-util", "sync", "time", "signal"] }
21+
tracing = { workspace = true }
22+
tracing-subscriber = { workspace = true }
2123
url = { workspace = true }
2224

2325
[dev-dependencies]

runtime/docker-gateway/src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,14 @@ impl State {
370370
}
371371

372372
if !saw_address {
373-
eprintln!(
373+
tracing::warn!(
374374
"docker gateway caller resolution returned no addresses for host {}",
375375
caller.host
376376
);
377377
}
378378
}
379379
Err(err) => {
380-
eprintln!(
380+
tracing::warn!(
381381
"docker gateway caller resolution failed for host {}: {err}",
382382
caller.host
383383
);
@@ -418,7 +418,7 @@ impl State {
418418
.await
419419
.is_err()
420420
{
421-
eprintln!(
421+
tracing::warn!(
422422
"docker gateway shutdown cleanup timed out after {:?}",
423423
SHUTDOWN_CLEANUP_TIMEOUT
424424
);
@@ -479,7 +479,7 @@ impl State {
479479
let targets = match parse_targets(&response.body) {
480480
Ok(value) => value,
481481
Err(err) => {
482-
eprintln!("docker gateway cleanup failed to parse {list_name} list: {err}");
482+
tracing::warn!("docker gateway cleanup failed to parse {list_name} list: {err}");
483483
return;
484484
}
485485
};
@@ -490,7 +490,7 @@ impl State {
490490
continue;
491491
};
492492
if !is_allowed_cleanup_delete_status(delete_response.status) {
493-
eprintln!(
493+
tracing::warn!(
494494
"docker gateway cleanup failed to delete {item_name} {target}: {}",
495495
delete_response.status
496496
);
@@ -542,7 +542,7 @@ pub async fn run(config: DockerGatewayConfig) -> Result<(), DockerGatewayError>
542542
ShutdownReason::Terminated => {
543543
// `docker compose down` sends SIGTERM and also performs its own teardown.
544544
// Skipping gateway cleanup avoids duplicate deletes and "No such container" races.
545-
eprintln!(
545+
tracing::warn!(
546546
"docker gateway received SIGTERM; skipping shutdown cleanup to avoid \
547547
teardown races"
548548
);
@@ -554,7 +554,7 @@ pub async fn run(config: DockerGatewayConfig) -> Result<(), DockerGatewayError>
554554
let (stream, peer) = match accepted {
555555
Ok(value) => value,
556556
Err(err) => {
557-
eprintln!("docker gateway accept failed: {err}");
557+
tracing::warn!("docker gateway accept failed: {err}");
558558
continue;
559559
}
560560
};
@@ -582,7 +582,7 @@ pub async fn run(config: DockerGatewayConfig) -> Result<(), DockerGatewayError>
582582
.with_upgrades()
583583
.await
584584
{
585-
eprintln!("docker gateway connection failed: {err}");
585+
tracing::warn!("docker gateway connection failed: {err}");
586586
}
587587
});
588588
}
@@ -973,7 +973,7 @@ async fn forward_with_upgrade(
973973

974974
tokio::spawn(async move {
975975
if let Err(err) = conn.with_upgrades().await {
976-
eprintln!("docker upgrade connection failed: {err}");
976+
tracing::warn!("docker upgrade connection failed: {err}");
977977
}
978978
});
979979

@@ -998,19 +998,19 @@ async fn forward_with_upgrade(
998998

999999
tokio::spawn(async move {
10001000
let Ok(down) = on_client.await else {
1001-
eprintln!("downstream upgrade failed");
1001+
tracing::warn!("downstream upgrade failed");
10021002
return;
10031003
};
10041004
let Ok(up) = on_upstream.await else {
1005-
eprintln!("upstream upgrade failed");
1005+
tracing::warn!("upstream upgrade failed");
10061006
return;
10071007
};
10081008

10091009
let mut down = TokioIo::new(down);
10101010
let mut up = TokioIo::new(up);
10111011

10121012
if let Err(err) = tokio::io::copy_bidirectional(&mut down, &mut up).await {
1013-
eprintln!("upgrade tunnel error: {err}");
1013+
tracing::warn!("upgrade tunnel error: {err}");
10141014
}
10151015
});
10161016

runtime/docker-gateway/src/main.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
use amber_docker_gateway::{DockerGatewayConfig, run};
2+
use tracing_subscriber::EnvFilter;
23

34
#[tokio::main]
45
async fn main() {
6+
init_tracing();
7+
58
let config = match DockerGatewayConfig::from_env() {
69
Ok(config) => config,
710
Err(err) => {
8-
eprintln!("docker gateway config error: {err}");
11+
tracing::error!("docker gateway config error: {err}");
912
std::process::exit(1);
1013
}
1114
};
1215

1316
if let Err(err) = run(config).await {
14-
eprintln!("docker gateway failed: {err}");
17+
tracing::error!("docker gateway failed: {err}");
1518
std::process::exit(1);
1619
}
1720
}
21+
22+
fn init_tracing() {
23+
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("warn"));
24+
tracing_subscriber::fmt()
25+
.with_env_filter(filter)
26+
.with_target(false)
27+
.without_time()
28+
.init();
29+
}

runtime/helper/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ serde = { workspace = true, features = ["derive"] }
1313
serde_json = { workspace = true }
1414
signal-hook = "0.3.18"
1515
thiserror = { workspace = true }
16+
tracing = { workspace = true }
17+
tracing-subscriber = { workspace = true }
1618

1719
[dev-dependencies]
1820
tempfile = { workspace = true }

0 commit comments

Comments
 (0)