Skip to content

Commit 60b954f

Browse files
Sync public snapshot from freebuff-private
Source: CodebuffAI/freebuff-private@c6e459f573bd6265fc538df66b2b23f9102af9d2
1 parent 89b25a4 commit 60b954f

3 files changed

Lines changed: 58 additions & 6 deletions

File tree

bun.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/src/util/__tests__/axiom-only-log.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, expect, test } from 'bun:test'
22

33
import {
4+
ADS_FETCH_COMPLETED_EVENT,
45
CONTEXT_PRUNING_COMPLETED_EVENT,
56
getAxiomOnlyLogEvent,
67
STREAM_RECOVERY_EVENT,
@@ -137,4 +138,32 @@ describe('getAxiomOnlyLogEvent', () => {
137138
data: { metric: 'stream_recovery_rescued' },
138139
})
139140
})
141+
142+
test('sanitizes ad-fetch metadata', () => {
143+
expect(
144+
getAxiomOnlyLogEvent({
145+
axiomEvent: ADS_FETCH_COMPLETED_EVENT,
146+
outcome: 'fill',
147+
requested_provider: 'gravity',
148+
served_provider: 'carbon',
149+
ad_count: 1,
150+
placement_id: 'CLI-Chat-Inline',
151+
duration_ms: 42,
152+
client_ua_product: 'freebuff-cli',
153+
attempted_providers: ['gravity', 'carbon'],
154+
messages: [{ role: 'user', content: 'secret' }],
155+
}),
156+
).toEqual({
157+
event: ADS_FETCH_COMPLETED_EVENT,
158+
data: {
159+
outcome: 'fill',
160+
requested_provider: 'gravity',
161+
served_provider: 'carbon',
162+
ad_count: 1,
163+
placement_id: 'CLI-Chat-Inline',
164+
duration_ms: 42,
165+
client_ua_product: 'freebuff-cli',
166+
},
167+
})
168+
})
140169
})

common/src/util/axiom-only-log.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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

1212
export 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. */
2020
export const STREAM_RECOVERY_EVENT = 'stream_recovery' as const
21+
export const ADS_FETCH_COMPLETED_EVENT = AnalyticsEvent.ADS_FETCH_COMPLETED
2122

2223
type AxiomOnlyFieldType = 'string' | 'number' | 'boolean'
2324
type 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+
6175
export 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

Comments
 (0)