mirror of
https://github.com/openai/codex.git
synced 2026-11-22 23:00:42 +00:00
Support managed OpenTelemetry configuration requirements (#57649)
## What changed - Allow `requirements.toml` to manage OpenTelemetry logging flags, tool-result byte limits, environment, and log, trace, and metrics exporters. - Apply higher-priority managed values over user configuration, replacing exporters atomically and warning when configured values conflict. Preserve unmanaged settings, including `span_attributes` and `tracestate`. - Expose managed `otel` settings through `configRequirements/read`, apply them in `config/read` without ordinary field origins, and reject configuration writes that overlap managed fields. - Distinguish omitted tool-result limits from explicit values while preserving the runtime default. ## Testing Add coverage for requirement precedence, relative TLS paths, override warnings, managed write protection, effective configuration reads, and exporter serialization through the app-server API. GitOrigin-RevId: 6a3343563bd3acb53a366ea6723684e3d0a4a01d
This commit is contained in:
@@ -1704,6 +1704,54 @@ async fn write_value_rejects_exact_managed_requirement() {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn write_value_rejects_managed_otel_values_and_preserves_unmanaged_siblings() {
|
||||
let tmp = tempdir().expect("tempdir");
|
||||
let path = tmp.path().join(CONFIG_TOML_FILE);
|
||||
std::fs::write(&path, "").expect("write user config");
|
||||
let service = ConfigManager::new_for_tests(
|
||||
tmp.path().to_path_buf(),
|
||||
vec![],
|
||||
LoaderOverrides::without_managed_config_for_tests(),
|
||||
CloudConfigBundleFixture::loader_with_enterprise_requirement(
|
||||
r#"[otel]
|
||||
tool_result = { max_bytes = 1024 }
|
||||
log_user_prompt = false
|
||||
log_agent_responses = true
|
||||
log_guardian_assessments = false
|
||||
exporter = "none"
|
||||
trace_exporter = "none"
|
||||
metrics_exporter = "none""#,
|
||||
),
|
||||
);
|
||||
for (key_path, managed) in [
|
||||
("otel", true),
|
||||
("otel.log_user_prompt", true),
|
||||
("otel.log_agent_responses", true),
|
||||
("otel.log_guardian_assessments", true),
|
||||
("otel.exporter.otlp-http.endpoint", true),
|
||||
("otel.trace_exporter.otlp-grpc.endpoint", true),
|
||||
("otel.metrics_exporter.otlp-http.headers", true),
|
||||
("otel.environment", false),
|
||||
("otel.tool_result.max_bytes", true),
|
||||
] {
|
||||
let result = service
|
||||
.write_value(ConfigValueWriteParams {
|
||||
file_path: Some(path.display().to_string()),
|
||||
key_path: key_path.to_string(),
|
||||
value: serde_json::json!("user"),
|
||||
merge_strategy: MergeStrategy::Replace,
|
||||
expected_version: None,
|
||||
})
|
||||
.await;
|
||||
assert_eq!(
|
||||
result.err().and_then(|error| error.write_error_code()),
|
||||
managed.then_some(ConfigWriteErrorCode::ConfigRequirementReadonly),
|
||||
"OTEL path {key_path}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn toml_path(tmp: &Path, name: &str) -> String {
|
||||
tmp.join(name).to_string_lossy().replace('\\', "\\\\")
|
||||
}
|
||||
@@ -1771,6 +1819,131 @@ enabled = false
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn read_projects_managed_otel_values_and_preserves_unmanaged_settings() {
|
||||
let tmp = tempdir().expect("tempdir");
|
||||
std::fs::write(
|
||||
tmp.path().join(CONFIG_TOML_FILE),
|
||||
r#"[otel]
|
||||
tool_result = { max_bytes = 1234 }
|
||||
log_user_prompt = true
|
||||
environment = "user"
|
||||
exporter = "statsig""#,
|
||||
)
|
||||
.expect("write user config");
|
||||
let service = ConfigManager::new_for_tests(
|
||||
tmp.path().to_path_buf(),
|
||||
vec![],
|
||||
LoaderOverrides::without_managed_config_for_tests(),
|
||||
CloudConfigBundleFixture::loader_with_enterprise_requirement(
|
||||
r#"[otel]
|
||||
log_user_prompt = false
|
||||
exporter = "none""#,
|
||||
),
|
||||
);
|
||||
let response = service
|
||||
.read(ConfigReadParams {
|
||||
include_layers: false,
|
||||
cwd: None,
|
||||
})
|
||||
.await
|
||||
.expect("config read should succeed");
|
||||
let otel = response
|
||||
.config
|
||||
.additional
|
||||
.get("otel")
|
||||
.expect("effective OTEL config");
|
||||
assert_eq!(
|
||||
otel,
|
||||
&serde_json::json!({
|
||||
"tool_result": { "max_bytes": 1234 },
|
||||
"log_user_prompt": false,
|
||||
"log_agent_responses": null,
|
||||
"log_guardian_assessments": null,
|
||||
"environment": "user",
|
||||
"exporter": "none",
|
||||
"trace_exporter": null,
|
||||
"metrics_exporter": null,
|
||||
"span_attributes": null,
|
||||
"tracestate": null,
|
||||
}),
|
||||
);
|
||||
for (path, user_owned) in [
|
||||
("otel.log_user_prompt", false),
|
||||
("otel.exporter", false),
|
||||
("otel.environment", true),
|
||||
("otel.tool_result.max_bytes", true),
|
||||
] {
|
||||
assert_eq!(response.origins.contains_key(path), user_owned, "{path}");
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn read_projects_managed_otel_tool_result_and_omits_its_origin() {
|
||||
let tmp = tempdir().expect("tempdir");
|
||||
std::fs::write(
|
||||
tmp.path().join(CONFIG_TOML_FILE),
|
||||
r#"[otel]
|
||||
tool_result = { max_bytes = 1234 }"#,
|
||||
)
|
||||
.expect("write user config");
|
||||
let service = ConfigManager::new_for_tests(
|
||||
tmp.path().to_path_buf(),
|
||||
vec![],
|
||||
LoaderOverrides::without_managed_config_for_tests(),
|
||||
CloudConfigBundleFixture::loader_with_enterprise_requirement(
|
||||
r#"[otel]
|
||||
tool_result = { max_bytes = 4096 }"#,
|
||||
),
|
||||
);
|
||||
|
||||
let response = service
|
||||
.read(ConfigReadParams {
|
||||
include_layers: false,
|
||||
cwd: None,
|
||||
})
|
||||
.await
|
||||
.expect("config read should succeed");
|
||||
assert_eq!(
|
||||
response
|
||||
.config
|
||||
.additional
|
||||
.get("otel")
|
||||
.and_then(|otel| otel.get("tool_result")),
|
||||
Some(&serde_json::json!({ "max_bytes": 4096 }))
|
||||
);
|
||||
assert!(!response.origins.contains_key("otel.tool_result.max_bytes"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn read_keeps_omitted_otel_tool_result_unset() {
|
||||
let tmp = tempdir().expect("tempdir");
|
||||
std::fs::write(
|
||||
tmp.path().join(CONFIG_TOML_FILE),
|
||||
r#"[otel]
|
||||
environment = "user""#,
|
||||
)
|
||||
.expect("write user config");
|
||||
|
||||
let service = ConfigManager::without_managed_config_for_tests(tmp.path().to_path_buf());
|
||||
let response = service
|
||||
.read(ConfigReadParams {
|
||||
include_layers: false,
|
||||
cwd: None,
|
||||
})
|
||||
.await
|
||||
.expect("config read should succeed");
|
||||
|
||||
assert_eq!(
|
||||
response
|
||||
.config
|
||||
.additional
|
||||
.get("otel")
|
||||
.and_then(|otel| otel.get("tool_result")),
|
||||
Some(&serde_json::Value::Null)
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn read_materializes_default_allow_login_shell() {
|
||||
let tmp = tempdir().expect("tempdir");
|
||||
|
||||
@@ -136,6 +136,7 @@ mod model_catalog;
|
||||
mod models;
|
||||
mod models_refresh_worker;
|
||||
mod notification_media;
|
||||
mod otel_config;
|
||||
mod otel_reloader;
|
||||
mod outgoing_message;
|
||||
mod plugin_config_reload;
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
//! Maps OTEL requirements into app-server responses.
|
||||
|
||||
use codex_app_server_protocol::OtelExporter;
|
||||
use codex_app_server_protocol::OtelHttpProtocol;
|
||||
use codex_app_server_protocol::OtelRequirements;
|
||||
use codex_app_server_protocol::OtelTlsConfig;
|
||||
use codex_app_server_protocol::OtelToolResultLogConfig;
|
||||
use codex_config::OtelRequirementsToml;
|
||||
use codex_config::types::OtelExporterKind;
|
||||
use codex_config::types::OtelHttpProtocol as CoreOtelHttpProtocol;
|
||||
use codex_config::types::OtelTlsConfig as CoreOtelTlsConfig;
|
||||
|
||||
pub(crate) fn map_otel_requirements_to_api(otel: OtelRequirementsToml) -> OtelRequirements {
|
||||
OtelRequirements {
|
||||
tool_result: otel.tool_result.map(|value| OtelToolResultLogConfig {
|
||||
max_bytes: value.max_bytes,
|
||||
}),
|
||||
log_user_prompt: otel.log_user_prompt,
|
||||
log_agent_responses: otel.log_agent_responses,
|
||||
log_guardian_assessments: otel.log_guardian_assessments,
|
||||
environment: otel.environment,
|
||||
exporter: otel.exporter.map(map_otel_exporter_to_api),
|
||||
trace_exporter: otel.trace_exporter.map(map_otel_exporter_to_api),
|
||||
metrics_exporter: otel.metrics_exporter.map(map_otel_exporter_to_api),
|
||||
}
|
||||
}
|
||||
|
||||
fn map_otel_exporter_to_api(exporter: OtelExporterKind) -> OtelExporter {
|
||||
match exporter {
|
||||
OtelExporterKind::None => OtelExporter::None,
|
||||
OtelExporterKind::Statsig => OtelExporter::Statsig,
|
||||
OtelExporterKind::OtlpHttp {
|
||||
endpoint,
|
||||
headers,
|
||||
protocol,
|
||||
tls,
|
||||
} => OtelExporter::OtlpHttp {
|
||||
endpoint,
|
||||
headers,
|
||||
protocol: match protocol {
|
||||
CoreOtelHttpProtocol::Binary => OtelHttpProtocol::Binary,
|
||||
CoreOtelHttpProtocol::Json => OtelHttpProtocol::Json,
|
||||
},
|
||||
tls: tls.map(map_otel_tls_to_api),
|
||||
},
|
||||
OtelExporterKind::OtlpGrpc {
|
||||
endpoint,
|
||||
headers,
|
||||
tls,
|
||||
} => OtelExporter::OtlpGrpc {
|
||||
endpoint,
|
||||
headers,
|
||||
tls: tls.map(map_otel_tls_to_api),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn map_otel_tls_to_api(tls: CoreOtelTlsConfig) -> OtelTlsConfig {
|
||||
OtelTlsConfig {
|
||||
ca_certificate: tls.ca_certificate.map(Into::into),
|
||||
client_certificate: tls.client_certificate.map(Into::into),
|
||||
client_private_key: tls.client_private_key.map(Into::into),
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use crate::config_manager_service::ConfigManagerError;
|
||||
use crate::error_code::internal_error;
|
||||
use crate::error_code::invalid_request;
|
||||
use crate::model_catalog::ModelCatalog;
|
||||
use crate::otel_config::map_otel_requirements_to_api;
|
||||
use crate::outgoing_message::ConnectionRequestId;
|
||||
use crate::outgoing_message::OutgoingMessageSender;
|
||||
use codex_analytics::AnalyticsEventsClient;
|
||||
@@ -591,7 +592,9 @@ pub(crate) fn map_requirements_to_api(
|
||||
service_tier: new_thread.service_tier,
|
||||
}),
|
||||
}),
|
||||
otel: None,
|
||||
otel: requirements
|
||||
.otel
|
||||
.map(|otel| map_otel_requirements_to_api(*otel)),
|
||||
sqlite_home: requirements.sqlite_home.map(Into::into),
|
||||
log_dir: requirements.log_dir.map(Into::into),
|
||||
model_catalog_json: requirements.model_catalog_json.map(Into::into),
|
||||
|
||||
@@ -351,7 +351,8 @@ impl TurnRequestProcessor {
|
||||
)
|
||||
.await;
|
||||
}
|
||||
self.review_start_inner(request_id, params)
|
||||
// Keep review setup from inflating the shared request dispatcher's stack frame.
|
||||
Box::pin(self.review_start_inner(request_id, params))
|
||||
.await
|
||||
.map(|()| None)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user