Skip to content

Commit db4973c

Browse files
chore(context-engine): add workspace_id to traces (#2522)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 892e34d commit db4973c

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

‎crates/forge_services/src/context_engine.rs‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<F: 'static + ProviderRepository + WorkspaceIndexRepository> ForgeWorkspaceS
7171
where
7272
F: WorkspaceIndexRepository,
7373
{
74-
info!("Fetching existing file hashes from server to detect changes...");
74+
info!(workspace_id = %workspace_id, "Fetching existing file hashes from server to detect changes...");
7575
let workspace_files =
7676
forge_domain::CodeBase::new(user_id.clone(), workspace_id.clone(), ());
7777

@@ -120,7 +120,7 @@ impl<F: 'static + ProviderRepository + WorkspaceIndexRepository> ForgeWorkspaceS
120120
.await?;
121121

122122
for path in &files_to_delete {
123-
info!(path = %path, "File deleted successfully");
123+
info!(workspace_id = %workspace_id, path = %path, "File deleted successfully");
124124
}
125125

126126
Ok(files_to_delete.len())
@@ -177,10 +177,10 @@ impl<F: 'static + ProviderRepository + WorkspaceIndexRepository> ForgeWorkspaceS
177177
let token = token.clone();
178178
let file_path = file.path.clone();
179179
async move {
180-
info!(path = %file_path, "File sync started");
180+
info!(workspace_id = %workspace_id, path = %file_path, "File sync started");
181181
self.upload(&user_id, &workspace_id, &token, vec![file])
182182
.await?;
183-
info!(path = %file_path, "File sync completed");
183+
info!(workspace_id = %workspace_id, path = %file_path, "File sync completed");
184184
Ok::<_, anyhow::Error>(1)
185185
}
186186
})
@@ -221,7 +221,10 @@ impl<F: 'static + ProviderRepository + WorkspaceIndexRepository> ForgeWorkspaceS
221221
workspace_id: workspace_id.clone(),
222222
})
223223
.await;
224-
let local_files: Vec<FileNode> = self.read_files(batch_size, &path).try_concat().await?;
224+
let local_files: Vec<FileNode> = self
225+
.read_files(batch_size, &path, &workspace_id)
226+
.try_concat()
227+
.await?;
225228
let total_file_count = local_files.len();
226229
emit(SyncProgress::FilesDiscovered { count: total_file_count }).await;
227230

@@ -283,7 +286,7 @@ impl<F: 'static + ProviderRepository + WorkspaceIndexRepository> ForgeWorkspaceS
283286
emit(counter.sync_progress()).await;
284287
}
285288
Err(e) => {
286-
warn!("Failed to delete files during sync: {:#}", e);
289+
warn!(workspace_id = %workspace_id, error = %e,"Failed to delete files during sync");
287290
failed_files += files_to_delete.len();
288291
}
289292
}
@@ -300,7 +303,7 @@ impl<F: 'static + ProviderRepository + WorkspaceIndexRepository> ForgeWorkspaceS
300303
emit(counter.sync_progress()).await;
301304
}
302305
Err(e) => {
303-
warn!("Failed to upload file during sync: {:#}", e);
306+
warn!(workspace_id = %workspace_id, error = %e, "Failed to upload file during sync");
304307
failed_files += 1;
305308
// Continue processing remaining uploads
306309
}
@@ -460,18 +463,20 @@ impl<F: 'static + ProviderRepository + WorkspaceIndexRepository> ForgeWorkspaceS
460463
&self,
461464
batch_size: usize,
462465
dir_path: &Path,
466+
workspace_id: &WorkspaceId,
463467
) -> impl Stream<Item = Result<Vec<FileNode>>> + Send
464468
where
465469
F: FileReaderInfra + EnvironmentInfra + CommandInfra,
466470
{
467471
let dir_path = dir_path.to_path_buf();
468472
let infra = self.infra.clone();
469473
let service = self.clone();
474+
let workspace_id = workspace_id.clone();
470475

471476
async_stream::stream! {
472-
info!("Discovering files for sync via git ls-files");
477+
info!(workspace_id = %workspace_id, "Discovering files for sync via git ls-files");
473478
let walked_files: Vec<WalkedFile> = service.git_ls_files(&dir_path).await?;
474-
info!(file_count = walked_files.len(), "Discovered files via git ls-files");
479+
info!(workspace_id = %workspace_id, file_count = walked_files.len(), "Discovered files via git ls-files");
475480

476481
// Filter files by allowed extension (pure function, no I/O)
477482
let filtered_files: Vec<_> = walked_files
@@ -483,6 +488,7 @@ impl<F: 'static + ProviderRepository + WorkspaceIndexRepository> ForgeWorkspaceS
483488
.collect();
484489

485490
info!(
491+
workspace_id = %workspace_id,
486492
filtered_count = filtered_files.len(),
487493
"Files after extension filtering"
488494
);
@@ -514,7 +520,7 @@ impl<F: 'static + ProviderRepository + WorkspaceIndexRepository> ForgeWorkspaceS
514520
yield Ok(file_nodes);
515521
}
516522
Err(e) => {
517-
warn!(error = ?e, "Failed to read file batch");
523+
warn!(workspace_id = %workspace_id, error = ?e, "Failed to read file batch");
518524
yield Err(e);
519525
}
520526
}
@@ -708,7 +714,7 @@ impl<
708714

709715
let batch_size = self.infra.get_environment().max_file_read_batch_size;
710716
let local_files: Vec<FileNode> = self
711-
.read_files(batch_size, &canonical_path)
717+
.read_files(batch_size, &canonical_path, &workspace.workspace_id)
712718
.try_concat()
713719
.await?;
714720

0 commit comments

Comments
 (0)