File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
frontend/packages/console-telemetry-plugin/src/listeners Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 11import { TelemetryEventListener } from '@console/dynamic-plugin-sdk/src' ;
22import { TELEMETRY_DISABLED , TELEMETRY_DEBUG } from './const' ;
33
4+ // Sample 20% of sessions
5+ const SAMPLE_SESSION = Math . random ( ) < 0.2 ;
6+
47/** Segmnet API Key that looks like a hash */
58const apiKey =
69 window . SERVER_FLAGS ?. telemetry ?. DEVSANDBOX_SEGMENT_API_KEY ||
@@ -97,7 +100,7 @@ const initSegment = () => {
97100 analytics . load ( apiKey , options ) ;
98101} ;
99102
100- if ( ! TELEMETRY_DISABLED && apiKey ) {
103+ if ( ! TELEMETRY_DISABLED && apiKey && SAMPLE_SESSION ) {
101104 initSegment ( ) ;
102105}
103106
@@ -122,6 +125,17 @@ export const eventListener: TelemetryEventListener = async (
122125 }
123126 return ;
124127 }
128+ if ( ! SAMPLE_SESSION ) {
129+ if ( TELEMETRY_DEBUG ) {
130+ // eslint-disable-next-line no-console
131+ console . debug (
132+ 'console-telemetry-plugin: session is not being sampled - ignoring telemetry event' ,
133+ eventType ,
134+ properties ,
135+ ) ;
136+ }
137+ return ;
138+ }
125139 switch ( eventType ) {
126140 case 'identify' :
127141 {
You can’t perform that action at this time.
0 commit comments