diff options
author | dan <dan.abramov@gmail.com> | 2024-05-30 16:32:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-30 16:32:59 +0100 |
commit | d6275e98c24ae12f070a689eb5602ac08b6abbb7 (patch) | |
tree | adb0cd6699a2c859e804c370d3b10e191ee63450 /src/lib/statsig/statsig.tsx | |
parent | 94312010269d511e122d208d0db540267578ed5c (diff) | |
download | voidsky-d6275e98c24ae12f070a689eb5602ac08b6abbb7.tar.zst |
[Statsig] Sample noisy events (#4288)
* Sample state:background and state:foreground * Sample feed events * Add DEV protection against forgetting to add events to the list
Diffstat (limited to 'src/lib/statsig/statsig.tsx')
-rw-r--r-- | src/lib/statsig/statsig.tsx | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/lib/statsig/statsig.tsx b/src/lib/statsig/statsig.tsx index 6ffca0ab4..573a123e1 100644 --- a/src/lib/statsig/statsig.tsx +++ b/src/lib/statsig/statsig.tsx @@ -87,7 +87,14 @@ export function toClout(n: number | null | undefined): number | undefined { } } -const DOWNSAMPLED_EVENTS = new Set(['router:navigate:sampled']) +const DOWNSAMPLED_EVENTS: Set<keyof LogEvents> = new Set([ + 'router:navigate:sampled', + 'state:background:sampled', + 'state:foreground:sampled', + 'home:feedDisplayed:sampled', + 'feed:endReached:sampled', + 'feed:refresh:sampled', +]) const isDownsampledSession = Math.random() < 0.9 // 90% likely export function logEvent<E extends keyof LogEvents>( @@ -98,6 +105,13 @@ export function logEvent<E extends keyof LogEvents>( if (isDownsampledSession && DOWNSAMPLED_EVENTS.has(eventName)) { return } + if (process.env.NODE_ENV === 'development') { + if (eventName.endsWith(':sampled')) { + logger.error( + 'Did you forget to add ' + eventName + ' to DOWNSAMPLED_EVENTS?', + ) + } + } const fullMetadata = { ...rawMetadata, } as Record<string, string> // Statsig typings are unnecessarily strict here. @@ -199,14 +213,14 @@ AppState.addEventListener('change', (state: AppStateStatus) => { lastState = state if (state === 'active') { lastActive = performance.now() - logEvent('state:foreground', {}) + logEvent('state:foreground:sampled', {}) } else { let secondsActive = 0 if (lastActive != null) { secondsActive = Math.round((performance.now() - lastActive) / 1e3) } lastActive = null - logEvent('state:background', { + logEvent('state:background:sampled', { secondsActive, }) } |