1+ import { AnalyticsEvent } from '../constants/analytics-events'
2+
13/**
24 * Operational events that belong in Axiom but not in product analytics.
35 *
4- * CLI logs normally redact structured info payloads before shipping and also
5- * mirror a sampled `cli_log` event to PostHog. This allowlist lets a small set
6- * of content-free operational events retain useful numeric/string/boolean
7- * metadata in Axiom without becoming product events or providing a general
8- * redaction bypass — each event declares an explicit field allowlist, and
9- * unknown keys or unexpected value types are always discarded.
6+ * This allowlist lets a small set of content-free operational events retain
7+ * useful numeric/string/boolean metadata without becoming product events or
8+ * providing a general redaction bypass. Unknown fields and unexpected value
9+ * types are always discarded.
1010 */
1111
1212export const CONTEXT_PRUNING_COMPLETED_EVENT =
@@ -18,6 +18,7 @@ export const CONTEXT_PRUNING_COMPLETED_EVENT =
1818 * allowlisted event — `_gave_up` logs at error level, which already ships
1919 * raw and doesn't need the allowlist. */
2020export const STREAM_RECOVERY_EVENT = 'stream_recovery' as const
21+ export const ADS_FETCH_COMPLETED_EVENT = AnalyticsEvent . ADS_FETCH_COMPLETED
2122
2223type AxiomOnlyFieldType = 'string' | 'number' | 'boolean'
2324type AxiomOnlyFieldSchema = Record < string , AxiomOnlyFieldType >
@@ -58,10 +59,24 @@ const STREAM_RECOVERY_FIELDS = {
5859 consecutive : 'number' ,
5960} as const satisfies AxiomOnlyFieldSchema
6061
62+ const ADS_FETCH_COMPLETED_FIELDS = {
63+ outcome : 'string' ,
64+ requested_provider : 'string' ,
65+ served_provider : 'string' ,
66+ ad_count : 'number' ,
67+ surface : 'string' ,
68+ placement_id : 'string' ,
69+ chat_session_id : 'string' ,
70+ duration_ms : 'number' ,
71+ client_ua_product : 'string' ,
72+ client_ua_version : 'string' ,
73+ } as const satisfies AxiomOnlyFieldSchema
74+
6175export type AxiomOnlyLogEvent = {
6276 event :
6377 | typeof CONTEXT_PRUNING_COMPLETED_EVENT
6478 | typeof STREAM_RECOVERY_EVENT
79+ | typeof ADS_FETCH_COMPLETED_EVENT
6580 data : Record < string , string | number | boolean >
6681}
6782
@@ -120,5 +135,11 @@ export function getAxiomOnlyLogEvent(
120135 data : sanitizeAllowlistedFields ( record , STREAM_RECOVERY_FIELDS ) ,
121136 }
122137 }
138+ if ( eventName === ADS_FETCH_COMPLETED_EVENT ) {
139+ return {
140+ event : eventName ,
141+ data : sanitizeAllowlistedFields ( record , ADS_FETCH_COMPLETED_FIELDS ) ,
142+ }
143+ }
123144 return null
124145}
0 commit comments