File tree 1 file changed +16
-1
lines changed
frontend/packages/console-telemetry-plugin/src/listeners
1 file changed +16
-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,8 @@ const initSegment = () => {
97
100
analytics . load ( apiKey , options ) ;
98
101
} ;
99
102
100
- if ( ! TELEMETRY_DISABLED && apiKey ) {
103
+ // Sample 20% of sessions
104
+ if ( ! TELEMETRY_DISABLED && apiKey && SAMPLE_SESSION ) {
101
105
initSegment ( ) ;
102
106
}
103
107
@@ -122,6 +126,17 @@ export const eventListener: TelemetryEventListener = async (
122
126
}
123
127
return ;
124
128
}
129
+ if ( ! SAMPLE_SESSION ) {
130
+ if ( TELEMETRY_DEBUG ) {
131
+ // eslint-disable-next-line no-console
132
+ console . debug (
133
+ 'console-telemetry-plugin: session is not being sampled - ignoring telemetry event' ,
134
+ eventType ,
135
+ properties ,
136
+ ) ;
137
+ }
138
+ return ;
139
+ }
125
140
switch ( eventType ) {
126
141
case 'identify' :
127
142
{
You can’t perform that action at this time.
0 commit comments