File tree 1 file changed +15
-1
lines changed
frontend/packages/console-telemetry-plugin/src/listeners
1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { TelemetryEventListener } from '@console/dynamic-plugin-sdk/src' ;
2
2
import { TELEMETRY_DISABLED , TELEMETRY_DEBUG } from './const' ;
3
3
4
+ // Sample 20% of sessions
5
+ const SAMPLE_SESSION = Math . random ( ) < 0.2 ;
6
+
4
7
/** Segmnet API Key that looks like a hash */
5
8
const apiKey =
6
9
window . SERVER_FLAGS ?. telemetry ?. DEVSANDBOX_SEGMENT_API_KEY ||
@@ -97,7 +100,7 @@ const initSegment = () => {
97
100
analytics . load ( apiKey , options ) ;
98
101
} ;
99
102
100
- if ( ! TELEMETRY_DISABLED && apiKey ) {
103
+ if ( ! TELEMETRY_DISABLED && apiKey && SAMPLE_SESSION ) {
101
104
initSegment ( ) ;
102
105
}
103
106
@@ -122,6 +125,17 @@ export const eventListener: TelemetryEventListener = async (
122
125
}
123
126
return ;
124
127
}
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
+ }
125
139
switch ( eventType ) {
126
140
case 'identify' :
127
141
{
You can’t perform that action at this time.
0 commit comments