Skip to content

Add MCP connector metrics#15805

Merged
nicholasclark-openai merged 7 commits intomainfrom
nicholasclark/2026-03-25-mcp-metrics
Mar 26, 2026
Merged

Add MCP connector metrics#15805
nicholasclark-openai merged 7 commits intomainfrom
nicholasclark/2026-03-25-mcp-metrics

Conversation

@nicholasclark-openai
Copy link
Copy Markdown
Contributor

@nicholasclark-openai nicholasclark-openai commented Mar 25, 2026

Summary

  • enrich codex.mcp.call with tool, connector_id, and sanitized connector_name for actual MCP executions
  • record codex.mcp.call.duration_ms for actual MCP executions so connector-level latency is visible in metrics
  • keep skipped, blocked, declined, and cancelled paths on the plain status-only codex.mcp.call counter

Included Changes

  • codex-rs/core/src/mcp_tool_call.rs: add connector-sliced MCP count and duration metrics only for executed tool calls, while leaving non-executed outcomes as status-only counts
  • codex-rs/core/src/mcp_tool_call_tests.rs: cover metric tag shaping, connector-name sanitization, and the new duration metric tags

Testing

  • cargo test -p codex-core
  • just fix -p codex-core
  • just fmt

Notes

  • cargo test -p codex-core still hits existing unrelated failures in approvals-reviewer config tests and the sandboxed JS REPL mktemp test
  • full workspace cargo test was not run

@nicholasclark-openai nicholasclark-openai changed the base branch from nicholasclark/2026-03-23-server-spans to main March 25, 2026 22:35
@nicholasclark-openai nicholasclark-openai changed the base branch from main to nicholasclark/2026-03-23-server-spans March 25, 2026 23:13
@nicholasclark-openai nicholasclark-openai changed the base branch from nicholasclark/2026-03-23-server-spans to main March 25, 2026 23:31
@nicholasclark-openai nicholasclark-openai force-pushed the nicholasclark/2026-03-25-mcp-metrics branch from c6b4fbf to a445016 Compare March 25, 2026 23:43
@nicholasclark-openai nicholasclark-openai marked this pull request as ready for review March 26, 2026 00:13
tag_refs.as_slice()
} else {
status_only_tags.as_slice()
};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is pretty messy. looks like this complexity is due to conditionally applying tags. for codex.mcp.call, can we always tag it with status, tool, connector_id, connector_name?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and reuse the same tags for both metrics?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was done to not pollute metrics for tool calls that didn't execute declines/safety/other, but agree it just makes things messy. I'll just skip the duration metric if we didn't execute and keep the tags the same (with status) otherwise

nicholasclark-openai and others added 4 commits March 25, 2026 17:58
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Copy link
Copy Markdown
Collaborator

@owenlin0 owenlin0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much cleaner, ty!

turn_context
.session_telemetry
.counter("codex.mcp.call", /*inc*/ 1, &[("status", status)]);
.record_duration(MCP_CALL_DURATION_METRIC, duration, &tag_refs);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: looks like we do this in another place above, we could extract this into a helper function

Co-authored-by: Codex <noreply@openai.com>
@nicholasclark-openai nicholasclark-openai enabled auto-merge (squash) March 26, 2026 16:46
@nicholasclark-openai nicholasclark-openai merged commit 8d479f7 into main Mar 26, 2026
36 checks passed
@nicholasclark-openai nicholasclark-openai deleted the nicholasclark/2026-03-25-mcp-metrics branch March 26, 2026 17:08
@github-actions github-actions bot locked and limited conversation to collaborators Mar 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants