Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Add tracing for project instructions and filesystem sandbox operations (#43913)

Charlie Marsh900b1e4cec1c
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<u8>,
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,