From 900b1e4cec1c4eada106a8071fc89c11c50de9a6 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 8 Sep 2026 20:51:27 +0000 Subject: [PATCH] Add tracing for project instructions and filesystem sandbox operations (#43913) ## What changed Add tracing spans for `AGENTS.md` discovery and loading, local file reads and metadata lookups, and filesystem sandbox request preparation and execution. Record the instruction byte limit, whether file operations use the sandbox, and the permission entry count during sandbox preparation, while skipping automatic argument capture. GitOrigin-RevId: a6aab1cbac975f8042ce48d6a238c48816f7bd77 --- codex-rs/core/src/agents_md.rs | 2 ++ codex-rs/exec-server/src/fs_sandbox.rs | 8 ++++++++ codex-rs/exec-server/src/local_file_system.rs | 10 ++++++++++ 3 files changed, 20 insertions(+) diff --git a/codex-rs/core/src/agents_md.rs b/codex-rs/core/src/agents_md.rs index 644407dd99..431834e1da 100644 --- a/codex-rs/core/src/agents_md.rs +++ b/codex-rs/core/src/agents_md.rs @@ -118,6 +118,7 @@ pub(crate) async fn load_project_instructions( /// discovered doc. If no documentation file is found the function returns /// `Ok(None)`. Unexpected I/O failures bubble up as `Err` so callers can /// decide how to handle them. +#[tracing::instrument(name = "agents_md.load", skip_all, fields(max_total = max_total))] async fn read_agents_md( config: &Config, fs: &dyn ExecutorFileSystem, @@ -184,6 +185,7 @@ async fn read_agents_md( /// Discovers AGENTS.md files from the project root to the current working /// directory, inclusive. Symlinks are allowed. +#[tracing::instrument(name = "agents_md.discover", skip_all)] async fn agents_md_paths( config: &Config, cwd: &PathUri, diff --git a/codex-rs/exec-server/src/fs_sandbox.rs b/codex-rs/exec-server/src/fs_sandbox.rs index 2d80b6ff2b..cd7c311267 100644 --- a/codex-rs/exec-server/src/fs_sandbox.rs +++ b/codex-rs/exec-server/src/fs_sandbox.rs @@ -73,6 +73,7 @@ impl FileSystemSandboxRunner { } } + #[tracing::instrument(name = "fs.sandbox_request", skip_all)] pub(crate) async fn run( &self, sandbox: &FileSystemSandboxContext, @@ -83,6 +84,11 @@ impl FileSystemSandboxRunner { run_command(command, request_json).await } + #[tracing::instrument( + name = "fs.sandbox_prepare", + skip_all, + fields(permission_entries = tracing::field::Empty) + )] pub(crate) fn sandbox_command( &self, sandbox: &FileSystemSandboxContext, @@ -101,6 +107,7 @@ impl FileSystemSandboxRunner { let native_permissions = native_permissions.materialize_project_roots_with_workspace_roots(workspace_roots); let mut file_system_policy = native_permissions.file_system_sandbox_policy(); + tracing::Span::current().record("permission_entries", file_system_policy.entries.len()); let helper_read_roots = if sandbox.use_legacy_landlock { Vec::new() } else { @@ -324,6 +331,7 @@ fn bazel_bwrap_env_key_is_allowed(_key: &str) -> bool { false } +#[tracing::instrument(name = "fs.sandbox_execute", skip_all)] async fn run_command( command: SandboxExecRequest, request_json: Vec, diff --git a/codex-rs/exec-server/src/local_file_system.rs b/codex-rs/exec-server/src/local_file_system.rs index 66a4876d45..63048da72a 100644 --- a/codex-rs/exec-server/src/local_file_system.rs +++ b/codex-rs/exec-server/src/local_file_system.rs @@ -128,6 +128,11 @@ impl LocalFileSystem { file_system.canonicalize(path, sandbox).await } + #[tracing::instrument( + name = "fs.read_file", + skip_all, + fields(sandboxed = sandbox.is_some_and(FileSystemSandboxContext::should_run_in_sandbox)) + )] async fn read_file( &self, path: &PathUri, @@ -170,6 +175,11 @@ impl LocalFileSystem { file_system.create_directory(path, options, sandbox).await } + #[tracing::instrument( + name = "fs.get_metadata", + skip_all, + fields(sandboxed = sandbox.is_some_and(FileSystemSandboxContext::should_run_in_sandbox)) + )] async fn get_metadata( &self, path: &PathUri,