Add bounded plugin measurement analytics (#38239)

## What changed

- Add `PluginMeasurementsInput` and `PluginMeasurementRow`, plus an analytics
  client method for recording batches and checking whether analytics are enabled.
- Emit each valid row as a `codex_plugin_measurement_event` with thread, turn,
  item, plugin, execution, and operation context.
- Bound batches at 100 rows and reject non-finite values, invalid identifiers,
  and rows with more than eight dimensions.
- Treat measurement events as plugin events when routing API-key analytics.

## Testing

- Cover batch limits, row filtering, serialized event payloads, and API-key
  plugin-event routing.

GitOrigin-RevId: f949ed06246ee1e22466df2660076f2d4f556444
This commit is contained in:
Kyle Brown authored and copyberry committed 2026-08-12 19:14:09 +00:00
1 parent dc8562d672
commit d6eefb26a6
7 files changed
+318

No files matched your search

+24
View File
@@ -22,6 +22,7 @@ use crate::facts::PluginInstallFailedInput;
use crate::facts::PluginInstallRequested;
use crate::facts::PluginInstallRequestedInput;
use crate::facts::PluginInstallSource;
use crate::facts::PluginMeasurementsInput;
use crate::facts::PluginState;
use crate::facts::PluginStateChangedInput;
use crate::facts::SkillInvocation;
@@ -34,6 +35,9 @@ use crate::facts::TurnResolvedConfigFact;
use crate::facts::TurnTokenUsageFact;
use crate::now_unix_millis;
use crate::reducer::AnalyticsReducer;
use crate::reducer::MAX_PLUGIN_MEASUREMENTS_PER_BATCH;
use crate::reducer::valid_plugin_measurement_identifier;
use crate::reducer::valid_plugin_measurement_row;
use codex_app_server_protocol::ClientRequest;
use codex_app_server_protocol::ClientResponsePayload;
use codex_app_server_protocol::InitializeParams;
@@ -255,6 +259,26 @@ impl AnalyticsEventsClient {
}
}
pub fn is_enabled(&self) -> bool {
self.queue.is_some()
}
pub fn track_plugin_measurements(&self, mut input: PluginMeasurementsInput) {
if input.rows.is_empty()
|| input.rows.len() > MAX_PLUGIN_MEASUREMENTS_PER_BATCH
|| !valid_plugin_measurement_identifier(&input.operation)
{
return;
}
input.rows.retain(valid_plugin_measurement_row);
if input.rows.is_empty() {
return;
}
self.record_fact(AnalyticsFact::Custom(
CustomAnalyticsFact::PluginMeasurements(input),
));
}
pub fn track_skill_invocations(
&self,
tracking: TrackEventsContext,