Skip to content

Commit 75cacba

Browse files
authored
🤖 fix: filter telemetry DAUs from CI/automation environments (#953)
Added comprehensive CI environment detection to prevent automated sources (CI pipelines, testing) from being counted as DAUs. ## CI Providers Filtered - GitHub Actions, GitLab CI, Jenkins, CircleCI, Travis CI - Azure Pipelines, Bitbucket Pipelines, TeamCity, Buildkite - AWS CodeBuild, Drone CI, AppVeyor, Vercel, Netlify Both backend (`telemetryService.ts`) and frontend (`client.ts`) now check for CI environments before sending telemetry events. _Generated with `mux`_
1 parent 480ca3f commit 75cacba

File tree

2 files changed

+69
-8
lines changed

2 files changed

+69
-8
lines changed

src/common/telemetry/client.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,35 @@
1212
import type { TelemetryEventPayload } from "./payload";
1313

1414
/**
15-
* Check if we're running in a test environment
15+
* Check if running in a CI/automation environment.
16+
* Covers major CI providers. This is a subset of what the backend checks
17+
* since the browser process has limited env var access.
18+
*/
19+
function isCIEnvironment(): boolean {
20+
if (typeof process === "undefined") {
21+
return false;
22+
}
23+
return (
24+
process.env.CI === "true" ||
25+
process.env.CI === "1" ||
26+
process.env.GITHUB_ACTIONS === "true" ||
27+
process.env.GITLAB_CI === "true" ||
28+
process.env.JENKINS_URL !== undefined ||
29+
process.env.CIRCLECI === "true"
30+
);
31+
}
32+
33+
/**
34+
* Check if we're running in a test or CI environment
1635
*/
1736
function isTestEnvironment(): boolean {
1837
return (
19-
typeof process !== "undefined" &&
20-
(process.env.NODE_ENV === "test" ||
21-
process.env.JEST_WORKER_ID !== undefined ||
22-
process.env.VITEST !== undefined ||
23-
process.env.TEST_INTEGRATION === "1")
38+
(typeof process !== "undefined" &&
39+
(process.env.NODE_ENV === "test" ||
40+
process.env.JEST_WORKER_ID !== undefined ||
41+
process.env.VITEST !== undefined ||
42+
process.env.TEST_INTEGRATION === "1")) ||
43+
isCIEnvironment()
2444
);
2545
}
2646

src/node/services/telemetryService.ts

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,56 @@ const DEFAULT_POSTHOG_HOST = "https://us.i.posthog.com";
2525
const TELEMETRY_ID_FILE = "telemetry_id";
2626

2727
/**
28-
* Check if telemetry is disabled via environment variable
28+
* Check if running in a CI/automation environment.
29+
* Covers major CI providers: GitHub Actions, GitLab CI, Jenkins, CircleCI,
30+
* Travis, Azure Pipelines, Bitbucket, TeamCity, Buildkite, etc.
31+
*/
32+
function isCIEnvironment(): boolean {
33+
return (
34+
// Generic CI indicator (set by most CI systems)
35+
process.env.CI === "true" ||
36+
process.env.CI === "1" ||
37+
// GitHub Actions
38+
process.env.GITHUB_ACTIONS === "true" ||
39+
// GitLab CI
40+
process.env.GITLAB_CI === "true" ||
41+
// Jenkins
42+
process.env.JENKINS_URL !== undefined ||
43+
// CircleCI
44+
process.env.CIRCLECI === "true" ||
45+
// Travis CI
46+
process.env.TRAVIS === "true" ||
47+
// Azure Pipelines
48+
process.env.TF_BUILD === "True" ||
49+
// Bitbucket Pipelines
50+
process.env.BITBUCKET_BUILD_NUMBER !== undefined ||
51+
// TeamCity
52+
process.env.TEAMCITY_VERSION !== undefined ||
53+
// Buildkite
54+
process.env.BUILDKITE === "true" ||
55+
// AWS CodeBuild
56+
process.env.CODEBUILD_BUILD_ID !== undefined ||
57+
// Drone CI
58+
process.env.DRONE === "true" ||
59+
// AppVeyor
60+
process.env.APPVEYOR === "True" ||
61+
// Vercel / Netlify (build environments)
62+
process.env.VERCEL === "1" ||
63+
process.env.NETLIFY === "true"
64+
);
65+
}
66+
67+
/**
68+
* Check if telemetry is disabled via environment variable or automation context
2969
*/
3070
function isTelemetryDisabled(): boolean {
3171
return (
3272
process.env.MUX_DISABLE_TELEMETRY === "1" ||
3373
process.env.NODE_ENV === "test" ||
3474
process.env.JEST_WORKER_ID !== undefined ||
3575
process.env.VITEST !== undefined ||
36-
process.env.TEST_INTEGRATION === "1"
76+
process.env.TEST_INTEGRATION === "1" ||
77+
isCIEnvironment()
3778
);
3879
}
3980

0 commit comments

Comments
 (0)