Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Merge pull request #32168 from storybookjs/shilman/add-dev-cancel-event
Telemetry: Send index stats on dev exit
(cherry picked from commit c5d386f)
  • Loading branch information
shilman authored and storybook-bot committed Aug 4, 2025
commit 5a08df846eae35d34b670b99e2620e5265c8d19f
23 changes: 23 additions & 0 deletions code/core/src/core-server/dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import compression from '@polka/compression';
import polka from 'polka';
import invariant from 'tiny-invariant';

import { telemetry } from '../telemetry';
import type { StoryIndexGenerator } from './utils/StoryIndexGenerator';
import { doTelemetry } from './utils/doTelemetry';
import { getManagerBuilder, getPreviewBuilder } from './utils/get-builders';
Expand All @@ -19,6 +20,7 @@ import { openInBrowser } from './utils/open-in-browser';
import { getServerAddresses } from './utils/server-address';
import { getServer } from './utils/server-init';
import { useStatics } from './utils/server-statics';
import { summarizeIndex } from './utils/summarizeIndex';

export async function storybookDevServer(options: Options) {
const [server, core] = await Promise.all([getServer(options), options.presets.apply('core')]);
Expand Down Expand Up @@ -130,5 +132,26 @@ export async function storybookDevServer(options: Options) {
// Now the preview has successfully started, we can count this as a 'dev' event.
doTelemetry(app, core, initializedStoryIndexGenerator, options);

async function cancelTelemetry() {
const payload = { eventType: 'dev' };
try {
const generator = await initializedStoryIndexGenerator;
const indexAndStats = await generator?.getIndexAndStats();
// compute stats so we can get more accurate story counts
if (indexAndStats) {
Object.assign(payload, {
storyIndex: summarizeIndex(indexAndStats.storyIndex),
storyStats: indexAndStats.stats,
});
}
} catch (err) {}
await telemetry('canceled', payload, { immediate: true });
process.exit(0);
}

if (!core?.disableTelemetry) {
process.on('SIGINT', cancelTelemetry);
}

return { previewResult, managerResult, address, networkAddress };
}