Skip to content

Commit 5016574

Browse files
committed
feat: add short_id utility for readable UUID logs
Display only first 8 characters of UUIDs in logs for better readability.
1 parent 4b76191 commit 5016574

6 files changed

Lines changed: 27 additions & 7 deletions

File tree

src/event_scheduled.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ pub fn handle_scheduled(
151151
{
152152
Some(w) => w,
153153
None => {
154-
log::error!("worker not found: {:?}", data.worker_id);
154+
log::error!(
155+
"worker not found: {}",
156+
crate::utils::short_id(&data.worker_id)
157+
);
155158
continue;
156159
}
157160
};

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub mod store;
99
pub mod task_executor;
1010
#[cfg(feature = "v8")]
1111
mod transform;
12+
pub mod utils;
1213
pub mod worker;
1314
pub mod worker_pool;
1415

@@ -23,3 +24,6 @@ pub use limiter::{BindingLimiter, BindingLimiters, LimitError, LimiterGuard};
2324

2425
// Re-export store types
2526
pub use store::{AssetsConfig, Binding, KvConfig, StorageConfig, WorkerWithBindings};
27+
28+
// Re-export utils
29+
pub use utils::short_id;

src/log.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ async fn flush_worker(nc: &async_nats::Client, batch: &mut Vec<LogMessage>, work
122122
log::debug!(
123123
"Flushing {} logs for worker {}",
124124
worker_logs.len(),
125-
worker_id
125+
crate::utils::short_id(worker_id)
126126
);
127127

128128
for log_msg in worker_logs {
@@ -155,7 +155,10 @@ pub struct WorkerLogHandler {
155155
impl WorkerLogHandler {
156156
/// Signal that this worker is done and logs should be flushed
157157
pub fn flush(self) {
158-
log::debug!("Flushing logs for worker: {}", self.worker_id);
158+
log::debug!(
159+
"Flushing logs for worker: {}",
160+
crate::utils::short_id(&self.worker_id)
161+
);
159162
// Drop tx first to close the channel
160163
drop(self.tx);
161164
// Then send flush signal

src/store.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use sqlx::prelude::FromRow;
22
use std::collections::HashMap;
33

4+
use crate::utils::short_id;
5+
46
#[derive(Debug)]
57
pub enum WorkerIdentifier {
68
Id(String),
@@ -429,7 +431,7 @@ pub async fn get_worker_with_bindings(
429431

430432
log::debug!(
431433
"worker found: id: {}, version: {}, bindings: {}, type: {}",
432-
basic.id,
434+
short_id(&basic.id),
433435
basic.version,
434436
bindings.len(),
435437
basic.code_type
@@ -637,7 +639,11 @@ async fn fetch_worker_binding_config(
637639
name: row.name,
638640
}),
639641
Err(err) => {
640-
log::warn!("failed to fetch worker_binding {}: {:?}", worker_id, err);
642+
log::warn!(
643+
"failed to fetch worker_binding {}: {:?}",
644+
short_id(worker_id),
645+
err
646+
);
641647
None
642648
}
643649
}

src/utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/// Returns the first 8 characters of an ID for readable logs
2+
pub fn short_id(id: &str) -> &str {
3+
&id[..8.min(id.len())]
4+
}

src/worker.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn parse_code(data: &WorkerWithBindings) -> Result<WorkerCode, TerminationReason
128128
if let Some(cached_code) = cache.get(&cache_key) {
129129
log::debug!(
130130
"transpile cache HIT: worker={}, version={}",
131-
data.id,
131+
crate::utils::short_id(&data.id),
132132
data.version
133133
);
134134
return Ok(WorkerCode::js(cached_code.clone()));
@@ -137,7 +137,7 @@ fn parse_code(data: &WorkerWithBindings) -> Result<WorkerCode, TerminationReason
137137

138138
log::debug!(
139139
"transpile cache MISS: worker={}, version={}",
140-
data.id,
140+
crate::utils::short_id(&data.id),
141141
data.version
142142
);
143143

0 commit comments

Comments
 (0)