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

Core: Add error categorization framework #23653

Merged
merged 28 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
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
add telemetry event to core-server
  • Loading branch information
yannbf committed Aug 21, 2023
commit ce666350cc270724c7d4e7e900cf2e7ba6718e3c
18 changes: 18 additions & 0 deletions code/lib/core-server/src/presets/common-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type { WhatsNewCache, WhatsNewData } from '@storybook/core-events';
import {
REQUEST_WHATS_NEW_DATA,
RESULT_WHATS_NEW_DATA,
SEND_TELEMETRY_EVENT,
SET_WHATS_NEW_CACHE,
TOGGLE_WHATS_NEW_NOTIFICATIONS,
} from '@storybook/core-events';
Expand Down Expand Up @@ -329,5 +330,22 @@ export const experimental_serverChannel = async (
}
);

channel.on(SEND_TELEMETRY_EVENT, async ({ payload, isError }) => {
yannbf marked this conversation as resolved.
Show resolved Hide resolved
const isTelemetryEnabled = coreOptions.disableTelemetry !== true;

if (isTelemetryEnabled) {
if (isError) {
await sendTelemetryError(payload, 'error', {
cliOptions: options,
presetOptions: { ...options, corePresets: [], overridePresets: [] },
skipPrompt: true,
});
} else {
// TODO: figure event type out. Maybe we need a new one?
await telemetry('dev', payload);
}
}
});

return channel;
};
6 changes: 6 additions & 0 deletions code/lib/preview/src/runtime.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SEND_TELEMETRY_EVENT } from '@storybook/core-events';
import { values } from './globals/runtime';
import { globals } from './globals/types';

Expand All @@ -7,3 +8,8 @@ const getKeys = Object.keys as <T extends object>(obj: T) => Array<keyof T>;
getKeys(globals).forEach((key) => {
(globalThis as any)[globals[key]] = values[key];
});

global.telemetry = (data) => {
const channel = global.__STORYBOOK_ADDONS_CHANNEL__;
channel.emit(SEND_TELEMETRY_EVENT, data);
};
1 change: 1 addition & 0 deletions code/ui/manager/src/globals/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export default {
'RESET_STORY_ARGS',
'RESULT_WHATS_NEW_DATA',
'SELECT_STORY',
'SEND_TELEMETRY_EVENT',
'SET_CONFIG',
'SET_CURRENT_STORY',
'SET_GLOBALS',
Expand Down
7 changes: 6 additions & 1 deletion code/ui/manager/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { AddonStore } from '@storybook/manager-api';
import { addons } from '@storybook/manager-api';
import type { Addon_Types, Addon_Config } from '@storybook/types';
import { createBrowserChannel } from '@storybook/channels';
import { CHANNEL_CREATED } from '@storybook/core-events';
import { CHANNEL_CREATED, SEND_TELEMETRY_EVENT } from '@storybook/core-events';
import Provider from './provider';
import { renderStorybookUI } from './index';

Expand Down Expand Up @@ -64,3 +64,8 @@ renderStorybookUI(rootEl, new ReactProvider());
Object.keys(Keys).forEach((key: keyof typeof Keys) => {
global[Keys[key]] = values[key];
});

global.telemetry = (data) => {
const channel = global.__STORYBOOK_ADDONS_CHANNEL__;
channel.emit(SEND_TELEMETRY_EVENT, data);
};