Skip to content

Commit 3402cda

Browse files
committed
OCPBUGS-54157: Sample segment sessions
1 parent bd6ef9a commit 3402cda

File tree

1 file changed

+15
-1
lines changed
  • frontend/packages/console-telemetry-plugin/src/listeners

1 file changed

+15
-1
lines changed

frontend/packages/console-telemetry-plugin/src/listeners/segment.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { TelemetryEventListener } from '@console/dynamic-plugin-sdk/src';
22
import { 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 */
58
const 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
{

0 commit comments

Comments
 (0)