MCPcopy Index your code
hub / github.com/codeaashu/claude-code / shouldSampleEvent

Function shouldSampleEvent

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

Source from the content-addressed store, hash-verified

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

Callers 1

logEventImplFunction · 0.85

Calls 1

getEventSamplingConfigFunction · 0.85

Tested by

no test coverage detected