mirror of
https://github.com/openai/codex.git
synced 2026-11-08 16:38:30 +00:00
Add MCP server context to otel tool_result logs (#12267)
Summary - capture the origin for each configured MCP server and expose it via the connection manager - plumb MCP server name/origin into tool logging and emit codex.tool_result events with those fields - add unit coverage for origin parsing and extend OTEL tests to assert empty MCP fields for non-MCP tools - currently not logging full urls or url paths to prevent logging potentially sensitive data Testing - Not run (not requested)
This commit is contained in:
1 parent
ede561b5d1
commit
2036a5f5e0
5 files changed
+148
No files matched your search
@@ -588,12 +588,15 @@ impl OtelManager {
|
||||
);
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn log_tool_result_with_tags<F, Fut, E>(
|
||||
&self,
|
||||
tool_name: &str,
|
||||
call_id: &str,
|
||||
arguments: &str,
|
||||
extra_tags: &[(&str, &str)],
|
||||
mcp_server: Option<&str>,
|
||||
mcp_server_origin: Option<&str>,
|
||||
f: F,
|
||||
) -> Result<(String, bool), E>
|
||||
where
|
||||
@@ -618,6 +621,8 @@ impl OtelManager {
|
||||
success,
|
||||
output.as_ref(),
|
||||
extra_tags,
|
||||
mcp_server,
|
||||
mcp_server_origin,
|
||||
);
|
||||
|
||||
result
|
||||
@@ -641,6 +646,8 @@ impl OtelManager {
|
||||
duration_ms = %Duration::ZERO.as_millis(),
|
||||
success = %false,
|
||||
output = %error,
|
||||
mcp_server = "",
|
||||
mcp_server_origin = "",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -654,6 +661,8 @@ impl OtelManager {
|
||||
success: bool,
|
||||
output: &str,
|
||||
extra_tags: &[(&str, &str)],
|
||||
mcp_server: Option<&str>,
|
||||
mcp_server_origin: Option<&str>,
|
||||
) {
|
||||
let success_str = if success { "true" } else { "false" };
|
||||
let mut tags = Vec::with_capacity(2 + extra_tags.len());
|
||||
@@ -662,6 +671,8 @@ impl OtelManager {
|
||||
tags.extend_from_slice(extra_tags);
|
||||
self.counter(TOOL_CALL_COUNT_METRIC, 1, &tags);
|
||||
self.record_duration(TOOL_CALL_DURATION_METRIC, duration, &tags);
|
||||
let mcp_server = mcp_server.unwrap_or("");
|
||||
let mcp_server_origin = mcp_server_origin.unwrap_or("");
|
||||
tracing::event!(
|
||||
tracing::Level::INFO,
|
||||
event.name = "codex.tool_result",
|
||||
@@ -681,6 +692,8 @@ impl OtelManager {
|
||||
duration_ms = %duration.as_millis(),
|
||||
success = %success_str,
|
||||
output = %output,
|
||||
mcp_server = %mcp_server,
|
||||
mcp_server_origin = %mcp_server_origin,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user