Skip to content

Commit 505c2fd

Browse files
committed
fix: inject pod_name, namespace, node_name into JSON log output
Reads from RuntimeContext (detected once at startup). On K8s, these fields appear in every JSON log line for correlation. On bare metal, fields are None and injection is skipped (no overhead). Uses the existing inject_and_redact_json_line mechanism alongside service_name and service_version.
1 parent 515c090 commit 505c2fd

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/logger/masking.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,27 @@ fn inject_and_redact_json_line(
256256
serde_json::Value::String(ver.to_string()),
257257
);
258258
}
259+
260+
// Inject K8s context fields (no-op on bare metal — fields are None)
261+
let ctx = crate::env::runtime_context();
262+
if let Some(ref pod) = ctx.pod_name {
263+
map.insert(
264+
"pod_name".to_string(),
265+
serde_json::Value::String(pod.clone()),
266+
);
267+
}
268+
if let Some(ref ns) = ctx.namespace {
269+
map.insert(
270+
"namespace".to_string(),
271+
serde_json::Value::String(ns.clone()),
272+
);
273+
}
274+
if let Some(ref node) = ctx.node_name {
275+
map.insert(
276+
"node_name".to_string(),
277+
serde_json::Value::String(node.clone()),
278+
);
279+
}
259280
}
260281
redact_json_value(&mut value, sensitive);
261282
let mut result = serde_json::to_string(&value).unwrap_or_else(|_| trimmed.to_string());

0 commit comments

Comments
 (0)