Skip to content

Commit

Permalink
feat(cli): treat telemetry consent as denied when running in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
juice49 authored and bjoerge committed Dec 14, 2023
1 parent 4d2921b commit c1feff6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/@sanity/cli/src/util/createTelemetryStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {SanityClient} from '@sanity/client'
import {ConsentStatus, createBatchedStore, createSessionId, TelemetryEvent} from '@sanity/telemetry'
import {debug as baseDebug} from '../debug'
import {getClientWrapper, getCliToken} from './clientWrapper'
import {isCi} from './isCi'

const debug = baseDebug.extend('telemetry')

Expand Down Expand Up @@ -60,6 +61,10 @@ export function createTelemetryStore(options: {env: {[key: string]: string | und

function resolveConsent(): Promise<{status: ConsentStatus}> {
debug('Resolving consent…')
if (isCi) {
debug('CI environment detected, treating telemetry consent as denied')
return Promise.resolve({status: 'denied'})
}
if (isTrueish(env.DO_NOT_TRACK)) {
debug('DO_NOT_TRACK is set, consent is denied')
return Promise.resolve({status: 'denied'})
Expand Down Expand Up @@ -118,6 +123,7 @@ export function createTelemetryStore(options: {env: {[key: string]: string | und
resolveConsent,
sendEvents,
})

process.once('beforeExit', () => store.flush())
return store
}

0 comments on commit c1feff6

Please sign in to comment.