Skip to content

Telemetry: Centralize disable logic with module-level flag#34441

Closed
valentinpalkovic wants to merge 2 commits into
nextfrom
worktree-ticklish-prancing-umbrella
Closed

Telemetry: Centralize disable logic with module-level flag#34441
valentinpalkovic wants to merge 2 commits into
nextfrom
worktree-ticklish-prancing-umbrella

Conversation

@valentinpalkovic
Copy link
Copy Markdown
Contributor

@valentinpalkovic valentinpalkovic commented Apr 2, 2026

Closes #34431

What I did

Telemetry was sent despite disableTelemetry: true in the main config because telemetry disable guards (if (!options.disableTelemetry)) were scattered across ~40 files and some locations (like checklist.ts, reported in #34431) were missing the guard entirely.

This PR introduces a module-level disable flag in the telemetry module. The telemetry() function now early-returns when disabled, making all callers safe by default — no guards needed at call sites.

How it works

  1. Added setTelemetryEnabled(enabled) and isTelemetryModuleEnabled() to code/core/src/telemetry/index.ts
  2. The telemetry() function checks the module flag and early-returns when disabled (skipping both notify() and sendTelemetry())
  3. The flag is set at 4 entry points:
    • withTelemetry() — from CLI --disable-telemetry flag
    • buildDevStandalone() — from core.disableTelemetry config
    • buildStaticStandalone() — from core.disableTelemetry config
    • experimental_serverChannel (common-preset) — from core.disableTelemetry config
    • Vitest plugin — from core.disableTelemetry or STORYBOOK_DISABLE_TELEMETRY env
  4. Removed all ~20 scattered if (!disableTelemetry) guards across the codebase
  5. Cleaned up now-unused coreOptions/coreConfig parameters from channel init functions

Files changed (32 files)

  • Core telemetry: telemetry/index.ts — module flag + setTelemetryEnabled + isTelemetryModuleEnabled
  • Entry points: withTelemetry.ts, build-dev.ts, build-static.ts, common-preset.ts, vitest-plugin/index.ts
  • Guard removals: doTelemetry.ts, telemetry-channel.ts, create-new-story-channel.ts, file-search-channel.ts, ghost-stories-channel.ts, open-in-editor-channel.ts, whats-new.ts, save-story.ts, dev-server.ts, cli-storybook/bin/run.ts, upgrade.ts, TelemetryService.ts, initiate.ts, UserPreferencesCommand.ts, AddonConfigurationCommand.ts, ProjectDetectionCommand.ts, scaffold-new-project.ts, onboarding/preset.ts, vitest/preset.ts, mocking-utils/extract.ts
  • Tests: Updated 5 test files to match new architecture

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

Caution

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

  1. Set disableTelemetry: true in .storybook/main.ts config
  2. Run storybook dev
  3. Verify no telemetry notification appears
  4. Verify no network requests to storybook.js.org/event-log
  5. Also verify with --disable-telemetry CLI flag

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • Refactor

    • Reorganized internal module dependencies and system architecture for improved maintainability.
  • Chores

    • Updated gitignore patterns to exclude additional build artifacts.

Instead of requiring every telemetry call site to check `disableTelemetry`,
introduce a module-level flag in the telemetry module that gates all calls.
The `telemetry()` function now early-returns when disabled, making all
callers safe by default. This fixes #34431 where `checklist.ts` was
missing the guard, causing telemetry to be sent despite `disableTelemetry: true`.

The flag is set at startup from CLI options (via `withTelemetry`) and from
config (via preset loading in `buildDevStandalone`, `buildStaticStandalone`,
and `experimental_serverChannel`). All ~20 scattered `if (!disableTelemetry)`
guards have been removed.

Closes #34431

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@valentinpalkovic valentinpalkovic added bug ci:normal Run our default set of CI jobs (choose this for most PRs). labels Apr 2, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 2, 2026

View your CI Pipeline Execution ↗ for commit 7f4084b

Command Status Duration Result
nx run-many -t compile,check,knip,test,lint,fmt... ⛔ Cancelled 1h 4m 24s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-07 14:39:34 UTC

@valentinpalkovic valentinpalkovic marked this pull request as ready for review April 7, 2026 13:33
@valentinpalkovic
Copy link
Copy Markdown
Contributor Author

Closing to recreate with proper PR template.

@github-project-automation github-project-automation Bot moved this from In Progress to Done in Core Team Projects Apr 7, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 7, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 63864402-7a98-4443-9f9f-fb3a2504f0d0

📥 Commits

Reviewing files that changed from the base of the PR and between b224bef and 7f4084b.

📒 Files selected for processing (32)
  • .gitignore
  • code/addons/onboarding/src/preset.ts
  • code/addons/vitest/src/preset.ts
  • code/addons/vitest/src/vitest-plugin/index.ts
  • code/core/src/core-server/build-dev.ts
  • code/core/src/core-server/build-static.ts
  • code/core/src/core-server/dev-server.ts
  • code/core/src/core-server/presets/common-preset.ts
  • code/core/src/core-server/server-channel/create-new-story-channel.test.ts
  • code/core/src/core-server/server-channel/create-new-story-channel.ts
  • code/core/src/core-server/server-channel/file-search-channel.test.ts
  • code/core/src/core-server/server-channel/file-search-channel.ts
  • code/core/src/core-server/server-channel/ghost-stories-channel.test.ts
  • code/core/src/core-server/server-channel/ghost-stories-channel.ts
  • code/core/src/core-server/server-channel/open-in-editor-channel.ts
  • code/core/src/core-server/server-channel/telemetry-channel.ts
  • code/core/src/core-server/utils/doTelemetry.ts
  • code/core/src/core-server/utils/save-story/save-story.ts
  • code/core/src/core-server/utils/whats-new.ts
  • code/core/src/core-server/withTelemetry.test.ts
  • code/core/src/core-server/withTelemetry.ts
  • code/core/src/mocking-utils/extract.ts
  • code/core/src/telemetry/index.ts
  • code/lib/cli-storybook/src/bin/run.ts
  • code/lib/cli-storybook/src/upgrade.ts
  • code/lib/create-storybook/src/commands/AddonConfigurationCommand.ts
  • code/lib/create-storybook/src/commands/ProjectDetectionCommand.ts
  • code/lib/create-storybook/src/commands/UserPreferencesCommand.ts
  • code/lib/create-storybook/src/initiate.ts
  • code/lib/create-storybook/src/scaffold-new-project.ts
  • code/lib/create-storybook/src/services/TelemetryService.test.ts
  • code/lib/create-storybook/src/services/TelemetryService.ts

📝 Walkthrough

Walkthrough

Centralized telemetry disablement was introduced via module-level controls (setTelemetryEnabled / isTelemetryModuleEnabled), and per-call conditional telemetry guards were removed across server channels, CLI, addons, and utilities so telemetry invocations occur unconditionally while runtime suppression is handled by the telemetry module.

Changes

Cohort / File(s) Summary
Telemetry Module Core
code/core/src/telemetry/index.ts
Added module-level _disabled flag with setTelemetryEnabled(enabled) and isTelemetryModuleEnabled(); telemetry(...) short-circuits when disabled.
Global init / wrapper / build / dev
code/core/src/core-server/withTelemetry.ts, code/core/src/core-server/withTelemetry.test.ts, code/core/src/core-server/build-dev.ts, code/core/src/core-server/build-static.ts, code/core/src/core-server/dev-server.ts
Shifted from per-call guards to calling setTelemetryEnabled(false) at startup when appropriate; removed many local conditional branches that previously skipped telemetry and attached signal handlers/telemetry calls unconditionally.
Server channel signatures & behavior
code/core/src/core-server/presets/common-preset.ts, code/core/src/core-server/server-channel/create-new-story-channel.ts, code/core/src/core-server/server-channel/file-search-channel.ts, code/core/src/core-server/server-channel/ghost-stories-channel.ts, code/core/src/core-server/server-channel/open-in-editor-channel.ts, code/core/src/core-server/server-channel/telemetry-channel.ts, code/core/src/core-server/server-channel/*.{test.ts}
Removed coreOptions: CoreConfig / coreConfig params from channel init signatures and deleted coreOptions.disableTelemetry guards; telemetry now emitted unconditionally or gated via isTelemetryModuleEnabled() at runtime. Tests updated to match new signatures and mocks.
Addon presets & vitest plugin
code/addons/onboarding/src/preset.ts, code/addons/vitest/src/preset.ts, code/addons/vitest/src/vitest-plugin/index.ts
Moved listener registration and telemetry handling outside previous telemetry-disable guards; introduced explicit calls to setTelemetryEnabled(false) where initialization respects presets/env.
Server utilities
code/core/src/core-server/utils/doTelemetry.ts, code/core/src/core-server/utils/whats-new.ts, code/core/src/core-server/utils/save-story/save-story.ts
Removed coreOptions gating; telemetry payload construction and emits now run regardless of prior per-call disableTelemetry guards.
Mocking & extract utilities
code/core/src/mocking-utils/extract.ts
Telemetry emission after mock extraction is now unconditional (removed options.coreOptions?.disableTelemetry guard).
CLI & create-storybook commands
code/lib/cli-storybook/src/bin/run.ts, code/lib/cli-storybook/src/upgrade.ts, code/lib/create-storybook/src/commands/..., code/lib/create-storybook/src/initiate.ts, code/lib/create-storybook/src/scaffold-new-project.ts
Removed local disableTelemetry flags and instance-level constructor flags; telemetry calls at command-level now always invoke telemetry(...) (module-level suppression used instead).
TelemetryService simplification
code/lib/create-storybook/src/services/TelemetryService.ts, code/lib/create-storybook/src/services/TelemetryService.test.ts
Removed disableTelemetry constructor parameter and per-instance gating; methods call telemetry(...) unconditionally; tests adjusted to use no-arg constructor.
Misc / Config
.gitignore
Added .omc to ignored entries.

Sequence Diagram(s)

sequenceDiagram
  participant Presets
  participant Server
  participant Channel as "Server Channel"
  participant Telemetry as "Telemetry Module"
  participant External as "External Telemetry Service"

  Presets->>Telemetry: call setTelemetryEnabled(false)? / default enabled
  Presets->>Server: start server (withTelemetry)
  Server->>Channel: register handlers (emit events)
  Channel->>Telemetry: telemetry('event', payload)
  alt telemetry module enabled
    Telemetry->>External: sendTelemetry(payload)
  else telemetry module disabled
    Telemetry-->>Channel: no-op (return early)
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug ci:normal Run our default set of CI jobs (choose this for most PRs).

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: Telemetry is sent despite disableTelemetry: true

1 participant