diff --git a/crates/tower-cmd/src/run.rs b/crates/tower-cmd/src/run.rs index b96f2ad0..bec58f5a 100644 --- a/crates/tower-cmd/src/run.rs +++ b/crates/tower-cmd/src/run.rs @@ -247,7 +247,7 @@ fn build_cli_execution_spec( run_id: String, ) -> ExecutionSpec { let spec = ExecutionSpec { - id: run_id, + id: run_id.clone(), package_stream: Box::new(package_stream), runtime: ExecRuntimeConfig { image: "local".to_string(), @@ -278,7 +278,7 @@ fn build_cli_execution_spec( timeout_seconds: 3600, }, networking: None, - telemetry_ctx: Context::new(), + telemetry_ctx: Context::new("local-runner".to_string()).with_runid(&run_id), }; spec } diff --git a/crates/tower-runtime/tests/local_test.rs b/crates/tower-runtime/tests/local_test.rs index 02069308..2a0c741f 100644 --- a/crates/tower-runtime/tests/local_test.rs +++ b/crates/tower-runtime/tests/local_test.rs @@ -48,7 +48,7 @@ async fn test_running_hello_world_json_logs() { // We need to create the package, which will load the app let opts = StartOptions { - ctx: tower_telemetry::Context::new(), + ctx: tower_telemetry::Context::new("runner-id".to_string()), package, output_sender: sender, cwd: None, @@ -97,7 +97,7 @@ async fn test_running_hello_world() { // We need to create the package, which will load the app let opts = StartOptions { - ctx: tower_telemetry::Context::new(), + ctx: tower_telemetry::Context::new("runner-id".to_string()), package, output_sender: sender, cwd: None, @@ -142,7 +142,7 @@ async fn test_running_use_faker() { // We need to create the package, which will load the app let opts = StartOptions { - ctx: tower_telemetry::Context::new(), + ctx: tower_telemetry::Context::new("runner-id".to_string()), package, output_sender: sender, cwd: None, @@ -194,7 +194,7 @@ async fn test_running_legacy_app() { // We need to create the package, which will load the app let opts = StartOptions { - ctx: tower_telemetry::Context::new(), + ctx: tower_telemetry::Context::new("runner-id".to_string()), package, output_sender: sender, cwd: None, @@ -260,7 +260,7 @@ async fn test_running_app_with_secret() { // We need to create the package, which will load the app let opts = StartOptions { - ctx: tower_telemetry::Context::new(), + ctx: tower_telemetry::Context::new("runner-id".to_string()), package, output_sender: sender, cwd: None, @@ -339,7 +339,7 @@ async fn test_abort_on_dependency_installation_failure() { let (sender, mut receiver) = unbounded_channel(); let opts = StartOptions { - ctx: tower_telemetry::Context::new(), + ctx: tower_telemetry::Context::new("runner-id".to_string()), package, output_sender: sender, cwd: None, diff --git a/crates/tower-runtime/tests/subprocess_test.rs b/crates/tower-runtime/tests/subprocess_test.rs index 40a99929..8d7448c6 100644 --- a/crates/tower-runtime/tests/subprocess_test.rs +++ b/crates/tower-runtime/tests/subprocess_test.rs @@ -45,7 +45,7 @@ async fn create_execution_spec(id: String, package: Package) -> ExecutionSpec { ExecutionSpec { id, - telemetry_ctx: tower_telemetry::Context::new(), + telemetry_ctx: tower_telemetry::Context::new("runner-id".to_string()), package_stream: Box::new(file), environment: "test".to_string(), secrets: HashMap::new(), diff --git a/crates/tower-telemetry/src/context.rs b/crates/tower-telemetry/src/context.rs index c1ac26ce..c61329b0 100644 --- a/crates/tower-telemetry/src/context.rs +++ b/crates/tower-telemetry/src/context.rs @@ -2,16 +2,20 @@ pub struct Context { /// runid is the ID of the run in the current context. pub runid: Option, + /// runner_id is the ID of the runner instance in the current context. + pub runner_id: String, } impl Context { - pub fn from_runid(runid: &str) -> Self { + pub fn new(runner_id: String) -> Self { Self { - runid: Some(runid.to_string()), + runid: None, + runner_id, } } - pub fn new() -> Self { - Self { runid: None } + pub fn with_runid(mut self, runid: &str) -> Self { + self.runid = Some(runid.to_string()); + self } } diff --git a/crates/tower-telemetry/src/logging.rs b/crates/tower-telemetry/src/logging.rs index 7c16fd48..03e8e80e 100644 --- a/crates/tower-telemetry/src/logging.rs +++ b/crates/tower-telemetry/src/logging.rs @@ -7,9 +7,9 @@ macro_rules! event_with_level { // With context ($level:expr, ctx: $ctx:expr, $fmt:expr, $($arg:tt)+) => { if let Some(runid) = &$ctx.runid { - $crate::tracing::event!($level, "tower.runid" = %runid, "{}", format!($fmt, $($arg)+)) + $crate::tracing::event!($level, "tower.runid" = %runid, "tower.runner_id" = %$ctx.runner_id, "{}", format!($fmt, $($arg)+)) } else { - $crate::tracing::event!($level, "{}", format!($fmt, $($arg)+)) + $crate::tracing::event!($level, "tower.runner_id" = %$ctx.runner_id, "{}", format!($fmt, $($arg)+)) } };