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: Add CLI version to context #21999

Merged
merged 5 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions code/lib/cli/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import leven from 'leven';
import { sync as readUpSync } from 'read-pkg-up';

import { logger } from '@storybook/node-logger';
import { globalContext } from '@storybook/telemetry';

import type { CommandOptions } from './generators/types';
import { initiate } from './initiate';
Expand All @@ -20,6 +21,9 @@ import { generateStorybookBabelConfigInCWD } from './babel-config';
import { dev } from './dev';
import { build } from './build';
import { parseList, getEnvConfig } from './utils';
import versions from './versions';

globalContext.cliVersion = versions.storybook;
shilman marked this conversation as resolved.
Show resolved Hide resolved

const pkg = readUpSync({ cwd: __dirname }).packageJson;
const consoleLogger = console;
Expand Down
2 changes: 2 additions & 0 deletions code/lib/telemetry/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export { getStorybookCoreVersion } from './package-json';

export { getPrecedingUpgrade } from './event-cache';

export { globalContext } from './telemetry';

export const telemetry = async (
eventType: EventType,
payload: Payload = {},
Expand Down
8 changes: 7 additions & 1 deletion code/lib/telemetry/src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ let tasks: Promise<any>[] = [];
// send telemetry
const sessionId = nanoid();

// context info sent with all events, provided
// by the app. currently:
// - cliVersion
export const globalContext = {} as Record<string, any>;

export async function sendTelemetry(
data: TelemetryData,
options: Partial<Options> = { retryDelay: 1000, immediate: false }
Expand All @@ -27,8 +32,9 @@ export async function sendTelemetry(
// flatten the data before we send it
const { eventType, payload, metadata, ...rest } = data;
const context = options.stripMetadata
? {}
? globalContext
: {
...globalContext,
anonymousId: getAnonymousProjectId(),
inCI: Boolean(process.env.CI),
isTTY: process.stdout.isTTY,
Expand Down