MCPcopy Create free account
hub / github.com/Noumena-Network/code / shouldSampleEvent

Function shouldSampleEvent

src/services/analytics/firstPartyEventLogger.ts:58–86  ·  view source on GitHub ↗
(eventName: string)

Source from the content-addressed store, hash-verified

56 * @returns The sample_rate if event should be logged, null if it should be dropped
57 */
58export function shouldSampleEvent(eventName: string): number | null {
59 const config = getEventSamplingConfig()
60 const eventConfig = config[eventName]
61
62 // If no config for this event, log at 100% rate (no sampling)
63 if (!eventConfig) {
64 return null
65 }
66
67 const sampleRate = eventConfig.sample_rate
68
69 // Validate sample rate is in valid range
70 if (typeof sampleRate !== 'number' || sampleRate < 0 || sampleRate > 1) {
71 return null
72 }
73
74 // Sample rate of 1 means log everything (no need to add metadata)
75 if (sampleRate >= 1) {
76 return null
77 }
78
79 // Sample rate of 0 means drop everything
80 if (sampleRate <= 0) {
81 return 0
82 }
83
84 // Randomly decide whether to sample this event
85 return Math.random() < sampleRate ? sampleRate : 0
86}
87
88const BATCH_CONFIG_NAME = 'ncode_1p_event_batch_config'
89type BatchConfig = {

Callers 1

logEventImplFunction · 0.85

Calls 1

getEventSamplingConfigFunction · 0.85

Tested by

no test coverage detected