Skip to content

Commit

Permalink
Merge pull request #28870 from storybookjs/shilman/fix-save-from-cont…
Browse files Browse the repository at this point in the history
…rols-telemetry

Telemetry: Disable save-from-controls logging for example stories
  • Loading branch information
shilman authored Aug 13, 2024
2 parents 763deb5 + c64542e commit a177fce
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion code/core/src/core-server/utils/doTelemetry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getPrecedingUpgrade, telemetry } from '@storybook/core/telemetry';
import type { CoreConfig, Options, StoryIndex } from '@storybook/core/types';
import type { CoreConfig, Options } from '@storybook/core/types';

import invariant from 'tiny-invariant';

Expand Down
6 changes: 4 additions & 2 deletions code/core/src/core-server/utils/save-story/save-story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { basename, join } from 'node:path';

import type { Channel } from '@storybook/core/channels';
import { formatFileContent } from '@storybook/core/common';
import { telemetry } from '@storybook/core/telemetry';
import { isExampleStoryId, telemetry } from '@storybook/core/telemetry';
import type { CoreConfig, Options } from '@storybook/core/types';
import { storyNameFromExport, toId } from '@storybook/csf';

Expand Down Expand Up @@ -122,7 +122,9 @@ export function initializeSaveStory(channel: Channel, options: Options, coreConf
error: null,
} satisfies ResponseData<SaveStoryResponsePayload>);

if (!coreConfig.disableTelemetry) {
// don't take credit for save-from-controls actions against CLI example stories
const isCLIExample = isExampleStoryId(newStoryId ?? csfId);
if (!coreConfig.disableTelemetry && !isCLIExample) {
await telemetry('save-story', {
action: name ? 'createStory' : 'updateStory',
success: true,
Expand Down
12 changes: 2 additions & 10 deletions code/core/src/core-server/utils/summarizeIndex.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isExampleStoryId } from '@storybook/core/telemetry';
import type { IndexEntry, StoryIndex } from '@storybook/core/types';

import { AUTODOCS_TAG, PLAY_FN_TAG, isMdxEntry } from './StoryIndexGenerator';
Expand Down Expand Up @@ -25,15 +26,6 @@ const isCLIExampleEntry = (entry: IndexEntry) =>
'example-page--logged-out',
].includes(entry.id);

/**
* Is this story part of the CLI generated examples,
* including user-created stories in those files
*/
const isAnyExampleEntry = (entry: IndexEntry) =>
entry.id.startsWith('example-button--') ||
entry.id.startsWith('example-header--') ||
entry.id.startsWith('example-page--');

export function summarizeIndex(storyIndex: StoryIndex) {
let storyCount = 0;
const componentTitles = new Set<string>();
Expand All @@ -49,7 +41,7 @@ export function summarizeIndex(storyIndex: StoryIndex) {
if (isCLIExampleEntry(entry)) {
if (entry.type === 'story') exampleStoryCount += 1;
if (entry.type === 'docs') exampleDocsCount += 1;
} else if (isAnyExampleEntry(entry)) {
} else if (isExampleStoryId(entry.id)) {
if (entry.type === 'story') onboardingStoryCount += 1;
if (entry.type === 'docs') onboardingDocsCount += 1;
} else if (entry.type === 'story') {
Expand Down
9 changes: 9 additions & 0 deletions code/core/src/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ export { getPrecedingUpgrade } from './event-cache';

export { addToGlobalContext } from './telemetry';

/**
* Is this story part of the CLI generated examples,
* including user-created stories in those files
*/
export const isExampleStoryId = (storyId: string) =>
storyId.startsWith('example-button--') ||
storyId.startsWith('example-header--') ||
storyId.startsWith('example-page--');

export const telemetry = async (
eventType: EventType,
payload: Payload = {},
Expand Down

0 comments on commit a177fce

Please sign in to comment.