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

feat(cli) add telemetry scaffolding #5321

Merged
merged 7 commits into from
Dec 18, 2023
Merged

Conversation

bjoerge
Copy link
Member

@bjoerge bjoerge commented Dec 4, 2023

Description

Adds telemetry scaffolding to the cli package. The actual instrumentation is added in #5320, CLI commands for opting in and out of telemetry is added in #5322.

A tagged release of this and the other relevant PRs for telemetry can be tested using:

npm i -g sanity@telemetry

…and then running against staging (for now):

SANITY_INTERNAL_ENV=staging sanity <command> [<args>]

Other relevant env vars:

  • SANITY_TELEMETRY_INSPECT=1: append all logged events to telemetry-events.ndjson in current workdir (note: the output file will not be cleared between cli runs)
  • DEBUG=sanity:cli:telemetry: log telemetry related debug information as the CLI runs.

E.g. to test the create project flow, with debug info and logging events to file, you can use:

SANITY_INTERNAL_ENV=staging DEBUG=sanity:cli:telemetry SANITY_TELEMETRY_INSPECT=1 npm create sanity@telemetry

What to review

  • Does the code changes make sense?
  • Any potential for accidental breakage?

Notes for release

TBD

Copy link

vercel bot commented Dec 4, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
performance-studio ✅ Ready (Inspect) Visit Preview Dec 18, 2023 1:54pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 18, 2023 1:54pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Dec 18, 2023 1:54pm

Copy link

socket-security bot commented Dec 4, 2023

New dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
@sanity/telemetry 0.7.0 None +4 537 kB bjoerge

Copy link
Contributor

github-actions bot commented Dec 4, 2023

No changes to documentation

Copy link
Contributor

github-actions bot commented Dec 4, 2023

Component Testing Report Updated Dec 18, 2023 1:55 PM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 14s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 2s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 8s 3 0 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 6s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 16s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 8s 9 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 39s 18 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 6s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 3s 3 0 0

@bjoerge bjoerge force-pushed the feat/cli-telemetry-scaffolding branch from 675781c to ea8db9e Compare December 11, 2023 14:24
@bjoerge bjoerge force-pushed the feat/cli-telemetry-scaffolding branch from ea8db9e to a919840 Compare December 11, 2023 14:30
@juice49 juice49 force-pushed the feat/cli-telemetry-scaffolding branch from a919840 to 36311e8 Compare December 12, 2023 12:42
@bjoerge bjoerge force-pushed the feat/cli-telemetry-scaffolding branch from 36311e8 to 6c225a7 Compare December 14, 2023 10:41
Copy link
Contributor

@ricokahler ricokahler left a comment

Choose a reason for hiding this comment

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

looks good! will review again once this points to prod instead of staging

@@ -0,0 +1,5 @@
/* eslint-disable no-process-env */
export const isCi =
process.env.CI || // Travis CI, CircleCI, Gitlab CI, Appveyor, CodeShip
Copy link
Contributor

Choose a reason for hiding this comment

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

would it be better to wrap these each in isTrueish?

Copy link
Member Author

Choose a reason for hiding this comment

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

Great callout. Will fix.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed (left process.env.BUILD_NUMBER out since I don't know for sure whether BUILD_NUMBER=0 is a valid status)

@@ -81,11 +81,7 @@ export class CommandRunner {
const output = this.handlers.outputter
const prompt = this.handlers.prompter

const {cliConfig, ...commandOptions} = options
const apiClient = getClientWrapper(
Copy link
Contributor

Choose a reason for hiding this comment

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

more curious than anything: why did you move the apiClient initialization into the CommandRunner? I didn't see this new key used anywhere in the PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question. It made sense at an earlier point during development. Reverting this. Thanks!

@@ -76,6 +87,11 @@ export async function runCli(cliRoot: string, {cliVersion}: {cliVersion: string}
args.groupOrCommand = 'help'
}

if (args.groupOrCommand === 'logout') {
// flush telemetry events before logging out
await flushTelemetry()
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this here instead of in the logoutCommand code?

Copy link
Member Author

@bjoerge bjoerge Dec 18, 2023

Choose a reason for hiding this comment

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

trying to keep the interface exposed to subcommands minimal, so wanted to avoid passing the flush method to subcommands at this point. We might change this later if we see that it's something we want subcommands to be able to do, but for now it made sense to special case this here.

packages/@sanity/cli/src/util/createTelemetryStore.ts Outdated Show resolved Hide resolved
@@ -76,6 +87,11 @@ export async function runCli(cliRoot: string, {cliVersion}: {cliVersion: string}
args.groupOrCommand = 'help'
}

if (args.groupOrCommand === 'logout') {
// flush telemetry events before logging out
await flushTelemetry()
Copy link
Member Author

@bjoerge bjoerge Dec 18, 2023

Choose a reason for hiding this comment

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

trying to keep the interface exposed to subcommands minimal, so wanted to avoid passing the flush method to subcommands at this point. We might change this later if we see that it's something we want subcommands to be able to do, but for now it made sense to special case this here.

@@ -0,0 +1,5 @@
/* eslint-disable no-process-env */
export const isCi =
process.env.CI || // Travis CI, CircleCI, Gitlab CI, Appveyor, CodeShip
Copy link
Member Author

Choose a reason for hiding this comment

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

Great callout. Will fix.

@@ -81,11 +81,7 @@ export class CommandRunner {
const output = this.handlers.outputter
const prompt = this.handlers.prompter

const {cliConfig, ...commandOptions} = options
const apiClient = getClientWrapper(
Copy link
Member Author

Choose a reason for hiding this comment

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

Good question. It made sense at an earlier point during development. Reverting this. Thanks!

@bjoerge bjoerge force-pushed the feat/cli-telemetry-scaffolding branch from d86ed77 to ec652fe Compare December 18, 2023 13:41
@bjoerge bjoerge added this pull request to the merge queue Dec 18, 2023
Merged via the queue into next with commit 0865664 Dec 18, 2023
40 checks passed
@bjoerge bjoerge deleted the feat/cli-telemetry-scaffolding branch December 18, 2023 18:15
bjoerge added a commit that referenced this pull request Dec 18, 2023
* fix(deps): add telemetry package as cli dependency

* feat(cli): add telemetry scaffolding for CLI

* fix(cli): flush telemetry store before logging out

* refactor(cli): abstract continuous integration check

* feat(cli): treat telemetry consent as denied when running in CI

* fix(cli): parse trueish env vars when detecting ci environment

* fixup! feat(cli): add telemetry scaffolding for CLI

---------

Co-authored-by: Ash <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants