mirror of
https://github.com/openai/codex.git
synced 2026-11-07 16:35:32 +00:00
feat: add a few metrics (#8910)
This commit is contained in:
1 parent
98e171258c
commit
5522663f92
5 files changed
+59
-25
No files matched your search
@@ -645,6 +645,18 @@ impl Session {
|
|||||||
session_configuration.session_source.clone(),
|
session_configuration.session_source.clone(),
|
||||||
);
|
);
|
||||||
config.features.emit_metrics(&otel_manager);
|
config.features.emit_metrics(&otel_manager);
|
||||||
|
otel_manager.counter(
|
||||||
|
"codex.session.started",
|
||||||
|
1,
|
||||||
|
&[(
|
||||||
|
"is_git",
|
||||||
|
if get_git_repo_root(&session_configuration.cwd).is_some() {
|
||||||
|
"true"
|
||||||
|
} else {
|
||||||
|
"false"
|
||||||
|
},
|
||||||
|
)],
|
||||||
|
);
|
||||||
|
|
||||||
otel_manager.conversation_starts(
|
otel_manager.conversation_starts(
|
||||||
config.model_provider.name.as_str(),
|
config.model_provider.name.as_str(),
|
||||||
@@ -1757,6 +1769,7 @@ mod handlers {
|
|||||||
use codex_protocol::protocol::TurnAbortReason;
|
use codex_protocol::protocol::TurnAbortReason;
|
||||||
use codex_protocol::protocol::WarningEvent;
|
use codex_protocol::protocol::WarningEvent;
|
||||||
|
|
||||||
|
use crate::context_manager::is_user_turn_boundary;
|
||||||
use codex_protocol::user_input::UserInput;
|
use codex_protocol::user_input::UserInput;
|
||||||
use codex_rmcp_client::ElicitationAction;
|
use codex_rmcp_client::ElicitationAction;
|
||||||
use codex_rmcp_client::ElicitationResponse;
|
use codex_rmcp_client::ElicitationResponse;
|
||||||
@@ -2111,6 +2124,18 @@ mod handlers {
|
|||||||
.terminate_all_processes()
|
.terminate_all_processes()
|
||||||
.await;
|
.await;
|
||||||
info!("Shutting down Codex instance");
|
info!("Shutting down Codex instance");
|
||||||
|
let turn_count = sess
|
||||||
|
.clone_history()
|
||||||
|
.await
|
||||||
|
.get_history()
|
||||||
|
.iter()
|
||||||
|
.filter(|item| is_user_turn_boundary(item))
|
||||||
|
.count();
|
||||||
|
sess.services.otel_manager.counter(
|
||||||
|
"conversation.turn.count",
|
||||||
|
i64::try_from(turn_count).unwrap_or(0),
|
||||||
|
&[],
|
||||||
|
);
|
||||||
|
|
||||||
// Gracefully flush and shutdown rollout recorder on session end so tests
|
// Gracefully flush and shutdown rollout recorder on session end so tests
|
||||||
// that inspect the rollout file do not race with the background writer.
|
// that inspect the rollout file do not race with the background writer.
|
||||||
@@ -2834,6 +2859,7 @@ pub(super) fn get_last_assistant_message_from_turn(responses: &[ResponseItem]) -
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) use tests::make_session_and_context;
|
pub(crate) use tests::make_session_and_context;
|
||||||
|
|
||||||
|
use crate::git_info::get_git_repo_root;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) use tests::make_session_and_context_with_rx;
|
pub(crate) use tests::make_session_and_context_with_rx;
|
||||||
|
|
||||||
|
|||||||
@@ -332,7 +332,7 @@ fn is_session_prefix(text: &str) -> bool {
|
|||||||
lowered.starts_with("<environment_context>")
|
lowered.starts_with("<environment_context>")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_user_turn_boundary(item: &ResponseItem) -> bool {
|
pub(crate) fn is_user_turn_boundary(item: &ResponseItem) -> bool {
|
||||||
let ResponseItem::Message { role, content, .. } = item else {
|
let ResponseItem::Message { role, content, .. } = item else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,3 +2,4 @@ mod history;
|
|||||||
mod normalize;
|
mod normalize;
|
||||||
|
|
||||||
pub(crate) use history::ContextManager;
|
pub(crate) use history::ContextManager;
|
||||||
|
pub(crate) use history::is_user_turn_boundary;
|
||||||
@@ -29,16 +29,18 @@ impl SessionTask for CompactTask {
|
|||||||
session.as_ref(),
|
session.as_ref(),
|
||||||
&ctx.client.get_provider(),
|
&ctx.client.get_provider(),
|
||||||
) {
|
) {
|
||||||
let _ = session
|
let _ = session.services.otel_manager.counter(
|
||||||
.services
|
"codex.task.compact",
|
||||||
.otel_manager
|
1,
|
||||||
.counter("codex.task.compact.remote", 1, &[]);
|
&[("type", "remote")],
|
||||||
|
);
|
||||||
crate::compact_remote::run_remote_compact_task(session, ctx).await
|
crate::compact_remote::run_remote_compact_task(session, ctx).await
|
||||||
} else {
|
} else {
|
||||||
let _ = session
|
let _ = session.services.otel_manager.counter(
|
||||||
.services
|
"codex.task.compact",
|
||||||
.otel_manager
|
1,
|
||||||
.counter("codex.task.compact.local", 1, &[]);
|
&[("type", "local")],
|
||||||
|
);
|
||||||
crate::compact::run_compact_task(session, ctx, input).await
|
crate::compact::run_compact_task(session, ctx, input).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+21
-16
@@ -29,20 +29,25 @@ This section list all the metrics exported by Codex when locally installed.
|
|||||||
|
|
||||||
## Metrics catalog
|
## Metrics catalog
|
||||||
|
|
||||||
Each metric includes the required fields plus the global context above.
|
Each metric includes the required fields plus the global context above. Every metrics are prefixed by `codex.`.
|
||||||
|
|
||||||
| Metric | Type | Fields | Description |
|
| Metric | Type | Fields | Description |
|
||||||
| ------------------------- | --------- | ------------------------------------- | ------------------------------------------------------------------------------- |
|
| ----------------- | ------- | -------------- | ------------------------------------------------------------------------ |
|
||||||
| `approval.requested` | counter | `tool`, `approved` | Tool approval request result (`approved`: `yes` or `no`). |
|
| `features.state` | counter | `key`, `value` | Feature values that differ from defaults (emit one row per non-default). |
|
||||||
| `auth.completed` | counter | `status` | Authentication completed (only for ChatGPT authentication). |
|
| `session.started` | counter | `is_git` | New session created. |
|
||||||
| `conversation.compact` | counter | `status`, `number` | Compaction event including the status and the compaction number in the session. |
|
| `task.compact` | counter | `type` | Number of compaction per type (`remote` or `local`) |
|
||||||
| `conversation.turn.count` | counter | `role` | User/assistant turns per session. |
|
| `task.user_shell` | counter | | Number of user shell actions (`!` in the TUI for example) |
|
||||||
| `feature.duration_ms` | histogram | `feature`, `status` | End-to-end feature latency. |
|
| `task.review` | counter | | Number of reviews triggered |
|
||||||
| `feature.used` | counter | `feature` | Feature usage through `/` (e.g., `/undo`, `/review`, ...). |
|
| `task.undo` | counter | | Number of undo made |
|
||||||
| `features.state` | counter | `key`, `value` | Feature values that differ from defaults (emit one row per non-default). |
|
|
||||||
| `mcp.call` | counter | `status` | MCP tool invocation result (`ok` or error string). |
|
### Metrics to be added
|
||||||
| `model.call.duration_ms` | histogram | `provider`, `status`, `attempt` | Model API request duration. |
|
|
||||||
| `session.started` | counter | `is_git` | New session created. |
|
| Metric | Type | Fields | Description |
|
||||||
| `tool.call` | counter | `tool`, `status` | Tool invocation result (`ok` or error string). |
|
| ------------------------- | --------- | ------------------------------------- | --------------------------------------------------------- |
|
||||||
| `tool.call.duration_ms` | histogram | `tool`, `status` | Tool execution time. |
|
| `approval.requested` | counter | `tool`, `approved` | Tool approval request result (`approved`: `yes` or `no`). |
|
||||||
| `user.feedback.submitted` | counter | `category`, `include_logs`, `success` | Feedback submission via `/feedback`. |
|
| `conversation.turn.count` | counter | | User/assistant turns per session. |
|
||||||
|
| `mcp.call` | counter | `status` | MCP tool invocation result (`ok` or error string). |
|
||||||
|
| `model.call.duration_ms` | histogram | `provider`, `status`, `attempt` | Model API request duration. |
|
||||||
|
| `tool.call` | counter | `tool`, `status` | Tool invocation result (`ok` or error string). |
|
||||||
|
| `tool.call.duration_ms` | histogram | `tool`, `status` | Tool execution time. |
|
||||||
|
| `user.feedback.submitted` | counter | `category`, `include_logs`, `success` | Feedback submission via `/feedback`. |
|
||||||
Reference in new issue
Block a user