Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telemetry: Disable save-from-controls logs for example stories #28870

Merged
merged 3 commits into from
Aug 13, 2024
Merged
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
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