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

chore(cli-storybook): Add telemetry #8803

Merged
merged 8 commits into from
Jul 20, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli-packages/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
]
},
"dependencies": {
"@redwoodjs/cli-helpers": "5.0.0",
"@redwoodjs/project-config": "5.0.0",
"@redwoodjs/telemetry": "5.0.0",
"@storybook/addon-a11y": "7.0.24",
Expand Down
16 changes: 15 additions & 1 deletion packages/cli-packages/storybook/src/commands/storybook.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious why we record attributes twice?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to record the command name inside the middleware because it might not have been recorded in the handler is if the check had throw an error.

We probably don't need the command: 'storybook' in the handler recordTelemetryAttributes since it'll be set by the middleware. I kept it there mainly to just be consistent that all handlers set the command name.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import terminalLink from 'terminal-link'
import type { Argv } from 'yargs'

import { recordTelemetryAttributes } from '@redwoodjs/cli-helpers'

import c from '../lib/colors'
import { StorybookYargsOptions } from '../types'

Expand Down Expand Up @@ -53,7 +55,11 @@ export function builder(
type: 'boolean',
default: defaultOptions.smokeTest,
})

.middleware(() => {
recordTelemetryAttributes({
command: 'storybook',
})
})
.check((argv) => {
if (argv.build && argv.smokeTest) {
throw new Error('Can not provide both "--build" and "--smoke-test"')
Expand Down Expand Up @@ -82,6 +88,14 @@ export async function handler(options: StorybookYargsOptions): Promise<void> {
// NOTE: We should provide some visual output before the import to increase
// the perceived performance of the command as there will be delay while we
// load the handler.
recordTelemetryAttributes({
command: 'storybook',
build: options.build,
ci: options.ci,
open: options.open,
smokeTest: options.smokeTest,
})

const { handler: storybookHandler } = await import('./storybookHandler.js')
await storybookHandler(options)
}
10 changes: 6 additions & 4 deletions packages/cli-packages/storybook/src/commands/storybookHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'node:path'

import execa from 'execa'
import execa, { ExecaError } from 'execa'

import { getPaths } from '@redwoodjs/project-config'
// Allow import of untyped package
Expand Down Expand Up @@ -72,8 +72,10 @@ export async function handler({
try {
await execa.command(command, execaOptions)
} catch (e) {
console.log(c.error((e as Error).message))
errorTelemetry(process.argv, (e as Error).message)
process.exit(1)
if ((e as ExecaError).signal !== 'SIGINT') {
console.log(c.error((e as Error).message))
errorTelemetry(process.argv, (e as Error).message)
}
process.exit((e as ExecaError).exitCode ?? 1)
}
}
1 change: 1 addition & 0 deletions packages/cli/src/telemetry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export async function startTelemetry() {
traceProvider.addSpanProcessor(traceProcessor)
traceProvider.register()

process.on('SIGINT', () => {})
process.on('exit', () => {
shutdownTelemetry()
})
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7304,6 +7304,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@redwoodjs/cli-storybook@workspace:packages/cli-packages/storybook"
dependencies:
"@redwoodjs/cli-helpers": 5.0.0
"@redwoodjs/project-config": 5.0.0
"@redwoodjs/telemetry": 5.0.0
"@storybook/addon-a11y": 7.0.24
Expand Down