Add attributed exec process lifecycle telemetry (#42373)

## Why

Exec-server process and network-policy events need stable attribution to the
launching tool call and executor without recording process payloads.

## What changed

- Add optional `ExecMetadata` to `ExecParams` and propagate the thread and tool
  call IDs from unified exec.
- Emit bounded OpenTelemetry events for process start, spawn failure, sandbox
  denial, and exit. Correlate them with the launch trace and registry-issued
  executor identity while excluding arguments, paths, environment values,
  output, and error text.
- Preserve launch attribution across long-running processes and reconnects, and
  attach the same metadata to network-policy audit events.
- Keep the protocol backward compatible when metadata is omitted, and prevent
  invalid trace headers from inheriting an unrelated active span.

## Testing

Add coverage for metadata serialization and propagation, lifecycle event
fields, trace relationships, reconnect behavior, spawn failures, sandbox
denials, and network-policy attribution.

GitOrigin-RevId: 7aa480a7289c73cb95e2c124c35500bb6f0d5084
This commit is contained in:
viyatb-oai
2026-09-02 21:58:58 +00:00
committed by copyberry
parent 5037919777
commit f53c91be2c
47 changed files with 1461 additions and 178 deletions
+20 -2
View File
@@ -6,6 +6,7 @@ use std::sync::atomic::Ordering;
use codex_exec_server_protocol::JSONRPCErrorError;
use codex_exec_server_protocol::RequestId;
use codex_http_client::HttpClientFactory;
use opentelemetry::trace::SpanContext;
use serde_json::to_value;
use std::collections::HashSet;
use tokio::sync::Mutex;
@@ -69,8 +70,10 @@ use crate::rpc::invalid_request;
use crate::server::file_system_handler::FileSystemHandler;
use crate::server::session_registry::SessionHandle;
use crate::server::session_registry::SessionRegistry;
use crate::telemetry::ExecutorRegistration;
pub(crate) struct ExecServerHandler {
pub(super) executor_registration: Option<Arc<ExecutorRegistration>>,
session_registry: Arc<SessionRegistry>,
notifications: RpcNotificationSender,
session: StdMutex<Option<SessionHandle>>,
@@ -92,6 +95,7 @@ impl ExecServerHandler {
http_client_factory: HttpClientFactory,
) -> Self {
Self {
executor_registration: None,
session_registry,
notifications,
session: StdMutex::new(None),
@@ -172,9 +176,23 @@ impl ExecServerHandler {
Ok(())
}
pub(crate) async fn exec(&self, params: ExecParams) -> Result<ExecResponse, JSONRPCErrorError> {
pub(crate) async fn exec(
&self,
params: ExecParams,
launch_context: Option<SpanContext>,
) -> Result<ExecResponse, JSONRPCErrorError> {
let session = self.require_initialized_for("exec")?;
session.process().exec(params).await
session
.process()
.exec(
params,
crate::process_telemetry::ProcessTelemetry {
launch_context,
executor_registration: self.executor_registration.clone(),
..Default::default()
},
)
.await
}
pub(crate) fn environment_info(&self) -> Result<EnvironmentInfo, JSONRPCErrorError> {