This commit is contained in:
alexsong-oai
2026-03-25 18:50:03 -07:00
parent 1fac4b3be6
commit 1f615494c8
2 changed files with 16 additions and 72 deletions

View File

@@ -291,27 +291,6 @@ impl TrackEventsJob {
}
}
fn job_type_for_event(event: &TrackEventRequest) -> &'static str {
match event {
TrackEventRequest::SkillInvocation(_) => SKILL_INVOCATIONS_JOB_TYPE,
TrackEventRequest::AppMentioned(_) => APP_MENTIONED_JOB_TYPE,
TrackEventRequest::AppUsed(_) => APP_USED_JOB_TYPE,
TrackEventRequest::PluginUsed(_) => PLUGIN_USED_JOB_TYPE,
TrackEventRequest::PluginInstalled(_) => PLUGIN_INSTALLED_JOB_TYPE,
TrackEventRequest::PluginUninstalled(_) => PLUGIN_UNINSTALLED_JOB_TYPE,
TrackEventRequest::PluginEnabled(_) => PLUGIN_ENABLED_JOB_TYPE,
TrackEventRequest::PluginDisabled(_) => PLUGIN_DISABLED_JOB_TYPE,
}
}
fn event_counts_by_job_type(events: &[TrackEventRequest]) -> BTreeMap<&'static str, usize> {
let mut counts = BTreeMap::new();
for event in events {
*counts.entry(job_type_for_event(event)).or_insert(0) += 1;
}
counts
}
fn emit_analytics_events_failure_counters(
reason: &'static str,
job_type: &'static str,
@@ -337,7 +316,22 @@ fn emit_analytics_events_failure_counters_for_events(
events: &[TrackEventRequest],
extra_tags: &[(&str, &str)],
) {
for (job_type, event_count) in event_counts_by_job_type(events) {
let mut counts = BTreeMap::new();
for event in events {
let job_type = match event {
TrackEventRequest::SkillInvocation(_) => SKILL_INVOCATIONS_JOB_TYPE,
TrackEventRequest::AppMentioned(_) => APP_MENTIONED_JOB_TYPE,
TrackEventRequest::AppUsed(_) => APP_USED_JOB_TYPE,
TrackEventRequest::PluginUsed(_) => PLUGIN_USED_JOB_TYPE,
TrackEventRequest::PluginInstalled(_) => PLUGIN_INSTALLED_JOB_TYPE,
TrackEventRequest::PluginUninstalled(_) => PLUGIN_UNINSTALLED_JOB_TYPE,
TrackEventRequest::PluginEnabled(_) => PLUGIN_ENABLED_JOB_TYPE,
TrackEventRequest::PluginDisabled(_) => PLUGIN_DISABLED_JOB_TYPE,
};
*counts.entry(job_type).or_insert(0) += 1;
}
for (job_type, event_count) in counts {
emit_analytics_events_failure_counters(reason, job_type, event_count, extra_tags);
}
}

View File

@@ -24,7 +24,6 @@ use crate::plugins::PluginId;
use crate::plugins::PluginTelemetryMetadata;
use pretty_assertions::assert_eq;
use serde_json::json;
use std::collections::BTreeMap;
use std::collections::HashSet;
use std::path::PathBuf;
use std::sync::Arc;
@@ -420,55 +419,6 @@ fn track_events_job_event_count_matches_underlying_payloads() {
assert_eq!(plugin_job.event_count(), 1);
}
#[test]
fn event_counts_by_job_type_groups_mixed_events() {
let tracking = TrackEventsContext {
model_slug: "gpt-5".to_string(),
thread_id: "thread-1".to_string(),
turn_id: "turn-1".to_string(),
};
let events = vec![
TrackEventRequest::AppMentioned(CodexAppMentionedEventRequest {
event_type: "codex_app_mentioned",
event_params: codex_app_metadata(
&tracking,
AppInvocation {
connector_id: Some("drive".to_string()),
app_name: Some("Drive".to_string()),
invocation_type: Some(InvocationType::Explicit),
},
),
}),
TrackEventRequest::AppUsed(CodexAppUsedEventRequest {
event_type: "codex_app_used",
event_params: codex_app_metadata(
&tracking,
AppInvocation {
connector_id: Some("calendar".to_string()),
app_name: Some("Calendar".to_string()),
invocation_type: Some(InvocationType::Implicit),
},
),
}),
TrackEventRequest::AppMentioned(CodexAppMentionedEventRequest {
event_type: "codex_app_mentioned",
event_params: codex_app_metadata(
&tracking,
AppInvocation {
connector_id: Some("gmail".to_string()),
app_name: Some("Gmail".to_string()),
invocation_type: None,
},
),
}),
];
assert_eq!(
super::event_counts_by_job_type(&events),
BTreeMap::from([("app_mentioned", 2), ("app_used", 1)])
);
}
fn sample_plugin_metadata() -> PluginTelemetryMetadata {
PluginTelemetryMetadata {
plugin_id: PluginId::parse("sample@test").expect("valid plugin id"),