Skip to content

Commit 323dea1

Browse files
committed
OCPBUGS-54157: Sample segment sessions
1 parent bd6ef9a commit 323dea1

File tree

1 file changed

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

1 file changed

+16
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
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,8 @@ const initSegment = () => {
97100
analytics.load(apiKey, options);
98101
};
99102

100-
if (!TELEMETRY_DISABLED && apiKey) {
103+
// Sample 20% of sessions
104+
if (!TELEMETRY_DISABLED && apiKey && SAMPLE_SESSION) {
101105
initSegment();
102106
}
103107

@@ -122,6 +126,17 @@ export const eventListener: TelemetryEventListener = async (
122126
}
123127
return;
124128
}
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+
}
125140
switch (eventType) {
126141
case 'identify':
127142
{

0 commit comments

Comments
 (0)