Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/telemetry-notice-disabled.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/shared': patch
---

Add support for the `CLERK_TELEMETRY_NOTICE_DISABLED` environment variable. Setting it to `1` (or `true`) suppresses the telemetry disclosure notice printed on dev-server startup while keeping telemetry collection enabled, for users who are okay with telemetry and no longer want the reminder. To disable telemetry collection itself (which also suppresses the notice), continue using `CLERK_TELEMETRY_DISABLED`.
26 changes: 26 additions & 0 deletions packages/shared/src/__tests__/telemetry.notice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ describe('maybeShowTelemetryNotice', () => {
beforeEach(() => {
originalCIEnv = Object.fromEntries(CI_VARS.map(name => [name, process.env[name]]));
clearCIEnv();
delete process.env.CLERK_TELEMETRY_NOTICE_DISABLED;
__resetTelemetryNoticeForTests();
logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
});

afterEach(() => {
logSpy.mockRestore();
delete process.env.CLERK_TELEMETRY_NOTICE_DISABLED;
for (const [name, value] of Object.entries(originalCIEnv)) {
if (typeof value === 'string') {
process.env[name] = value;
Expand Down Expand Up @@ -111,4 +113,28 @@ describe('maybeShowTelemetryNotice', () => {

expect(() => maybeShowTelemetryNotice()).not.toThrow();
});

test('skips when CLERK_TELEMETRY_NOTICE_DISABLED is set to 1', () => {
process.env.CLERK_TELEMETRY_NOTICE_DISABLED = '1';

maybeShowTelemetryNotice();

expect(logSpy).not.toHaveBeenCalled();
});

test('skips when CLERK_TELEMETRY_NOTICE_DISABLED is set to true', () => {
process.env.CLERK_TELEMETRY_NOTICE_DISABLED = 'true';

maybeShowTelemetryNotice();

expect(logSpy).not.toHaveBeenCalled();
});

test('still prints when CLERK_TELEMETRY_NOTICE_DISABLED is falsy', () => {
process.env.CLERK_TELEMETRY_NOTICE_DISABLED = 'false';

maybeShowTelemetryNotice();

expect(logSpy).toHaveBeenCalled();
});
});
14 changes: 13 additions & 1 deletion packages/shared/src/telemetry/notice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
* delta is small. Authoritative disclosure for those setups lives in the Clerk
* telemetry docs (https://clerk.com/docs/telemetry). Opt-out continues to work the
* same way (`telemetry={false}` on `<ClerkProvider>` or the framework-specific
* `*_CLERK_TELEMETRY_DISABLED` env var).
* `*_CLERK_TELEMETRY_DISABLED` env var). Users who keep telemetry enabled can suppress
* just this notice with `CLERK_TELEMETRY_NOTICE_DISABLED=1`.
*
* Persistence is in-process via a `globalThis` Symbol, which survives Next.js HMR
* module reloads. No filesystem access, no `node:` imports, no dynamic-code APIs, so
Expand Down Expand Up @@ -61,6 +62,14 @@ function isCI(): boolean {
return automatedEnvironmentVariables.some(name => isTruthy(process.env[name]));
}

// Silences only the notice, unlike CLERK_TELEMETRY_DISABLED which also turns off collection.
function isNoticeDisabled(): boolean {
if (typeof process === 'undefined' || !process.env) {
return false;
}
return isTruthy(process.env.CLERK_TELEMETRY_NOTICE_DISABLED);
}

function hasSeen(): boolean {
return Boolean((globalThis as Record<symbol, unknown>)[PROCESS_FLAG]);
}
Expand Down Expand Up @@ -103,6 +112,9 @@ export function maybeShowTelemetryNotice(options: MaybeShowTelemetryNoticeOption
if (isCI()) {
return;
}
if (isNoticeDisabled()) {
return;
}
if (hasSeen()) {
return;
}
Expand Down
Loading