From 1b1720bb75233661b30205000c4c3bff855d47c8 Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Wed, 23 Oct 2024 09:16:45 +0200 Subject: [PATCH] chore: disable telemetry (#39137) * chore: remove telemetry from create-gatsby * fix: make gatsby-telemetry no-op * chore: remove gatsby-telemetry usage --- .../gatsby-cli/__tests__/options.js | 5 +- packages/create-gatsby/src/__tests__/run.ts | 41 --- .../create-gatsby/src/__tests__/tracking.ts | 61 ---- packages/create-gatsby/src/index.ts | 43 --- packages/create-gatsby/src/tracking.ts | 81 ----- packages/create-gatsby/src/utils/hash.ts | 6 - packages/gatsby-cli/package.json | 1 - packages/gatsby-cli/src/create-cli.ts | 21 +- packages/gatsby-cli/src/init-starter.ts | 8 - .../src/reporter/loggers/ink/cli.tsx | 12 +- .../src/reporter/redux/internal-actions.ts | 6 - packages/gatsby-cli/src/reporter/reporter.ts | 6 +- packages/gatsby-cli/src/util/version.ts | 7 - .../gatsby-dev-cli/src/__tests__/watch.js | 1 - .../src/utils/traverse-package-deps.js | 1 - .../gatsby-plugin-gatsby-cloud/package.json | 1 - .../src/__tests__/routes.js | 6 - .../src/gatsby-node.js | 29 +- .../gatsby-plugin-page-creator/package.json | 1 - .../src/create-page-wrapper.ts | 3 - .../src/gatsby-node.ts | 5 - packages/gatsby-telemetry/package.json | 10 +- .../src/__tests__/telemetry.ts | 182 ----------- packages/gatsby-telemetry/src/create-flush.ts | 30 +- .../gatsby-telemetry/src/event-storage.ts | 73 +---- packages/gatsby-telemetry/src/index.ts | 135 ++++---- packages/gatsby-telemetry/src/postinstall.js | 14 - packages/gatsby-telemetry/src/send.ts | 11 +- .../src/show-analytics-notification.ts | 24 -- packages/gatsby-telemetry/src/telemetry.ts | 308 ++---------------- packages/gatsby/package.json | 1 - .../gatsby/src/bootstrap/load-config/index.ts | 13 - .../src/bootstrap/load-plugins/validate.ts | 7 - packages/gatsby/src/commands/build.ts | 40 --- .../gatsby/src/commands/develop-process.ts | 29 -- packages/gatsby/src/commands/develop.ts | 11 - packages/gatsby/src/commands/repl.ts | 3 - packages/gatsby/src/commands/serve.ts | 10 - .../src/query/__tests__/data-tracking.js | 7 - packages/gatsby/src/redux/__tests__/index.js | 21 -- packages/gatsby/src/redux/actions/public.js | 3 - .../gatsby/src/redux/actions/restricted.ts | 3 - packages/gatsby/src/redux/index.ts | 9 - packages/gatsby/src/redux/save-state.js | 14 - packages/gatsby/src/services/initialize.ts | 38 --- .../sample-site-for-experiment.ts.snap | 17 - .../src/utils/__tests__/handle-flags.ts | 19 +- .../__tests__/sample-site-for-experiment.ts | 24 -- packages/gatsby/src/utils/adapter/manager.ts | 4 - packages/gatsby/src/utils/api-runner-node.js | 15 +- packages/gatsby/src/utils/engines-helpers.ts | 6 - packages/gatsby/src/utils/feedback.ts | 7 - .../src/utils/parcel/compile-gatsby-files.ts | 8 - .../src/utils/sample-site-for-experiment.ts | 14 - .../src/utils/show-experiment-notice.ts | 2 - packages/gatsby/src/utils/start-server.ts | 11 - .../gatsby/src/utils/websocket-manager.ts | 32 -- .../src/utils/worker/__tests__/config.ts | 9 - .../src/utils/worker/__tests__/datastore.ts | 9 - .../gatsby/src/utils/worker/__tests__/jobs.ts | 9 - .../src/utils/worker/__tests__/queries.ts | 9 - .../src/utils/worker/__tests__/schema.ts | 9 - .../src/utils/worker/__tests__/share-state.ts | 9 - yarn.lock | 16 +- 64 files changed, 138 insertions(+), 1432 deletions(-) delete mode 100644 packages/create-gatsby/src/__tests__/tracking.ts delete mode 100644 packages/create-gatsby/src/tracking.ts delete mode 100644 packages/create-gatsby/src/utils/hash.ts delete mode 100644 packages/gatsby-telemetry/src/__tests__/telemetry.ts delete mode 100644 packages/gatsby-telemetry/src/postinstall.js delete mode 100644 packages/gatsby-telemetry/src/show-analytics-notification.ts delete mode 100644 packages/gatsby/src/utils/__tests__/__snapshots__/sample-site-for-experiment.ts.snap delete mode 100644 packages/gatsby/src/utils/__tests__/sample-site-for-experiment.ts delete mode 100644 packages/gatsby/src/utils/sample-site-for-experiment.ts diff --git a/integration-tests/gatsby-cli/__tests__/options.js b/integration-tests/gatsby-cli/__tests__/options.js index b53c22c47d176..26ce644dd5958 100644 --- a/integration-tests/gatsby-cli/__tests__/options.js +++ b/integration-tests/gatsby-cli/__tests__/options.js @@ -5,10 +5,11 @@ jest.setTimeout(MAX_TIMEOUT) describe(`gatsby options`, () => { it(`Prints the options`, () => { - const [status, logs] = GatsbyCLI.from(`gatsby-sites/gatsby-build`).invoke(`options`) + const [status, logs] = GatsbyCLI.from(`gatsby-sites/gatsby-build`).invoke( + `options` + ) logs.should.contain(`Package Manager`) - logs.should.contain(`Telemetry enabled`) expect(status).toBe(0) }) }) diff --git a/packages/create-gatsby/src/__tests__/run.ts b/packages/create-gatsby/src/__tests__/run.ts index 1790bea5cd784..0b6cc7ebcaac6 100644 --- a/packages/create-gatsby/src/__tests__/run.ts +++ b/packages/create-gatsby/src/__tests__/run.ts @@ -2,7 +2,6 @@ import path from "path" import { reporter } from "../utils/reporter" import { initStarter } from "../init-starter" import { setSiteMetadata } from "../utils/site-metadata" -import { trackCli } from "../tracking" import { run, DEFAULT_STARTERS } from "../index" jest.mock(`../utils/parse-args`) @@ -35,11 +34,6 @@ jest.mock(`enquirer`, () => { return MockedEnquirer }) jest.mock(`../utils/reporter`) -jest.mock(`../tracking`, () => { - return { - trackCli: jest.fn(), - } -}) jest.mock(`../init-starter`, () => { return { initStarter: jest.fn(), @@ -57,12 +51,6 @@ jest.mock(`../utils/site-metadata`, () => { setSiteMetadata: jest.fn(), } }) -jest.mock(`../utils/hash`, () => { - return { - sha256: jest.fn(args => args), - md5: jest.fn(args => args), - } -}) jest.mock(`../utils/question-helpers`, () => { const originalQuestionHelpers = jest.requireActual( @@ -185,13 +173,6 @@ describe(`run`, () => { dirName ) }) - it(`should track JS was selected as language`, async () => { - await run() - expect(trackCli).toHaveBeenCalledWith(`CREATE_GATSBY_SELECT_OPTION`, { - name: `LANGUAGE`, - valueString: `js`, - }) - }) }) describe(`no ts flag`, () => { @@ -211,13 +192,6 @@ describe(`run`, () => { siteName ) }) - it(`should track JS was selected as language`, async () => { - await run() - expect(trackCli).toHaveBeenCalledWith(`CREATE_GATSBY_SELECT_OPTION`, { - name: `LANGUAGE`, - valueString: `js`, - }) - }) }) describe(`ts flag`, () => { @@ -237,14 +211,6 @@ describe(`run`, () => { siteName ) }) - - it(`should track TS was selected as language`, async () => { - await run() - expect(trackCli).toHaveBeenCalledWith(`CREATE_GATSBY_SELECT_OPTION`, { - name: `LANGUAGE`, - valueString: `ts`, - }) - }) }) }) @@ -265,11 +231,4 @@ describe(`skip and ts flag`, () => { dirName ) }) - it(`should track TS was selected as language`, async () => { - await run() - expect(trackCli).toHaveBeenCalledWith(`CREATE_GATSBY_SELECT_OPTION`, { - name: `LANGUAGE`, - valueString: `ts`, - }) - }) }) diff --git a/packages/create-gatsby/src/__tests__/tracking.ts b/packages/create-gatsby/src/__tests__/tracking.ts deleted file mode 100644 index 04b66679b83b3..0000000000000 --- a/packages/create-gatsby/src/__tests__/tracking.ts +++ /dev/null @@ -1,61 +0,0 @@ -let isTrackingEnabled: () => boolean - -const get = jest.fn() -const set = jest.fn() - -jest.doMock(`../utils/get-config-store`, () => { - return { - getConfigStore: (): unknown => { - return { - get, - set, - } - }, - } -}) - -describe(`isTrackingEnabled`, () => { - beforeEach(() => { - jest.resetModules() - isTrackingEnabled = require(`../tracking`).isTrackingEnabled - }) - - it(`is enabled by default`, () => { - const enabled = isTrackingEnabled() - expect(enabled).toBeTrue() - }) - - it(`respects the setting of the config store`, () => { - get.mockImplementationOnce(key => { - if (key === `telemetry.enabled`) { - return false - } else { - return true - } - }) - - const enabled = isTrackingEnabled() - expect(enabled).toBeFalse() - - const cachedEnabled = isTrackingEnabled() - expect(cachedEnabled).toBeFalse() - }) - - describe(`process.env.GATSBY_TELEMETRY_DISABLED`, () => { - beforeAll(() => { - process.env.GATSBY_TELEMETRY_DISABLED = `true` - }) - - it(`respects the setting of the environment variable`, () => { - const enabled = isTrackingEnabled() - expect(enabled).toBeFalse() - - const cachedEnabled = isTrackingEnabled() - expect(cachedEnabled).toBeFalse() - }) - - afterAll(() => { - process.env.GATSBY_TELEMETRY_DISABLED = undefined - }) - }) -}) diff --git a/packages/create-gatsby/src/index.ts b/packages/create-gatsby/src/index.ts index 4559bfb6ef7cb..589929b9e9404 100644 --- a/packages/create-gatsby/src/index.ts +++ b/packages/create-gatsby/src/index.ts @@ -12,7 +12,6 @@ import { plugin } from "./components/plugin" import { makePluginConfigQuestions } from "./plugin-options-form" import { center, wrap } from "./components/utils" import { stripIndent } from "common-tags" -import { trackCli } from "./tracking" import { reporter } from "./utils/reporter" import { setSiteMetadata } from "./utils/site-metadata" import { makeNpmSafe } from "./utils/make-npm-safe" @@ -20,7 +19,6 @@ import { generateQuestions, validateProjectName, } from "./utils/question-helpers" -import { sha256, md5 } from "./utils/hash" import { maybeUseEmoji } from "./utils/emoji" import { parseArgs } from "./utils/parse-args" @@ -75,8 +73,6 @@ export type PluginConfigMap = Record> export async function run(): Promise { const { flags, dirName } = parseArgs(process.argv.slice(2)) - trackCli(`CREATE_GATSBY_START`) - const { version } = require(`../package.json`) reporter.info(colors.grey(`create-gatsby version ${version}`)) @@ -149,28 +145,6 @@ ${center(colors.blueBright.bold.underline(`Welcome to Gatsby!`))} answers.language = `ts` } - // Telemetry - trackCli(`CREATE_GATSBY_SELECT_OPTION`, { - name: `project_name`, - valueString: sha256(answers.project), - }) - trackCli(`CREATE_GATSBY_SELECT_OPTION`, { - name: `LANGUAGE`, - valueString: answers.language, - }) - trackCli(`CREATE_GATSBY_SELECT_OPTION`, { - name: `CMS`, - valueString: answers.cms || `none`, - }) - trackCli(`CREATE_GATSBY_SELECT_OPTION`, { - name: `CSS_TOOLS`, - valueString: answers.styling || `none`, - }) - trackCli(`CREATE_GATSBY_SELECT_OPTION`, { - name: `PLUGIN`, - valueStringArray: answers.features || [], - }) - // Collect a report of things we will do to present to the user once the questions are complete const messages: Array = [ `${maybeUseEmoji( @@ -263,14 +237,10 @@ ${center(colors.blueBright.bold.underline(`Welcome to Gatsby!`))} `\nGreat! A few of the selections you made need to be configured. Please fill in the options for each plugin now:\n` ) - trackCli(`CREATE_GATSBY_SET_PLUGINS_START`) - const enquirer = new Enquirer>>() enquirer.use(plugin) pluginConfig = { ...pluginConfig, ...(await enquirer.prompt(config)) } - - trackCli(`CREATE_GATSBY_SET_PLUGINS_STOP`) } // If we're not skipping prompts, give the user a report of what we're about to do @@ -291,8 +261,6 @@ ${colors.bold(`Thanks! Here's what we'll now do:`)} }) if (!confirm) { - trackCli(`CREATE_GATSBY_CANCEL`) - reporter.info(`OK, bye!`) return } @@ -349,15 +317,4 @@ ${colors.bold(`Thanks! Here's what we'll now do:`)} reporter.info(`See all commands at\n ${colors.blueBright(`https://www.gatsbyjs.com/docs/reference/gatsby-cli/`)} `) - - const siteHash = md5(fullPath) - trackCli(`CREATE_GATSBY_SUCCESS`, { siteHash }) } - -process.on(`exit`, exitCode => { - trackCli(`CREATE_GATSBY_END`, { exitCode }) - - if (exitCode === -1) { - trackCli(`CREATE_GATSBY_ERROR`) - } -}) diff --git a/packages/create-gatsby/src/tracking.ts b/packages/create-gatsby/src/tracking.ts deleted file mode 100644 index e277af15e3167..0000000000000 --- a/packages/create-gatsby/src/tracking.ts +++ /dev/null @@ -1,81 +0,0 @@ -import fetch from "node-fetch" -import { v4 as uuidv4 } from "@lukeed/uuid" -import { getConfigStore } from "./utils/get-config-store" -import { isTruthy } from "./utils/is-truthy" - -const store = getConfigStore() -const gatsbyCliVersion = require(`../package.json`).version -const analyticsApi = - process.env.GATSBY_TELEMETRY_API || `https://analytics.gatsbyjs.com/events` -let trackingEnabled: boolean | undefined -const trackingDisabledFromEnvVar: boolean | undefined = isTruthy( - process.env.GATSBY_TELEMETRY_DISABLED -) - -const getMachineId = (): string => { - let machineId = store.get(`telemetry.machineId`) - - if (typeof machineId !== `string`) { - machineId = uuidv4() - store.set(`telemetry.machineId`, machineId) - } - - return machineId -} - -export interface ITrackCliArgs { - name?: string - valueString?: string - exitCode?: number - valueStringArray?: Array - siteHash?: string -} - -const sessionId = uuidv4() - -// Adapted from gatsby-telemetry -export function isTrackingEnabled(): boolean { - // Cache the result - if (trackingEnabled !== undefined) { - return trackingEnabled - } - - let enabled = store.get(`telemetry.enabled`) as boolean | null - - if (enabled === undefined || enabled === null) { - enabled = true - store.set(`telemetry.enabled`, enabled) - } - - if (trackingDisabledFromEnvVar) { - enabled = false - } - - trackingEnabled = enabled - - return enabled -} - -export const trackCli = (eventType: string, args?: ITrackCliArgs): void => { - if (!isTrackingEnabled()) { - return - } - - fetch(analyticsApi, { - method: `POST`, - headers: { - "content-type": `application/json`, - "user-agent": `create-gatsby:${gatsbyCliVersion}`, - }, - body: JSON.stringify({ - eventType, - time: new Date(), - sessionId, - machineId: getMachineId(), - componentId: `create-gatsby`, - componentVersion: 1, - gatsbyCliVersion, - ...args, - }), - }).catch(() => {}) /* do nothing, it's telemetry */ -} diff --git a/packages/create-gatsby/src/utils/hash.ts b/packages/create-gatsby/src/utils/hash.ts deleted file mode 100644 index ced08a278b176..0000000000000 --- a/packages/create-gatsby/src/utils/hash.ts +++ /dev/null @@ -1,6 +0,0 @@ -import crypto from "crypto" - -export const sha256 = (str: string): string => - crypto.createHash(`sha256`).update(str).digest(`hex`) -export const md5 = (str: string): string => - crypto.createHash(`md5`).update(str).digest(`hex`) diff --git a/packages/gatsby-cli/package.json b/packages/gatsby-cli/package.json index 2cdc445c6bf88..00fb5ea343f5a 100644 --- a/packages/gatsby-cli/package.json +++ b/packages/gatsby-cli/package.json @@ -32,7 +32,6 @@ "fs-exists-cached": "^1.0.0", "fs-extra": "^11.2.0", "gatsby-core-utils": "^4.14.0-next.2", - "gatsby-telemetry": "^4.14.0-next.2", "hosted-git-info": "^3.0.8", "is-valid-path": "^0.1.1", "joi": "^17.9.2", diff --git a/packages/gatsby-cli/src/create-cli.ts b/packages/gatsby-cli/src/create-cli.ts index 2c3d605b2a18d..b2f7e0b67799f 100644 --- a/packages/gatsby-cli/src/create-cli.ts +++ b/packages/gatsby-cli/src/create-cli.ts @@ -3,12 +3,6 @@ import resolveCwd from "resolve-cwd" import yargs from "yargs" import envinfo from "envinfo" import { sync as existsSync } from "fs-exists-cached" -import { - trackCli, - setDefaultTags, - setTelemetryEnabled, - isTrackingEnabled, -} from "gatsby-telemetry" import { run as runCreateGatsby } from "create-gatsby" import report from "./reporter" import { setStore } from "./reporter/redux" @@ -522,19 +516,15 @@ export const createCli = (argv: Array): yargs.Arguments => { buildLocalCommands(cli, isLocalSite) try { - const { version } = require(`../package.json`) cli.version( `version`, `Show the version of the Gatsby CLI and the Gatsby package in the current project`, getVersionInfo() ) - setDefaultTags({ gatsbyCliVersion: version }) } catch (e) { // ignore } - trackCli(argv) - return cli .command({ command: `new [rootPath] [starter]`, @@ -565,10 +555,8 @@ export const createCli = (argv: Array): yargs.Arguments => { description: `Disable telemetry`, }), - handler: handlerP(({ enable, disable }: yargs.Arguments) => { - const enabled = Boolean(enable) || !disable - setTelemetryEnabled(enabled) - report.log(`Telemetry collection ${enabled ? `enabled` : `disabled`}`) + handler: handlerP(() => { + report.log(`Telemetry is no longer gathered and is always disabled`) }), }) .command({ @@ -594,7 +582,6 @@ export const createCli = (argv: Array): yargs.Arguments => { handler: handlerP(({ cmd, key, value }: yargs.Arguments) => { if (!getPackageManager()) { - trackCli(`SET_DEFAULT_PACKAGE_MANAGER`, { name: `npm` }) setPackageManager(`npm`) } @@ -607,10 +594,9 @@ export const createCli = (argv: Array): yargs.Arguments => { if (value) { // @ts-ignore setPackageManager(value) - trackCli(`SET_PACKAGE_MANAGER`, { name: `${value}` }) + return } else { - trackCli(`SET_PACKAGE_MANAGER`, { name: `npm` }) setPackageManager(`npm`) } } else { @@ -623,7 +609,6 @@ export const createCli = (argv: Array): yargs.Arguments => { console.log(` Package Manager: ${getPackageManager()} - Telemetry enabled: ${isTrackingEnabled()} `) }), }) diff --git a/packages/gatsby-cli/src/init-starter.ts b/packages/gatsby-cli/src/init-starter.ts index e821dece03932..cec7643127970 100644 --- a/packages/gatsby-cli/src/init-starter.ts +++ b/packages/gatsby-cli/src/init-starter.ts @@ -3,7 +3,6 @@ import { execSync } from "child_process" import execa from "execa" import { sync as existsSync } from "fs-exists-cached" import fs from "fs-extra" -import { trackCli, trackError } from "gatsby-telemetry" import hostedGitInfo from "hosted-git-info" import isValid from "is-valid-path" import sysPath from "path" @@ -290,8 +289,6 @@ export async function initStarter( return } if (urlObject.protocol && urlObject.host) { - trackError(`NEW_PROJECT_NAME_MISSING`) - const isStarterAUrl = starter && !url.parse(starter).hostname && !url.parse(starter).protocol @@ -325,7 +322,6 @@ export async function initStarter( } if (existsSync(sysPath.join(rootPath, `package.json`))) { - trackError(`NEW_PROJECT_IS_NPM_PROJECT`) report.panic({ id: `11613`, context: { @@ -337,9 +333,6 @@ export async function initStarter( const hostedInfo = hostedGitInfo.fromUrl(starterPath) - trackCli(`NEW_PROJECT`, { - starterName: hostedInfo ? hostedInfo.shortcut() : `local:starter`, - }) if (hostedInfo) { await clone(hostedInfo, rootPath) } else { @@ -366,5 +359,4 @@ export async function initStarter( ) successMessage(rootPath) - trackCli(`NEW_PROJECT_END`) } diff --git a/packages/gatsby-cli/src/reporter/loggers/ink/cli.tsx b/packages/gatsby-cli/src/reporter/loggers/ink/cli.tsx index eb3f59d7164eb..7ddfe02df32d7 100644 --- a/packages/gatsby-cli/src/reporter/loggers/ink/cli.tsx +++ b/packages/gatsby-cli/src/reporter/loggers/ink/cli.tsx @@ -1,7 +1,6 @@ import React from "react" import { Box, Static } from "ink" import { isTTY } from "../../../util/is-tty" -import { trackBuildError } from "gatsby-telemetry" import { Spinner } from "./components/spinner" import { ProgressBar } from "./components/progress-bar" import { Message, IMessageProps } from "./components/messages" @@ -32,16 +31,7 @@ class CLI extends React.Component { } memoizedReactElementsForMessages: Array = [] - componentDidCatch(error: Error, info: React.ErrorInfo): void { - trackBuildError(`INK`, { - error: { - error: { - stack: info.componentStack, - }, - text: error.message, - }, - }) - } + componentDidCatch(): void {} static getDerivedStateFromError(error: Error): ICLIState { return { hasError: true, error } diff --git a/packages/gatsby-cli/src/reporter/redux/internal-actions.ts b/packages/gatsby-cli/src/reporter/redux/internal-actions.ts index 2949610205478..5cc3d738d9d98 100644 --- a/packages/gatsby-cli/src/reporter/redux/internal-actions.ts +++ b/packages/gatsby-cli/src/reporter/redux/internal-actions.ts @@ -1,5 +1,4 @@ import { uuid } from "gatsby-core-utils" -import { trackCli } from "gatsby-telemetry" import signalExit from "signal-exit" import { Dispatch } from "redux" @@ -242,11 +241,6 @@ export const endActivity = ({ }, }) } else if (activity.status === ActivityStatuses.InProgress) { - trackCli(`ACTIVITY_DURATION`, { - name: activity.text, - duration: Math.round(durationMS), - }) - if (activity.errored) { status = ActivityStatuses.Failed } diff --git a/packages/gatsby-cli/src/reporter/reporter.ts b/packages/gatsby-cli/src/reporter/reporter.ts index f860d50f4046d..2f490d9f4a2a8 100644 --- a/packages/gatsby-cli/src/reporter/reporter.ts +++ b/packages/gatsby-cli/src/reporter/reporter.ts @@ -1,6 +1,5 @@ import { stripIndent } from "common-tags" import chalk from "chalk" -import { trackError } from "gatsby-telemetry" import { globalTracer, Span, SpanContext } from "opentracing" import * as reduxReporterActions from "./redux/actions" @@ -109,8 +108,7 @@ class Reporter { error?: Error | Array, pluginName?: string ): never => { - const reporterError = this.error(errorMeta, error, pluginName) - trackError(`GENERAL_PANIC`, { error: reporterError }) + this.error(errorMeta, error, pluginName) prematureEnd() return process.exit(1) } @@ -121,7 +119,6 @@ class Reporter { pluginName?: string ): IStructuredError | Array => { const reporterError = this.error(errorMeta, error, pluginName) - trackError(`BUILD_PANIC`, { error: reporterError }) if (process.env.gatsby_executing_command === `build`) { prematureEnd() process.exit(1) @@ -194,7 +191,6 @@ class Reporter { if (structuredError) { reporterActions.createLog(structuredError) - trackError(`GENERIC_ERROR`, { error: structuredError }) } // TODO: remove this once Error component can render this info diff --git a/packages/gatsby-cli/src/util/version.ts b/packages/gatsby-cli/src/util/version.ts index 8e680b0087eaf..c36fc56c2f2be 100644 --- a/packages/gatsby-cli/src/util/version.ts +++ b/packages/gatsby-cli/src/util/version.ts @@ -1,14 +1,7 @@ -import { setDefaultTags } from "gatsby-telemetry" import { getGatsbyVersion } from "gatsby-core-utils" export const getLocalGatsbyVersion = (): string => { const version = getGatsbyVersion() - try { - setDefaultTags({ installedGatsbyVersion: version }) - } catch (e) { - // ignore - } - return version } diff --git a/packages/gatsby-dev-cli/src/__tests__/watch.js b/packages/gatsby-dev-cli/src/__tests__/watch.js index 52a11a5f96a64..af4329bd87213 100644 --- a/packages/gatsby-dev-cli/src/__tests__/watch.js +++ b/packages/gatsby-dev-cli/src/__tests__/watch.js @@ -350,7 +350,6 @@ describe(`dependency changes`, () => { `gatsby-theme-blog`, `gatsby-theme-blog-core`, `gatsby-theme-notes`, - `gatsby-telemetry`, `gatsby-transformer-asciidoc`, `gatsby-transformer-csv`, `gatsby-transformer-documentationjs`, diff --git a/packages/gatsby-dev-cli/src/utils/traverse-package-deps.js b/packages/gatsby-dev-cli/src/utils/traverse-package-deps.js index 5941d64303553..98763e983d4ef 100644 --- a/packages/gatsby-dev-cli/src/utils/traverse-package-deps.js +++ b/packages/gatsby-dev-cli/src/utils/traverse-package-deps.js @@ -9,7 +9,6 @@ const path = require(`path`) * ``` * { * "gatsby-cli": Set(["gatsby"]), - * "gatsby-telemetry": Set(["gatsby", "gatsby-cli"]), * "gatsby-source-filesystem": Set(["gatsby-source-contentful", "gatsby-source-drupal", "gatsby-source-wordpress", etc]) * // no package have remark plugin in dependencies - so dependent list is empty * "gatsby-transformer-remark": Set([]) diff --git a/packages/gatsby-plugin-gatsby-cloud/package.json b/packages/gatsby-plugin-gatsby-cloud/package.json index e19161ccc927a..c3b09b038ea33 100644 --- a/packages/gatsby-plugin-gatsby-cloud/package.json +++ b/packages/gatsby-plugin-gatsby-cloud/package.json @@ -10,7 +10,6 @@ "@babel/runtime": "^7.20.13", "fs-extra": "^11.2.0", "gatsby-core-utils": "^4.14.0-next.2", - "gatsby-telemetry": "^4.14.0-next.2", "kebab-hash": "^0.1.2", "lodash": "^4.17.21", "webpack-assets-manifest": "^5.1.0" diff --git a/packages/gatsby-plugin-gatsby-cloud/src/__tests__/routes.js b/packages/gatsby-plugin-gatsby-cloud/src/__tests__/routes.js index 6d3289783eb1f..13944ddcf8c4a 100644 --- a/packages/gatsby-plugin-gatsby-cloud/src/__tests__/routes.js +++ b/packages/gatsby-plugin-gatsby-cloud/src/__tests__/routes.js @@ -3,12 +3,6 @@ import * as path from "path" import * as os from "os" const { onPostBuild } = require(`../gatsby-node`) -jest.mock(`gatsby-telemetry`, () => { - return { - captureEvent: jest.fn(), - } -}) - describe(`Routes IPC`, () => { let tmpDir diff --git a/packages/gatsby-plugin-gatsby-cloud/src/gatsby-node.js b/packages/gatsby-plugin-gatsby-cloud/src/gatsby-node.js index 2e51f73ea5c13..d8d005f2863cb 100644 --- a/packages/gatsby-plugin-gatsby-cloud/src/gatsby-node.js +++ b/packages/gatsby-plugin-gatsby-cloud/src/gatsby-node.js @@ -5,7 +5,6 @@ import { joinPath, generateHtmlPath, } from "gatsby-core-utils" -import { captureEvent } from "gatsby-telemetry" import makePluginData from "./plugin-data" import buildHeadersProgram from "./build-headers-program" import copyFunctionsManifest from "./copy-functions-manifest" @@ -38,7 +37,7 @@ exports.onCreateWebpackConfig = ({ actions, stage }) => { exports.onPostBuild = async ({ store }, userPluginOptions) => { const pluginOptions = { ...DEFAULT_OPTIONS, ...userPluginOptions } - const { redirects, pageDataStats, nodes, pages } = store.getState() + const { redirects, pages } = store.getState() const pluginData = makePluginData(store, assetsManifest) @@ -65,32 +64,6 @@ exports.onPostBuild = async ({ store }, userPluginOptions) => { await emitRoutes(batch) } - let nodesCount - - try { - const { getDataStore } = require(`gatsby/dist/datastore`) - nodesCount = getDataStore().countNodes() - } catch (e) { - // swallow exception - } - - if (typeof nodesCount === `undefined`) { - nodesCount = nodes && nodes.size - } - - const pagesCount = pageDataStats && pageDataStats.size - - try { - captureEvent(`GATSBY_CLOUD_METADATA`, { - siteMeasurements: { - pagesCount, - nodesCount, - }, - }) - } catch (e) { - console.error(e) - } - let rewrites = [] if (pluginOptions.generateMatchPathRewrites) { const matchPathsFile = joinPath( diff --git a/packages/gatsby-plugin-page-creator/package.json b/packages/gatsby-plugin-page-creator/package.json index 4170ee4d933be..5a925212355ba 100644 --- a/packages/gatsby-plugin-page-creator/package.json +++ b/packages/gatsby-plugin-page-creator/package.json @@ -33,7 +33,6 @@ "gatsby-core-utils": "^4.14.0-next.2", "gatsby-page-utils": "^3.14.0-next.2", "gatsby-plugin-utils": "^4.14.0-next.2", - "gatsby-telemetry": "^4.14.0-next.2", "globby": "^11.1.0", "lodash": "^4.17.21" }, diff --git a/packages/gatsby-plugin-page-creator/src/create-page-wrapper.ts b/packages/gatsby-plugin-page-creator/src/create-page-wrapper.ts index 64942194a8aea..9b9e4ead25c83 100644 --- a/packages/gatsby-plugin-page-creator/src/create-page-wrapper.ts +++ b/packages/gatsby-plugin-page-creator/src/create-page-wrapper.ts @@ -10,7 +10,6 @@ import { Options as ISlugifyOptions } from "@sindresorhus/slugify" import { createClientOnlyPage } from "./create-client-only-page" import { createPagesFromCollectionBuilder } from "./create-pages-from-collection-builder" import systemPath from "path" -import { trackFeatureIsUsed } from "gatsby-telemetry" import { Reporter } from "gatsby/reporter" import type { TrailingSlash } from "gatsby-page-utils" @@ -48,7 +47,6 @@ export function createPage( // If the page includes a `{}` in it, then we create it as a collection builder if (pathIsCollectionBuilder(absolutePath)) { - trackFeatureIsUsed(`UnifiedRoutes:collection-page-builder`) createPagesFromCollectionBuilder({ filePath, absolutePath, @@ -64,7 +62,6 @@ export function createPage( // If the path includes a `[]` in it, then we create it as a client only route if (pathIsClientOnlyRoute(absolutePath)) { - trackFeatureIsUsed(`UnifiedRoutes:client-page-builder`) createClientOnlyPage(filePath, absolutePath, actions, trailingSlash) return } diff --git a/packages/gatsby-plugin-page-creator/src/gatsby-node.ts b/packages/gatsby-plugin-page-creator/src/gatsby-node.ts index 29b252ab996a8..a34f2f979df53 100644 --- a/packages/gatsby-plugin-page-creator/src/gatsby-node.ts +++ b/packages/gatsby-plugin-page-creator/src/gatsby-node.ts @@ -9,7 +9,6 @@ import { PluginOptions, PluginCallback, } from "gatsby" -import { trackFeatureIsUsed } from "gatsby-telemetry" import { parse, GraphQLString } from "gatsby/graphql" import { createPath, @@ -424,10 +423,6 @@ export async function onPluginInit( try { const files = await findCollectionPageFiles(pagesPath) - if (files.length > 0) { - trackFeatureIsUsed(`UnifiedRoutes:collection-page-builder`) - } - await Promise.all( files.map(async relativePath => { const absolutePath = require.resolve( diff --git a/packages/gatsby-telemetry/package.json b/packages/gatsby-telemetry/package.json index 9b4fa6c851232..c012ed8cee0ff 100644 --- a/packages/gatsby-telemetry/package.json +++ b/packages/gatsby-telemetry/package.json @@ -9,16 +9,9 @@ "dependencies": { "@babel/code-frame": "^7.18.6", "@babel/runtime": "^7.20.13", - "@turist/fetch": "^7.2.0", - "@turist/time": "^0.0.2", - "boxen": "^5.1.2", - "configstore": "^5.0.1", "fs-extra": "^11.2.0", "gatsby-core-utils": "^4.14.0-next.2", - "git-up": "^7.0.0", - "is-docker": "^2.2.1", - "lodash": "^4.17.21", - "node-fetch": "^2.6.11" + "git-up": "^7.0.0" }, "devDependencies": { "@babel/cli": "^7.20.7", @@ -46,7 +39,6 @@ "scripts": { "build": "babel src --out-dir lib --ignore \"**/__tests__\",\"**/__mocks__\" --extensions \".ts,.js\"", "prepare": "cross-env NODE_ENV=production npm run build && npm run typegen", - "postinstall": "node src/postinstall.js || true", "typegen": "rimraf --glob \"lib/**/*.d.ts\" && tsc --emitDeclarationOnly --declaration --declarationDir lib/", "watch": "babel -w src --out-dir lib --ignore \"**/__tests__\",\"**/__mocks__\" --extensions \".ts,.js\"" }, diff --git a/packages/gatsby-telemetry/src/__tests__/telemetry.ts b/packages/gatsby-telemetry/src/__tests__/telemetry.ts deleted file mode 100644 index 6bf57b5c5ba5c..0000000000000 --- a/packages/gatsby-telemetry/src/__tests__/telemetry.ts +++ /dev/null @@ -1,182 +0,0 @@ -import { EventStorage } from "../event-storage" -import { AnalyticsTracker } from "../telemetry" -import * as fs from "fs-extra" -import * as os from "os" -import * as path from "path" -import { uuid } from "gatsby-core-utils" - -const uuidv4 = uuid.v4 - -jest.mock(`../event-storage`) - -let telemetry -beforeEach(() => { - ;(EventStorage as jest.Mock).mockReset() - telemetry = new AnalyticsTracker() -}) - -describe(`Telemetry`, () => { - it(`Adds event to store`, () => { - telemetry.buildAndStoreEvent(`demo`, {}) - expect(EventStorage).toHaveBeenCalledTimes(1) - expect( - (EventStorage as jest.Mock).mock.instances[0].addEvent - ).toHaveBeenCalledTimes(2) - }) - - it(`Doesn't add event to store if telemetry tracking is turned off`, () => { - ;(EventStorage as jest.Mock).mockReset() - telemetry = new AnalyticsTracker({ trackingEnabled: false }) - telemetry.trackActivity(`demo`) - expect( - (EventStorage as jest.Mock).mock.instances[0].addEvent - ).not.toHaveBeenCalled() - }) - - describe(`trackFeatureIsUsed`, () => { - it(`Attaches feature list to the events`, () => { - telemetry.trackFeatureIsUsed(`Foo:bar`) - telemetry.buildAndStoreEvent(`demo`, {}) - expect( - (EventStorage as jest.Mock).mock.instances[0].addEvent - ).toHaveBeenCalledWith( - expect.objectContaining({ - features: [`Foo:bar`], - }) - ) - }) - }) - - describe(`allows overriding defaults`, () => { - it(`allows overriding componentId`, () => { - const t = new AnalyticsTracker({ - componentId: `desktop`, - gatsbyCliVersion: `1.2.3-beta1`, - }) - t.buildAndStoreEvent(`demo`, {}) - expect( - (EventStorage as jest.Mock).mock.instances[1].addEvent - ).toHaveBeenCalledWith( - expect.objectContaining({ - componentId: `desktop`, - gatsbyCliVersion: `1.2.3-beta1`, - }) - ) - }) - }) - - describe(`allows reading tags from path`, () => { - it(`getTagsFromPath should read the file and detect updates`, async () => { - const t = new AnalyticsTracker({ - componentId: `component`, - }) - - // Test it when env not set - let res = t.getTagsFromPath() - expect(res).toMatchObject({}) - expect(t.lastEnvTagsFromFileTime).toBe(0) - - // create file and write initial data - const filePath = path.join(fs.realpathSync(os.tmpdir()), uuidv4()) - console.log(filePath) - process.env.GATSBY_TELEMETRY_METADATA_PATH = filePath - - fs.writeFileSync(filePath, JSON.stringify({ componentId: `test` })) - await new Promise(resolve => { - setTimeout(resolve, 2000) - }) - // get it and make sure we see it and the ts matches - res = t.getTagsFromPath() - expect(res).toMatchObject({ componentId: `test` }) - let stat = fs.statSync(filePath) - expect(t.lastEnvTagsFromFileTime).toBe(stat.mtimeMs) - - // Update the file - fs.writeFileSync(filePath, JSON.stringify({ componentId: `test2` })) - - await new Promise(resolve => { - setTimeout(resolve, 2000) - }) - stat = fs.statSync(filePath) - // make sure we see the change - res = t.getTagsFromPath() - expect(t.lastEnvTagsFromFileTime).toBe(stat.mtimeMs) - expect(res).toMatchObject({ componentId: `test2` }) - - // read it with out updating - res = t.getTagsFromPath() - expect(t.lastEnvTagsFromFileTime).toBe(stat.mtimeMs) - expect(res).toMatchObject({ componentId: `test2` }) - fs.unlinkSync(filePath) - - const filePath2 = path.join(fs.realpathSync(os.tmpdir()), uuidv4()) - process.env.GATSBY_TELEMETRY_METADATA_PATH = filePath2 - res = t.getTagsFromPath() - expect(t.lastEnvTagsFromFileTime).toBe(stat.mtimeMs) - expect(res).toMatchObject({}) - }, 10000) - }) - - it(`getTagsFromPath is used for buildEvent`, async () => { - const t = new AnalyticsTracker({ - componentId: `component`, - }) - t.buildAndStoreEvent(`demo`, {}) - expect( - (EventStorage as jest.Mock).mock.instances[1].addEvent - ).toHaveBeenCalledWith( - expect.objectContaining({ - eventType: `demo`, - componentId: `component`, - }) - ) - const filePath = path.join(fs.realpathSync(os.tmpdir()), uuidv4()) - process.env.GATSBY_TELEMETRY_METADATA_PATH = filePath - fs.writeFileSync(filePath, JSON.stringify({ componentId: `test` })) - await new Promise(resolve => { - setTimeout(resolve, 2000) - }) - const stat = fs.statSync(filePath) - t.buildAndStoreEvent(`demo2`, {}) - - expect(t.lastEnvTagsFromFileTime).toBe(stat.mtimeMs) - expect( - (EventStorage as jest.Mock).mock.instances[1].addEvent - ).toHaveBeenCalledWith( - expect.objectContaining({ - eventType: `demo2`, - componentId: `test`, - }) - ) - - t.buildAndStoreEvent(`demo3`, {}) - expect( - (EventStorage as jest.Mock).mock.instances[1].addEvent - ).toHaveBeenCalledWith( - expect.objectContaining({ - eventType: `demo3`, - componentId: `test`, - }) - ) - - expect(t.lastEnvTagsFromFileTime).toBe(stat.mtimeMs) - - fs.writeFileSync(filePath, JSON.stringify({ componentId: `4` })) - await new Promise(resolve => { - setTimeout(resolve, 2000) - }) - const stat2 = fs.statSync(filePath) - - t.buildAndStoreEvent(`demo4`, {}) - expect(t.lastEnvTagsFromFileTime).toBe(stat2.mtimeMs) - expect( - (EventStorage as jest.Mock).mock.instances[1].addEvent - ).toHaveBeenCalledWith( - expect.objectContaining({ - eventType: `demo4`, - componentId: `4`, - }) - ) - fs.unlinkSync(filePath) - }, 10000) -}) diff --git a/packages/gatsby-telemetry/src/create-flush.ts b/packages/gatsby-telemetry/src/create-flush.ts index 3279667163fed..83205b307158c 100644 --- a/packages/gatsby-telemetry/src/create-flush.ts +++ b/packages/gatsby-telemetry/src/create-flush.ts @@ -1,28 +1,4 @@ -import { isCI } from "gatsby-core-utils" -const { join } = require(`path`) -const { fork, spawnSync } = require(`child_process`) -import time, { TimeUnit } from "@turist/time" - -export function createFlush(isTrackingEnabled: boolean): () => Promise { - return async function flush(): Promise { - if (!isTrackingEnabled) { - return - } - - if (isCI()) { - spawnSync(process.execPath, [join(__dirname, `send.js`)], { - execArgv: [], - timeout: time(1, TimeUnit.Minute), - }) - return - } - // Submit events on background with out blocking the main process - // nor relying on it's life cycle - const forked = fork(join(__dirname, `send.js`), { - detached: true, - stdio: `ignore`, - execArgv: [], - }) - forked.unref() - } +/* eslint-disable @typescript-eslint/no-unused-vars */ +export function createFlush(_isTrackingEnabled: boolean): () => Promise { + return async function flush(): Promise {} } diff --git a/packages/gatsby-telemetry/src/event-storage.ts b/packages/gatsby-telemetry/src/event-storage.ts index a1eb51deb5499..ba480bf04b546 100644 --- a/packages/gatsby-telemetry/src/event-storage.ts +++ b/packages/gatsby-telemetry/src/event-storage.ts @@ -1,12 +1,10 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ + import path from "path" -import Configstore from "configstore" -import createFetch from "@turist/fetch" import { Store } from "./store" import { ensureDirSync } from "fs-extra" -import { isTruthy } from "gatsby-core-utils" -import { InMemoryConfigStore } from "./in-memory-store" -const fetch = createFetch() +import { InMemoryConfigStore } from "./in-memory-store" /* The events data collection is a spooled process that * buffers events to a local fs based buffer @@ -15,20 +13,15 @@ const fetch = createFetch() * to continue even when working offline. */ export class EventStorage { - analyticsApi = - process.env.GATSBY_TELEMETRY_API || `https://analytics.gatsbyjs.com/events` - config: Configstore | InMemoryConfigStore + analyticsApi = process.env.GATSBY_TELEMETRY_API + config: InMemoryConfigStore store: Store verbose: boolean debugEvents: boolean disabled: boolean constructor() { - try { - this.config = new Configstore(`gatsby`, {}, { globalConfigPath: true }) - } catch (e) { - this.config = new InMemoryConfigStore() - } + this.config = new InMemoryConfigStore() const baseDir = path.dirname(this.config.path) @@ -39,59 +32,23 @@ export class EventStorage { } this.store = new Store(baseDir) - this.verbose = isTruthy(process.env.GATSBY_TELEMETRY_VERBOSE) - this.debugEvents = isTruthy(process.env.GATSBY_TELEMETRY_DEBUG) - this.disabled = isTruthy(process.env.GATSBY_TELEMETRY_DISABLED) + this.verbose = false + this.debugEvents = false + this.disabled = true } isTrackingDisabled(): boolean { return this.disabled } - addEvent(event: unknown): void { - if (this.disabled) { - return - } - - const eventString = JSON.stringify(event) - - if (this.debugEvents || this.verbose) { - console.log(`Captured event:`, JSON.parse(eventString)) - - if (this.debugEvents) { - // Bail because we don't want to send debug events - return - } - } - - this.store.appendToBuffer(eventString + `\n`) - } + addEvent(_event: unknown): void {} async sendEvents(): Promise { - return this.store.startFlushEvents(async (eventsData: string) => { - const events = eventsData - .split(`\n`) - .filter(e => e && e.length > 2) // drop empty lines - .map(e => JSON.parse(e)) - - return this.submitEvents(events) - }) + return true } - async submitEvents(events: unknown): Promise { - try { - const res = await fetch(this.analyticsApi, { - method: `POST`, - headers: { - "content-type": `application/json`, - "user-agent": this.getUserAgent(), - }, - body: JSON.stringify(events), - }) - return res.ok - } catch (e) { - return false - } + async submitEvents(_events: unknown): Promise { + return true } getUserAgent(): string { @@ -103,11 +60,11 @@ export class EventStorage { } } - getConfig(key: string): string | boolean | Record { + getConfig(key: string): string | boolean | unknown | Record { if (key) { return this.config.get(key) } - return this.config.all + return this.config.all() } updateConfig(key: string, value: string | number | boolean | null): void { diff --git a/packages/gatsby-telemetry/src/index.ts b/packages/gatsby-telemetry/src/index.ts index 4152eb7203519..68dc1c806da22 100644 --- a/packages/gatsby-telemetry/src/index.ts +++ b/packages/gatsby-telemetry/src/index.ts @@ -1,121 +1,120 @@ -import { +/* eslint-disable @typescript-eslint/no-unused-vars */ +import type { AnalyticsTracker, IAggregateStats, ITelemetryTagsPayload, ITelemetryOptsPayload, IDefaultTelemetryTagsPayload, } from "./telemetry" -import { Request, Response } from "express" -import { createFlush } from "./create-flush" -import time, { TimeUnit } from "@turist/time" +import type { Request, Response } from "express" -const instance = new AnalyticsTracker() +export const flush = (): Promise => Promise.resolve() -export const flush = createFlush(instance.isTrackingEnabled()) - -process.on(`exit`, flush) - -// For long running commands we want to occasionally flush the data -// -// The data is also sent on exit. - -const intervalDuration = process.env.TELEMETRY_BUFFER_INTERVAL -const interval = - intervalDuration && Number.isFinite(+intervalDuration) - ? Math.max(Number(intervalDuration), 1000) - : time(10, TimeUnit.Minute) - -function tick(): void { - flush() - .catch(console.error) - .then(() => setTimeout(tick, interval)) -} - -export function trackFeatureIsUsed(name: string): void { - instance.trackFeatureIsUsed(name) +export function trackFeatureIsUsed(_name: string): void { + // no_op } export function trackCli( - input: string | Array, - tags?: ITelemetryTagsPayload, - opts?: ITelemetryOptsPayload + _input: string | Array, + _tags?: ITelemetryTagsPayload, + _opts?: ITelemetryOptsPayload ): void { - instance.trackCli(input, tags, opts) + // no_op } export function captureEvent( - input: string | Array, - tags?: ITelemetryTagsPayload, - opts?: ITelemetryOptsPayload + _input: string | Array, + _tags?: ITelemetryTagsPayload, + _opts?: ITelemetryOptsPayload ): void { - instance.captureEvent(input, tags, opts) + // no_op } -export function trackError(input: string, tags?: ITelemetryTagsPayload): void { - instance.captureError(input, tags) +export function trackError( + _input: string, + _tags?: ITelemetryTagsPayload +): void { + // no_op } export function trackBuildError( - input: string, - tags?: ITelemetryTagsPayload + _input: string, + _tags?: ITelemetryTagsPayload ): void { - instance.captureBuildError(input, tags) + // no_op } -export function setDefaultTags(tags: IDefaultTelemetryTagsPayload): void { - instance.decorateAll(tags) +export function setDefaultTags(_tags: IDefaultTelemetryTagsPayload): void { + // no_op } export function decorateEvent( - event: string, - tags?: Record + _event: string, + _tags?: Record ): void { - instance.decorateNextEvent(event, tags) + // no_op } -export function setTelemetryEnabled(enabled: boolean): void { - instance.setTelemetryEnabled(enabled) +export function setTelemetryEnabled(_enabled: boolean): void { + // no_op } export function startBackgroundUpdate(): void { - setTimeout(tick, interval) + // no_op } export function isTrackingEnabled(): boolean { - return instance.isTrackingEnabled() + return false } export function aggregateStats(data: Array): IAggregateStats { - return instance.aggregateStats(data) + const sum = data.reduce((acc, x) => acc + x, 0) + const mean = sum / data.length || 0 + const median = data.sort()[Math.floor((data.length - 1) / 2)] || 0 + const stdDev = + Math.sqrt( + data.reduce((acc, x) => acc + Math.pow(x - mean, 2), 0) / + (data.length - 1) + ) || 0 + + const skewness = + data.reduce((acc, x) => acc + Math.pow(x - mean, 3), 0) / + data.length / + Math.pow(stdDev, 3) + + return { + count: data.length, + min: data.reduce((acc, x) => (x < acc ? x : acc), data[0] || 0), + max: data.reduce((acc, x) => (x > acc ? x : acc), 0), + sum: sum, + mean: mean, + median: median, + stdDev: stdDev, + skewness: !Number.isNaN(skewness) ? skewness : 0, + } } export function addSiteMeasurement( - event: string, - obj: ITelemetryTagsPayload["siteMeasurements"] + _event: string, + _obj: ITelemetryTagsPayload["siteMeasurements"] ): void { - instance.addSiteMeasurement(event, obj) -} - -export function expressMiddleware(source: string) { - return function (req: Request, _res: Response, next): void { - try { - instance.trackActivity(`${source}_ACTIVE`, { - userAgent: req.headers[`user-agent`], - }) - } catch (e) { - // ignore - } + // no_op +} + +export function expressMiddleware(_source: string) { + return function (_req: Request, _res: Response, next): void { + // no_op next() } } // Internal -export function setDefaultComponentId(componentId: string): void { - instance.componentId = componentId +export function setDefaultComponentId(_componentId: string): void { + // no_op } -export function setGatsbyCliVersion(version: string): void { - instance.gatsbyCliVersion = version +export function setGatsbyCliVersion(_version: string): void { + // no_op } export { diff --git a/packages/gatsby-telemetry/src/postinstall.js b/packages/gatsby-telemetry/src/postinstall.js deleted file mode 100644 index 329a98cb430fa..0000000000000 --- a/packages/gatsby-telemetry/src/postinstall.js +++ /dev/null @@ -1,14 +0,0 @@ -try { - const showAnalyticsNotification = require(`./showAnalyticsNotification`) - const { isCI } = require(`gatsby-core-utils`) - const { EventStorage } = require(`./event-storage`) - - const eventStorage = new EventStorage() - const disabled = eventStorage.disabled - const enabledInConfig = eventStorage.getConfig(`telemetry.enabled`) - if (enabledInConfig === undefined && !disabled && !isCI()) { - showAnalyticsNotification() - } -} catch (e) { - // ignore -} diff --git a/packages/gatsby-telemetry/src/send.ts b/packages/gatsby-telemetry/src/send.ts index fd9885460b174..e89c38a7a07c4 100644 --- a/packages/gatsby-telemetry/src/send.ts +++ b/packages/gatsby-telemetry/src/send.ts @@ -1,10 +1 @@ -import { AnalyticsTracker } from "./telemetry" -const instance = new AnalyticsTracker() - -function flush(): void { - instance.sendEvents().catch(_e => { - // ignore - }) -} - -flush() +// no-op diff --git a/packages/gatsby-telemetry/src/show-analytics-notification.ts b/packages/gatsby-telemetry/src/show-analytics-notification.ts deleted file mode 100644 index 05aa5869487ba..0000000000000 --- a/packages/gatsby-telemetry/src/show-analytics-notification.ts +++ /dev/null @@ -1,24 +0,0 @@ -import boxen from "boxen" - -const defaultConfig = { - padding: 1, - borderColor: `blue`, - borderStyle: `double`, -} as boxen.Options - -const defaultMessage = - `Gatsby collects anonymous usage analytics\n` + - `to help improve Gatsby for all users.\n` + - `\n` + - `If you'd like to opt-out, you can use \`gatsby telemetry --disable\`\n` + - `To learn more, checkout https://gatsby.dev/telemetry` - -/** - * Analytics notice for the end-user - */ -export function showAnalyticsNotification( - config: boxen.Options = defaultConfig, - message: string = defaultMessage -): void { - console.log(boxen(message, config)) -} diff --git a/packages/gatsby-telemetry/src/telemetry.ts b/packages/gatsby-telemetry/src/telemetry.ts index 345687cb545c1..e3d807bc562b3 100644 --- a/packages/gatsby-telemetry/src/telemetry.ts +++ b/packages/gatsby-telemetry/src/telemetry.ts @@ -1,29 +1,14 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ + import * as fs from "fs-extra" import os from "os" -import { - isCI, - getCIName, - createContentDigest, - getTermProgram, - uuid, -} from "gatsby-core-utils" +import { createContentDigest, getTermProgram, uuid } from "gatsby-core-utils" import { getRepositoryId as _getRepositoryId, IRepositoryId, } from "./repository-id" -import { createFlush } from "./create-flush" -import { EventStorage } from "./event-storage" -import { showAnalyticsNotification } from "./show-analytics-notification" -import { cleanPaths } from "./error-helpers" -import { getDependencies } from "./get-dependencies" - -import isDocker from "is-docker" -import lodash from "lodash" - -const typedUUIDv4 = uuid.v4 as () => string const finalEventRegex = /(END|STOP)$/ -const dbEngine = `redux` export type SemVer = string @@ -129,8 +114,6 @@ export interface ITelemetryOptsPayload { } export class AnalyticsTracker { - store = new EventStorage() - componentId: string debouncer = {} metadataCache = {} defaultTags = {} @@ -141,37 +124,13 @@ export class AnalyticsTracker { gatsbyCliVersion?: SemVer installedGatsbyVersion?: SemVer repositoryId?: IRepositoryId - features = new Set() - machineId: string + siteHash?: string = createContentDigest(process.cwd()) lastEnvTagsFromFileTime = 0 lastEnvTagsFromFileValue: ITelemetryTagsPayload = {} - constructor({ - componentId, - gatsbyCliVersion, - trackingEnabled, - }: IAnalyticsTrackerConstructorParameters = {}) { - this.componentId = componentId || `gatsby-cli` - try { - if (this.store.isTrackingDisabled()) { - this.trackingEnabled = false - } - if (trackingEnabled !== undefined) { - this.trackingEnabled = trackingEnabled - } - - this.defaultTags = this.getTagsFromEnv() - - // These may throw and should be last - this.componentVersion = require(`../package.json`).version - this.gatsbyCliVersion = gatsbyCliVersion || this.getGatsbyCliVersion() - this.installedGatsbyVersion = this.getGatsbyVersion() - } catch (e) { - // ignore - } - this.machineId = this.getMachineId() - this.captureMetadataEvent() + constructor(_arg: IAnalyticsTrackerConstructorParameters = {}) { + // no-op } // We might have two instances of this lib loaded, one from globally installed gatsby-cli and one from local gatsby. @@ -206,13 +165,6 @@ export class AnalyticsTracker { } getTagsFromEnv(): Record { - if (process.env.GATSBY_TELEMETRY_TAGS) { - try { - return JSON.parse(process.env.GATSBY_TELEMETRY_TAGS) - } catch (_) { - // ignore - } - } return {} } @@ -239,155 +191,34 @@ export class AnalyticsTracker { } trackCli( - type: string | Array = ``, - tags: ITelemetryTagsPayload = {}, - opts: ITelemetryOptsPayload = { debounce: false } - ): void { - if (!this.isTrackingEnabled()) { - return - } - if (typeof tags.siteHash === `undefined`) { - tags.siteHash = this.siteHash - } - this.captureEvent(type, tags, opts) - } + _type: string | Array = ``, + _tags: ITelemetryTagsPayload = {}, + _opts: ITelemetryOptsPayload = { debounce: false } + ): void {} captureEvent( - type: string | Array = ``, - tags: ITelemetryTagsPayload = {}, - opts: ITelemetryOptsPayload = { debounce: false } - ): void { - if (!this.isTrackingEnabled()) { - return - } - let baseEventType = `CLI_COMMAND` - if (Array.isArray(type)) { - type = type.length > 2 ? type[2].toUpperCase() : `` - baseEventType = `CLI_RAW_COMMAND` - } - - const decoration = this.metadataCache[type] - const eventType = `${baseEventType}_${type}` - - if (opts.debounce) { - const debounceTime = 5 * 1000 - const now = Date.now() - const debounceKey = JSON.stringify({ type, decoration, tags }) - const last = this.debouncer[debounceKey] || 0 - if (now - last < debounceTime) { - return - } - this.debouncer[debounceKey] = now - } - - delete this.metadataCache[type] - this.buildAndStoreEvent(eventType, lodash.merge({}, tags, decoration)) - } + _type: string | Array = ``, + _tags: ITelemetryTagsPayload = {}, + _opts: ITelemetryOptsPayload = { debounce: false } + ): void {} isFinalEvent(event: string): boolean { return finalEventRegex.test(event) } - captureError(type: string, tags: ITelemetryTagsPayload = {}): void { - if (!this.isTrackingEnabled()) { - return - } + captureError(_type: string, _tags: ITelemetryTagsPayload = {}): void {} - const decoration = this.metadataCache[type] - delete this.metadataCache[type] - const eventType = `CLI_ERROR_${type}` - - this.formatErrorAndStoreEvent(eventType, lodash.merge({}, tags, decoration)) - } - - captureBuildError(type: string, tags: ITelemetryTagsPayload = {}): void { - if (!this.isTrackingEnabled()) { - return - } - const decoration = this.metadataCache[type] - delete this.metadataCache[type] - const eventType = `BUILD_ERROR_${type}` - - this.formatErrorAndStoreEvent(eventType, lodash.merge({}, tags, decoration)) - } + captureBuildError(_type: string, _tags: ITelemetryTagsPayload = {}): void {} formatErrorAndStoreEvent( - eventType: string, - tags: ITelemetryTagsPayload - ): void { - if (tags.error) { - // `error` ought to have been `errors` but is `error` in the database - if (Array.isArray(tags.error)) { - const { error, ...restOfTags } = tags - error.forEach(err => { - this.formatErrorAndStoreEvent(eventType, { - error: err, - ...restOfTags, - }) - }) - return - } - - tags.errorV2 = { - // errorCode field was changed from `id` to `code` - id: tags.error.code || tags.error.id, - text: cleanPaths(tags.error.text), - level: tags.error.level, - type: tags.error?.type, - // see if we need empty string or can just use NULL - stack: cleanPaths(tags.error?.error?.stack || ``), - context: cleanPaths(JSON.stringify(tags.error?.context)), - } + _eventType: string, + _tags: ITelemetryTagsPayload + ): void {} - delete tags.error - } - - this.buildAndStoreEvent(eventType, tags) - } - - buildAndStoreEvent(eventType: string, tags: ITelemetryTagsPayload): void { - const event = { - installedGatsbyVersion: this.installedGatsbyVersion, - gatsbyCliVersion: this.gatsbyCliVersion, - ...lodash.merge({}, this.defaultTags, tags), // The schema must include these - eventType, - sessionId: this.sessionId, - time: new Date(), - machineId: this.getMachineId(), - componentId: this.componentId, - osInformation: this.getOsInfo(), - componentVersion: this.componentVersion, - dbEngine, - features: Array.from(this.features), - ...this.getRepositoryId(), - ...this.getTagsFromPath(), - } - this.store.addEvent(event) - if (this.isFinalEvent(eventType)) { - // call create flush - const flush = createFlush(this.isTrackingEnabled()) - flush() - } - } + buildAndStoreEvent(_eventType: string, _tags: ITelemetryTagsPayload): void {} getTagsFromPath(): ITelemetryTagsPayload { - const path = process.env.GATSBY_TELEMETRY_METADATA_PATH - - if (!path) { - return {} - } - try { - const stat = fs.statSync(path) - if (this.lastEnvTagsFromFileTime < stat.mtimeMs) { - this.lastEnvTagsFromFileTime = stat.mtimeMs - const data = fs.readFileSync(path, `utf8`) - this.lastEnvTagsFromFileValue = JSON.parse(data) - } - } catch (e) { - // nop - return {} - } - return this.lastEnvTagsFromFileValue + return {} } getIsTTY(): boolean { @@ -395,34 +226,11 @@ export class AnalyticsTracker { } getMachineId(): string { - // Cache the result - if (this.machineId) { - return this.machineId - } - let machineId = this.store.getConfig(`telemetry.machineId`) - if (typeof machineId !== `string`) { - machineId = typedUUIDv4() - this.store.updateConfig(`telemetry.machineId`, machineId) - } - this.machineId = machineId - return machineId + return `` } isTrackingEnabled(): boolean { - // Cache the result - if (this.trackingEnabled !== undefined) { - return this.trackingEnabled - } - let enabled = this.store.getConfig(`telemetry.enabled`) as boolean | null - if (enabled === undefined || enabled === null) { - if (!isCI()) { - showAnalyticsNotification() - } - enabled = true - this.store.updateConfig(`telemetry.enabled`, enabled) - } - this.trackingEnabled = enabled - return enabled + return false } getOsInfo(): IOSInfo { @@ -436,9 +244,9 @@ export class AnalyticsTracker { release: os.release(), cpus: (cpus && cpus.length > 0 && cpus[0].model) || undefined, arch: os.arch(), - ci: isCI(), - ciName: getCIName(), - docker: isDocker(), + ci: false, + ciName: null, + docker: false, termProgram: getTermProgram(), isTTY: this.getIsTTY(), } @@ -446,45 +254,18 @@ export class AnalyticsTracker { return osInfo } - trackActivity(source: string, tags: ITelemetryTagsPayload = {}): void { - if (!this.isTrackingEnabled()) { - return - } - // debounce by sending only the first event within a rolling window - const now = Date.now() - const last = this.debouncer[source] || 0 - const debounceTime = 5 * 1000 // 5 sec + trackActivity(_source: string, _tags: ITelemetryTagsPayload = {}): void {} - if (now - last > debounceTime) { - this.captureEvent(source, tags) - } - this.debouncer[source] = now - } - - decorateNextEvent(event: string, obj): void { - const cached = this.metadataCache[event] || {} - this.metadataCache[event] = Object.assign(cached, obj) - } + decorateNextEvent(_event: string, _obj): void {} addSiteMeasurement( - event: string, - obj: ITelemetryTagsPayload["siteMeasurements"] - ): void { - const cachedEvent = this.metadataCache[event] || {} - const cachedMeasurements = cachedEvent.siteMeasurements || {} - this.metadataCache[event] = Object.assign(cachedEvent, { - siteMeasurements: Object.assign(cachedMeasurements, obj), - }) - } + _event: string, + _obj: ITelemetryTagsPayload["siteMeasurements"] + ): void {} - decorateAll(tags: ITelemetryTagsPayload): void { - this.defaultTags = Object.assign(this.defaultTags, tags) - } + decorateAll(_tags: ITelemetryTagsPayload): void {} - setTelemetryEnabled(enabled: boolean): void { - this.trackingEnabled = enabled - this.store.updateConfig(`telemetry.enabled`, enabled) - } + setTelemetryEnabled(_enabled: boolean): void {} aggregateStats(data: Array): IAggregateStats { const sum = data.reduce((acc, x) => acc + x, 0) @@ -513,28 +294,11 @@ export class AnalyticsTracker { } } - captureMetadataEvent(): void { - if (!this.isTrackingEnabled()) { - return - } - const deps = getDependencies() - const evt = { - dependencies: deps?.dependencies, - devDependencies: deps?.devDependencies, - } - - this.captureEvent(`METADATA`, evt) - } + captureMetadataEvent(): void {} async sendEvents(): Promise { - if (!this.isTrackingEnabled()) { - return true - } - - return this.store.sendEvents() + return true } - trackFeatureIsUsed(name: string): void { - this.features.add(name) - } + trackFeatureIsUsed(_name: string): void {} } diff --git a/packages/gatsby/package.json b/packages/gatsby/package.json index e29bc03c362e7..cc1e59c382768 100644 --- a/packages/gatsby/package.json +++ b/packages/gatsby/package.json @@ -103,7 +103,6 @@ "gatsby-plugin-utils": "^4.14.0-next.2", "gatsby-react-router-scroll": "^6.14.0-next.2", "gatsby-script": "^2.14.0-next.1", - "gatsby-telemetry": "^4.14.0-next.2", "gatsby-worker": "^2.14.0-next.2", "glob": "^7.2.3", "globby": "^11.1.0", diff --git a/packages/gatsby/src/bootstrap/load-config/index.ts b/packages/gatsby/src/bootstrap/load-config/index.ts index 44282be0f2580..816f9dea43cda 100644 --- a/packages/gatsby/src/bootstrap/load-config/index.ts +++ b/packages/gatsby/src/bootstrap/load-config/index.ts @@ -1,5 +1,4 @@ import reporter from "gatsby-cli/lib/reporter" -import telemetry from "gatsby-telemetry" import { preferDefault } from "../prefer-default" import { getConfigFile } from "../get-config-file" import { internalActions } from "../../redux/actions" @@ -62,18 +61,6 @@ export async function loadConfig({ } process.env.GATSBY_SLICES = `true` - - // track usage of feature - enabledConfigFlags.forEach(flag => { - if (flag.telemetryId) { - telemetry.trackFeatureIsUsed(flag.telemetryId) - } - }) - - // Track the usage of config.flags - if (config?.flags) { - telemetry.trackFeatureIsUsed(`ConfigFlags`) - } } // theme gatsby configs can be functions or objects diff --git a/packages/gatsby/src/bootstrap/load-plugins/validate.ts b/packages/gatsby/src/bootstrap/load-plugins/validate.ts index 059a38d72775a..b553f0eb88e78 100644 --- a/packages/gatsby/src/bootstrap/load-plugins/validate.ts +++ b/packages/gatsby/src/bootstrap/load-plugins/validate.ts @@ -7,7 +7,6 @@ import reporter from "gatsby-cli/lib/reporter" import { validateOptionsSchema, Joi } from "gatsby-plugin-utils" import { IPluginRefObject } from "gatsby-plugin-utils/dist/types" import { stripIndent } from "common-tags" -import { trackCli } from "gatsby-telemetry" import { isWorker } from "gatsby-worker" import { resolveModuleExports } from "../resolve-module-exports" import { getLatestAPIs } from "../../utils/get-latest-gatsby-files" @@ -362,12 +361,6 @@ async function validatePluginsOptions( } if you believe this option is valid. `) ) - trackCli(`UNKNOWN_PLUGIN_OPTION`, { - name: plugin.resolve, - valueString: validationWarnings - .map(error => error.path.join(`.`)) - .join(`, `), - }) // We do not increment errors++ here as we do not want to process.exit if there are only warnings } diff --git a/packages/gatsby/src/commands/build.ts b/packages/gatsby/src/commands/build.ts index a4b5ca390a9a3..ff669d2fe606c 100644 --- a/packages/gatsby/src/commands/build.ts +++ b/packages/gatsby/src/commands/build.ts @@ -1,8 +1,6 @@ import path from "path" import report from "gatsby-cli/lib/reporter" -import signalExit from "signal-exit" import fs from "fs-extra" -import telemetry from "gatsby-telemetry" import { updateInternalSiteMetadata, isTruthy, @@ -60,7 +58,6 @@ import { } from "../utils/page-ssr-module/bundle-webpack" import { shouldGenerateEngines } from "../utils/engines-helpers" import reporter from "gatsby-cli/lib/reporter" -import type webpack from "webpack" import { materializePageMode, getPageMode, @@ -117,13 +114,6 @@ module.exports = async function build( const buildActivity = report.phantomActivity(`build`) buildActivity.start() - telemetry.trackCli(`BUILD_START`) - signalExit(exitCode => { - telemetry.trackCli(`BUILD_END`, { - exitCode: exitCode as number | undefined, - }) - }) - const buildSpan = buildActivity.span buildSpan.setTag(`directory`, program.directory) @@ -155,7 +145,6 @@ module.exports = async function build( let closeJavascriptBundleCompilation: (() => Promise) | undefined let closeHTMLBundleCompilation: (() => Promise) | undefined let closePartialHydrationBundleCompilation: (() => Promise) | undefined - let webpackAssets: Array | null = null let webpackCompilationHash: string | null = null let webpackSSRCompilationHash: string | null = null let templateCompilationHashes: Record = {} @@ -179,11 +168,6 @@ module.exports = async function build( reportWebpackWarnings(rawMessages.warnings, report) } - webpackAssets = stats.toJson({ - all: false, - assets: true, - cachedAssets: true, - }).assets as Array webpackCompilationHash = stats.hash as string } catch (err) { buildActivityTimer.panic(structureWebpackErrors(Stage.BuildJavascript, err)) @@ -382,13 +366,6 @@ module.exports = async function build( SSGCount++ } } - - telemetry.addSiteMeasurement(`BUILD_END`, { - totalPagesCount: store.getState().pages.size, // total number of pages - SSRCount, - DSGCount, - SSGCount, - }) } await copyStaticQueriesToEngine({ @@ -510,20 +487,6 @@ module.exports = async function build( // an equivalent static directory within public. copyStaticDirs() - if (telemetry.isTrackingEnabled()) { - // transform asset size to kB (from bytes) to fit 64 bit to numbers - const bundleSizes = (webpackAssets as Array) - .filter(asset => asset.name.endsWith(`.js`)) - .map(asset => asset.size / 1000) - const pageDataSizes = [...store.getState().pageDataStats.values()] - - telemetry.addSiteMeasurement(`BUILD_END`, { - bundleStats: telemetry.aggregateStats(bundleSizes), - pageDataStats: telemetry.aggregateStats(pageDataSizes), - queryStats: graphqlRunner.getStats(), - }) - } - store.dispatch(actions.setProgramStatus(`BOOTSTRAP_QUERY_RUNNING_FINISHED`)) await db.saveState() @@ -586,9 +549,6 @@ module.exports = async function build( } } - telemetry.addSiteMeasurement(`BUILD_END`, { - totalPagesCount: store.getState().pages.size, // total number of pages - }) const postBuildActivityTimer = report.activityTimer(`onPostBuild`, { parentSpan: buildSpan, }) diff --git a/packages/gatsby/src/commands/develop-process.ts b/packages/gatsby/src/commands/develop-process.ts index 20c4b3649adf9..fb3dad5b3e6dd 100644 --- a/packages/gatsby/src/commands/develop-process.ts +++ b/packages/gatsby/src/commands/develop-process.ts @@ -1,12 +1,10 @@ import { syncStaticDir } from "../utils/get-static-dir" import reporter from "gatsby-cli/lib/reporter" -import telemetry from "gatsby-telemetry" import { isTruthy } from "gatsby-core-utils" import express from "express" import inspector from "inspector" import { initTracer } from "../utils/tracer" import { detectPortInUseAndPrompt } from "../utils/detect-port-in-use-and-prompt" -import onExit from "signal-exit" import { userGetsSevenDayFeedback, userPassesFeedbackRequestHeuristic, @@ -14,7 +12,6 @@ import { showSevenDayFeedbackRequest, } from "../utils/feedback" import { markWebpackStatusAsPending } from "../utils/webpack-status" -import { store } from "../redux" import { IProgram, IDebugInfo } from "./types" import { interpret } from "xstate" @@ -47,30 +44,6 @@ if (process.send) { }, 1000) } -onExit(() => { - let SSGCount = 0 - let DSGCount = 0 - let SSRCount = 0 - for (const page of store.getState().pages.values()) { - if (page.mode === `SSR`) { - SSRCount++ - } else if (page.mode === `DSG`) { - DSGCount++ - } else { - SSGCount++ - } - } - - telemetry.trackCli(`DEVELOP_STOP`, { - siteMeasurements: { - totalPagesCount: store.getState().pages.size, - SSRCount, - DSGCount, - SSGCount, - }, - }) -}) - process.on( `message`, (msg: { @@ -133,8 +106,6 @@ module.exports = async (program: IDevelopArgs): Promise => { ) markWebpackStatusAsPending() reporter.pendingActivity({ id: `webpack-develop` }) - telemetry.trackCli(`DEVELOP_START`) - telemetry.startBackgroundUpdate() const port = typeof program.port === `string` ? parseInt(program.port, 10) : program.port diff --git a/packages/gatsby/src/commands/develop.ts b/packages/gatsby/src/commands/develop.ts index 94d6289bb7bb5..43c7fd40231be 100644 --- a/packages/gatsby/src/commands/develop.ts +++ b/packages/gatsby/src/commands/develop.ts @@ -11,7 +11,6 @@ import { slash } from "gatsby-core-utils/path" import reporter from "gatsby-cli/lib/reporter" import { getSslCert } from "../utils/get-ssl-cert" import { IProgram, IDebugInfo } from "./types" -import { flush as telemetryFlush } from "gatsby-telemetry" // Adapted from https://stackoverflow.com/a/16060619 const requireUncached = (file: string): any => { @@ -258,11 +257,6 @@ module.exports = async (program: IProgram): Promise => { // This needs to be propagated back to the parent process developProcess.onExit( (code: number | null, signal: NodeJS.Signals | null) => { - try { - telemetryFlush() - } catch (e) { - // nop - } if (isRestarting) return if (signal !== null) { process.kill(process.pid, signal) @@ -331,11 +325,6 @@ function shutdownServices( { developProcess }: IShutdownServicesOptions, signal: NodeJS.Signals ): Promise { - try { - telemetryFlush() - } catch (e) { - // nop - } const services = [developProcess.stop(signal)] return Promise.all(services) diff --git a/packages/gatsby/src/commands/repl.ts b/packages/gatsby/src/commands/repl.ts index 34739739720c0..8b9afd76c5177 100644 --- a/packages/gatsby/src/commands/repl.ts +++ b/packages/gatsby/src/commands/repl.ts @@ -1,14 +1,12 @@ import repl from "repl" import { graphql } from "graphql" import { bootstrap } from "../bootstrap" -import { trackCli } from "gatsby-telemetry" import { getNodes, getNode, getNodesByType } from "../datastore" import { loadNodeContent } from "../utils/nodes" import { store } from "../redux" import { IProgram } from "./types" module.exports = async (program: IProgram): Promise => { - trackCli(`REPL_START`) // run bootstrap await bootstrap({ program }) @@ -48,7 +46,6 @@ module.exports = async (program: IProgram): Promise => { _.context.staticQueries = staticQueryComponents _.on(`exit`, () => { - trackCli(`REPL_STOP`) process.exit(0) }) } diff --git a/packages/gatsby/src/commands/serve.ts b/packages/gatsby/src/commands/serve.ts index 415b689806d6b..e62dd06d315d0 100644 --- a/packages/gatsby/src/commands/serve.ts +++ b/packages/gatsby/src/commands/serve.ts @@ -5,9 +5,7 @@ import compression from "compression" import express from "express" import chalk from "chalk" import { match as reachMatch } from "@gatsbyjs/reach-router" -import onExit from "signal-exit" import report from "gatsby-cli/lib/reporter" -import telemetry from "gatsby-telemetry" import { detectPortInUseAndPrompt } from "../utils/detect-port-in-use-and-prompt" import { getConfigFile } from "../bootstrap/get-config-file" @@ -40,10 +38,6 @@ interface IServeProgram extends IProgram { prefixPaths: boolean } -onExit(() => { - telemetry.trackCli(`SERVE_STOP`) -}) - const readMatchPaths = async ( program: IServeProgram ): Promise> => { @@ -100,8 +94,6 @@ const matchPathRouter = } module.exports = async (program: IServeProgram): Promise => { - telemetry.trackCli(`SERVE_START`) - telemetry.startBackgroundUpdate() await initTracer( process.env.GATSBY_OPEN_TRACING_CONFIG_FILE || program.openTracingConfigFile ) @@ -130,8 +122,6 @@ module.exports = async (program: IServeProgram): Promise => { // eslint-disable-next-line new-cap const router = express.Router() - app.use(telemetry.expressMiddleware(`SERVE`)) - router.use(compression()) router.use( diff --git a/packages/gatsby/src/query/__tests__/data-tracking.js b/packages/gatsby/src/query/__tests__/data-tracking.js index c121b3c175919..477c17fb57900 100644 --- a/packages/gatsby/src/query/__tests__/data-tracking.js +++ b/packages/gatsby/src/query/__tests__/data-tracking.js @@ -35,13 +35,6 @@ jest.mock(`fs-extra`, () => { } }) -jest.mock(`gatsby-telemetry`, () => { - return { - trackCli: () => {}, - captureEvent: () => {}, - } -}) - jest.mock(`../../utils/cache-lmdb`, () => { return { default: class MockedCache { diff --git a/packages/gatsby/src/redux/__tests__/index.js b/packages/gatsby/src/redux/__tests__/index.js index 009cc669ce44e..950cba334a600 100644 --- a/packages/gatsby/src/redux/__tests__/index.js +++ b/packages/gatsby/src/redux/__tests__/index.js @@ -1,7 +1,6 @@ const _ = require(`lodash`) const path = require(`path`) const v8 = require(`v8`) -const telemetry = require(`gatsby-telemetry`) const reporter = require(`gatsby-cli/lib/reporter`) const writeToCache = jest.spyOn(require(`../persist`), `writeToCache`) const v8Serialize = jest.spyOn(v8, `serialize`) @@ -163,26 +162,6 @@ describe(`redux db`, () => { reporterInfo.mockClear() }) - it(`should have cache status telemetry event`, async () => { - jest.spyOn(telemetry, `trackCli`) - - readState() - - expect(telemetry.trackCli).toHaveBeenCalledWith(`CACHE_STATUS`, { - cacheStatus: `COLD`, - }) - - store.getState().nodes = getFakeNodes() - - await saveState() - - readState() - - expect(telemetry.trackCli).toHaveBeenCalledWith(`CACHE_STATUS`, { - cacheStatus: `WARM`, - }) - }) - it(`should write redux cache to disk`, async () => { createPages(defaultPage) diff --git a/packages/gatsby/src/redux/actions/public.js b/packages/gatsby/src/redux/actions/public.js index e310857219774..da30fddc21b56 100644 --- a/packages/gatsby/src/redux/actions/public.js +++ b/packages/gatsby/src/redux/actions/public.js @@ -27,7 +27,6 @@ const { } = require(`../../utils/path`) const { applyTrailingSlashOption } = require(`gatsby-page-utils`) const apiRunnerNode = require(`../../utils/api-runner-node`) -const { trackCli } = require(`gatsby-telemetry`) const { getNonGatsbyCodeFrame } = require(`../../utils/stack-trace-utils`) const { getPageMode } = require(`../../utils/page-mode`) const normalizePath = require(`../../utils/normalize-path`).default @@ -720,8 +719,6 @@ const createNode = ( trackParams[`pluginName`] = `${plugin.name}@${plugin.version}` } - trackCli(`CREATE_NODE`, trackParams, { debounce: true }) - const result = nodeSchema.validate(node) if (result.error) { if (!hasErroredBecauseOfNodeValidation.has(result.error.message)) { diff --git a/packages/gatsby/src/redux/actions/restricted.ts b/packages/gatsby/src/redux/actions/restricted.ts index 0764b763f8010..c076e766b35c2 100644 --- a/packages/gatsby/src/redux/actions/restricted.ts +++ b/packages/gatsby/src/redux/actions/restricted.ts @@ -27,7 +27,6 @@ import { import { generateComponentChunkName } from "../../utils/js-chunk-names" import { store } from "../index" import normalizePath from "normalize-path" -import { trackFeatureIsUsed } from "gatsby-telemetry" import { validateComponent } from "../../utils/validate-component" type RestrictionActionNames = @@ -503,8 +502,6 @@ export const actions = { } } - trackFeatureIsUsed(`SliceAPI`) - const componentPath = normalizePath(payload.component) const oldSlice = slices.get(payload.id) diff --git a/packages/gatsby/src/redux/index.ts b/packages/gatsby/src/redux/index.ts index 5b4b5e81a9131..b05b6cce1ebf6 100644 --- a/packages/gatsby/src/redux/index.ts +++ b/packages/gatsby/src/redux/index.ts @@ -8,7 +8,6 @@ import { Store, } from "redux" import _ from "lodash" -import telemetry from "gatsby-telemetry" import { mett } from "../utils/mett" import thunk, { ThunkMiddleware, ThunkAction, ThunkDispatch } from "redux-thunk" @@ -74,16 +73,8 @@ export const readState = (): IGatsbyState => { // runs gatsby the first time after upgrading. delete state[`jsonDataPaths`] - telemetry.trackCli(`CACHE_STATUS`, { - cacheStatus: `WARM`, - }) - return state } catch (e) { - telemetry.trackCli(`CACHE_STATUS`, { - cacheStatus: `COLD`, - }) - return {} as IGatsbyState } } diff --git a/packages/gatsby/src/redux/save-state.js b/packages/gatsby/src/redux/save-state.js index c76a752f1fc21..e573000519656 100644 --- a/packages/gatsby/src/redux/save-state.js +++ b/packages/gatsby/src/redux/save-state.js @@ -1,6 +1,4 @@ -const _ = require(`lodash`) const report = require(`gatsby-cli/lib/reporter`) -const { captureEvent } = require(`gatsby-telemetry`) const redux = require(`./`) let saveInProgress = false @@ -8,24 +6,12 @@ async function saveState() { if (saveInProgress) return saveInProgress = true - const startTime = Date.now() - try { await redux.saveState() } catch (err) { report.warn(`Error persisting state: ${(err && err.message) || err}`) } - try { - const duration = (Date.now() - startTime) / 1000 - captureEvent(`INTERNAL_STATE_PERSISTENCE_DURATION`, { - name: `Save Internal State`, - duration: Math.round(duration), - }) - } catch (err) { - console.error(err) - } - saveInProgress = false } diff --git a/packages/gatsby/src/services/initialize.ts b/packages/gatsby/src/services/initialize.ts index fda5e3f1248dd..2144be3620eb1 100644 --- a/packages/gatsby/src/services/initialize.ts +++ b/packages/gatsby/src/services/initialize.ts @@ -4,7 +4,6 @@ import * as fs from "fs-extra" import { releaseAllMutexes } from "gatsby-core-utils/mutex" import { md5, md5File } from "gatsby-core-utils" import path from "path" -import telemetry from "gatsby-telemetry" import glob from "globby" import apiRunnerNode from "../utils/api-runner-node" @@ -59,8 +58,6 @@ Please give feedback on their respective umbrella issues! - https://gatsby.dev/dev-ssr-feedback - https://gatsby.dev/cache-clearing-feedback `) - - telemetry.trackFeatureIsUsed(`FastDev`) } // Show stack trace on unhandled promises. @@ -89,7 +86,6 @@ export async function initialize({ reporter.info( `GATSBY_DISABLE_CACHE_PERSISTENCE is enabled. Cache won't be persisted. Next builds will not be able to reuse any work done by current session.` ) - telemetry.trackFeatureIsUsed(`DisableCachePersistence`) } if (!args) { reporter.panic(`Missing program args`) @@ -239,17 +235,6 @@ export async function initialize({ // @ts-ignore we'll need to fix redux typings https://redux.js.org/usage/usage-with-typescript store.dispatch(removeStaleJobs(store.getState().jobsV2)) - // Multiple occurrences of the same name-version-pair can occur, - // so we report an array of unique pairs - const pluginsStr = _.uniq(flattenedPlugins.map(p => `${p.name}@${p.version}`)) - telemetry.decorateEvent(`BUILD_END`, { - plugins: pluginsStr, - }) - - telemetry.decorateEvent(`DEVELOP_STOP`, { - plugins: pluginsStr, - }) - // Start plugin runner which listens to the store // and invokes Gatsby API based on actions. startPluginRunner() @@ -471,15 +456,6 @@ export async function initialize({ // make sure all previous mutexes are released await releaseAllMutexes() - - // in future this should show which plugin's caches are purged - // possibly should also have which plugins had caches - telemetry.decorateEvent(`BUILD_END`, { - pluginCachesPurged: [`*`], - }) - telemetry.decorateEvent(`DEVELOP_STOP`, { - pluginCachesPurged: [`*`], - }) } // Update the store with the new plugins hash. @@ -630,9 +606,6 @@ export async function initialize({ }) activity.end() - // Track trailing slash option used in config - telemetry.trackFeatureIsUsed(`trailingSlash:${state.config.trailingSlash}`) - // Collect resolvable extensions and attach to program. const extensions = [`.mjs`, `.js`, `.jsx`, `.wasm`, `.json`] // Change to this being an action and plugins implement `onPreBootstrap` @@ -649,18 +622,7 @@ export async function initialize({ const workerPool = WorkerPool.create() - const siteDirectoryFiles = await fs.readdir(siteDirectory) - - const gatsbyFilesIsInESM = siteDirectoryFiles.some(file => - file.match(/gatsby-(node|config)\.mjs/) - ) - - if (gatsbyFilesIsInESM) { - telemetry.trackFeatureIsUsed(`ESMInGatsbyFiles`) - } - if (state.config.graphqlTypegen) { - telemetry.trackFeatureIsUsed(`GraphQLTypegen`) // This is only run during `gatsby develop` if (process.env.gatsby_executing_command === `develop`) { writeGraphQLConfig(program) diff --git a/packages/gatsby/src/utils/__tests__/__snapshots__/sample-site-for-experiment.ts.snap b/packages/gatsby/src/utils/__tests__/__snapshots__/sample-site-for-experiment.ts.snap deleted file mode 100644 index 50fe207f9a778..0000000000000 --- a/packages/gatsby/src/utils/__tests__/__snapshots__/sample-site-for-experiment.ts.snap +++ /dev/null @@ -1,17 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not: a 1`] = `true`; - -exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not: b 1`] = `false`; - -exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not: c 1`] = `false`; - -exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not: d 1`] = `true`; - -exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not: e 1`] = `true`; - -exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not: f 1`] = `false`; - -exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not: h 1`] = `false`; - -exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not: i 1`] = `false`; diff --git a/packages/gatsby/src/utils/__tests__/handle-flags.ts b/packages/gatsby/src/utils/__tests__/handle-flags.ts index 59eb724461fa7..1990d79f54551 100644 --- a/packages/gatsby/src/utils/__tests__/handle-flags.ts +++ b/packages/gatsby/src/utils/__tests__/handle-flags.ts @@ -1,6 +1,5 @@ import _ from "lodash" -import sampleSiteForExperiment from "../sample-site-for-experiment" import handleFlags from "../handle-flags" import { IFlag, satisfiesSemvers, fitnessEnum } from "../flags" @@ -91,13 +90,7 @@ describe(`handle flags`, () => { experimental: false, description: `test`, umbrellaIssue: `test`, - testFitness: (flag): fitnessEnum => { - if (sampleSiteForExperiment(flag.name, 100)) { - return `OPT_IN` - } else { - return false - } - }, + testFitness: (): fitnessEnum => `OPT_IN`, }, { name: `PARTIAL_RELEASE_ONLY_VERY_OLD_LODASH`, @@ -112,10 +105,7 @@ describe(`handle flags`, () => { // Because of this, this flag will never show up lodash: `<=3.9`, } - if ( - satisfiesSemvers(semver) && - sampleSiteForExperiment(flag.name, 100) - ) { + if (satisfiesSemvers(semver)) { return `OPT_IN` } else { return false @@ -135,10 +125,7 @@ describe(`handle flags`, () => { // Because of this, this flag will never show up lodash: `>=4.9`, } - if ( - satisfiesSemvers(semver) && - sampleSiteForExperiment(flag.name, 100) - ) { + if (satisfiesSemvers(semver)) { return `OPT_IN` } else { return false diff --git a/packages/gatsby/src/utils/__tests__/sample-site-for-experiment.ts b/packages/gatsby/src/utils/__tests__/sample-site-for-experiment.ts deleted file mode 100644 index 0c261fc3016a4..0000000000000 --- a/packages/gatsby/src/utils/__tests__/sample-site-for-experiment.ts +++ /dev/null @@ -1,24 +0,0 @@ -import sampleSiteForExperiment from "../sample-site-for-experiment" - -import { - getRepositoryId, - IRepositoryId, -} from "gatsby-telemetry/lib/repository-id" -;(getRepositoryId as unknown as jest.Mock).mockReturnValue({ - repositoryId: `mockId`, -}) - -jest.mock(`gatsby-telemetry/lib/repository-id`) - -describe(`sampleSiteForExperiment`, () => { - it(`returns true or false depending on if they randomly are bucketed in or not`, () => { - const experiments = [`a`, `b`, `c`, `d`, `e`, `f`, `h`, `i`] - experiments.forEach(experiment => { - expect(sampleSiteForExperiment(experiment, 0)).toBeFalsy() - expect(sampleSiteForExperiment(experiment, 50)).toMatchSnapshot( - experiment - ) - expect(sampleSiteForExperiment(experiment, 100)).toBeTruthy() - }) - }) -}) diff --git a/packages/gatsby/src/utils/adapter/manager.ts b/packages/gatsby/src/utils/adapter/manager.ts index 2cf30e595cf7c..39ff97442adf1 100644 --- a/packages/gatsby/src/utils/adapter/manager.ts +++ b/packages/gatsby/src/utils/adapter/manager.ts @@ -5,7 +5,6 @@ import { slash } from "gatsby-core-utils/path" import { generatePageDataPath } from "gatsby-core-utils/page-data" import { posix } from "path" import { sync as globSync } from "glob" -import telemetry from "gatsby-telemetry" import { copy, pathExists, unlink } from "fs-extra" import pathToRegexp from "path-to-regexp" import type { @@ -137,8 +136,6 @@ export async function initAdapterManager(): Promise { // If we don't have adapter, use no-op adapter manager if (!adapterInit) { - telemetry.trackFeatureIsUsed(`adapter:no-op`) - const manager = noOpAdapterManager() await setAdapter({ manager }) @@ -150,7 +147,6 @@ export async function initAdapterManager(): Promise { } reporter.info(`Using ${adapter.name} adapter`) - telemetry.trackFeatureIsUsed(`adapter:${adapter.name}`) const directoriesToCache = [`.cache`, `public`] const manager: IAdapterManager = { diff --git a/packages/gatsby/src/utils/api-runner-node.js b/packages/gatsby/src/utils/api-runner-node.js index e3cca8d7f39ad..74c3b6fd699c6 100644 --- a/packages/gatsby/src/utils/api-runner-node.js +++ b/packages/gatsby/src/utils/api-runner-node.js @@ -30,7 +30,6 @@ const { getNodeAndSavePathDependency, loadNodeContent } = require(`./nodes`) const { getPublicPath } = require(`./get-public-path`) const { importGatsbyPlugin } = require(`./import-gatsby-plugin`) const { getNonGatsbyCodeFrameFormatted } = require(`./stack-trace-utils`) -const { trackBuildError, decorateEvent } = require(`gatsby-telemetry`) import errorParser from "./api-runner-error-parser" import { wrapNode, wrapNodes } from "./detect-node-mutations" import { reportOnce } from "./report-once" @@ -494,15 +493,7 @@ const runAPI = async (plugin, api, args, activity) => { callback(err, val) } - try { - gatsbyNode[api](...apiCallArgs, cb) - } catch (e) { - trackBuildError(api, { - error: e, - pluginName: `${plugin.name}@${plugin.version}`, - }) - throw e - } + gatsbyNode[api](...apiCallArgs, cb) }) } else { try { @@ -662,10 +653,6 @@ function apiRunnerNode(api, args = {}, { pluginSource, activity } = {}) { runAPI(plugin, api, { ...args, parentSpan: apiSpan }, activity) ) }).catch(err => { - decorateEvent(`BUILD_PANIC`, { - pluginName: `${plugin.name}@${plugin.version}`, - }) - const localReporter = getLocalReporter({ activity, reporter }) const file = stackTrace diff --git a/packages/gatsby/src/utils/engines-helpers.ts b/packages/gatsby/src/utils/engines-helpers.ts index ab7c254d18916..f84d69fd167c5 100644 --- a/packages/gatsby/src/utils/engines-helpers.ts +++ b/packages/gatsby/src/utils/engines-helpers.ts @@ -1,13 +1,11 @@ import { emitter, store } from "../redux" import { ICreatePageAction, ISetComponentFeatures } from "../redux/types" -import { trackFeatureIsUsed } from "gatsby-telemetry" export function shouldPrintEngineSnapshot(): boolean { return process.env.gatsby_executing_command === `build` } let generate = false -let shouldSendTelemetryForHeadAPI = true export function shouldGenerateEngines(): boolean { return process.env.gatsby_executing_command === `build` && generate } @@ -18,10 +16,6 @@ emitter.on(`CREATE_PAGE`, (action: ICreatePageAction) => { emitter.on(`SET_COMPONENT_FEATURES`, (action: ISetComponentFeatures) => { if (action.payload.serverData) generate = true if (action.payload.config) generate = true - if (action.payload.Head && shouldSendTelemetryForHeadAPI) { - trackFeatureIsUsed(`HeadAPI`) - shouldSendTelemetryForHeadAPI = false - } }) export function shouldBundleDatastore(): boolean { diff --git a/packages/gatsby/src/utils/feedback.ts b/packages/gatsby/src/utils/feedback.ts index 43b8aea3b7f70..80a471305ab6f 100644 --- a/packages/gatsby/src/utils/feedback.ts +++ b/packages/gatsby/src/utils/feedback.ts @@ -1,6 +1,5 @@ import report from "gatsby-cli/lib/reporter" import { getConfigStore, getGatsbyVersion, isCI } from "gatsby-core-utils" -import { trackCli } from "gatsby-telemetry" import getDayOfYear from "date-fns/getDayOfYear" const feedbackKey = `feedback.disabled` @@ -18,9 +17,6 @@ export function setFeedbackDisabledValue(enabled: boolean): void { // Print the feedback request to the user export function showFeedbackRequest(): void { getConfigStore().set(lastDateKey, Date.now()) - trackCli(`SHOW_FEEDBACK_LINK`, { - name: `https://gatsby.dev/feedback`, - }) report.log( `\n\nHello! Will you help Gatsby improve by taking a four question survey?\nIt takes less than five minutes and your ideas and feedback will be very helpful.` ) @@ -29,9 +25,6 @@ export function showFeedbackRequest(): void { export function showSevenDayFeedbackRequest(): void { getConfigStore().set(sevenDayKey, Date.now()) - trackCli(`SHOW_SEVEN_DAY_FEEDBACK_LINK`, { - name: `https://gatsby.dev/feedback-survey`, - }) report.log( `\n\nHi there! Will you tell us about how you're learning Gatsby? \nIt takes less than 5 minutes and your feedback will help us make installing and using Gatsby so much better.` ) diff --git a/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts b/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts index 6edde27b95f86..bcf759690e618 100644 --- a/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts +++ b/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts @@ -5,7 +5,6 @@ import type { Diagnostic } from "@parcel/diagnostic" import reporter from "gatsby-cli/lib/reporter" import { WorkerPool } from "gatsby-worker" import { ensureDir, emptyDir, existsSync, remove, readdir } from "fs-extra" -import telemetry from "gatsby-telemetry" import { isNearMatch } from "../is-near-match" export const COMPILED_CACHE_DIR = `.cache/compiled` @@ -233,13 +232,6 @@ export async function compileGatsbyFiles( } } } - - if (telemetry.isTrackingEnabled()) { - telemetry.trackCli(`PARCEL_COMPILATION_END`, { - valueInteger: compiledTSFilesCount, - name: `count of compiled ts files`, - }) - } } catch (error) { if (error.diagnostics) { handleErrors(error.diagnostics) diff --git a/packages/gatsby/src/utils/sample-site-for-experiment.ts b/packages/gatsby/src/utils/sample-site-for-experiment.ts deleted file mode 100644 index 4bd914b06c554..0000000000000 --- a/packages/gatsby/src/utils/sample-site-for-experiment.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { getRepositoryId } from "gatsby-telemetry/lib/repository-id" -import { murmurhash } from "gatsby-core-utils/murmurhash" - -const sampleSite = (experimentName: string, percentage: number): boolean => { - const bucketNumber = - murmurhash( - experimentName + `` + JSON.stringify(getRepositoryId().repositoryId), - 0 - ) % 100 - - return bucketNumber < percentage -} - -export default sampleSite diff --git a/packages/gatsby/src/utils/show-experiment-notice.ts b/packages/gatsby/src/utils/show-experiment-notice.ts index 8599737fd991c..65b6fe89ac64f 100644 --- a/packages/gatsby/src/utils/show-experiment-notice.ts +++ b/packages/gatsby/src/utils/show-experiment-notice.ts @@ -1,7 +1,6 @@ import { getConfigStore } from "gatsby-core-utils" import reporter from "gatsby-cli/lib/reporter" import chalk from "chalk" -import telemetry from "gatsby-telemetry" type CancelExperimentNoticeCallback = () => void @@ -66,7 +65,6 @@ ${chalk.bgBlue.bold(notice.experimentIdentifier)} (${notice.umbrellaLink}), ${ export const showExperimentNotices = (): void => { if (noticesToShow.length > 0) { - telemetry.trackCli(`InviteToTryExperiment`) // Store that we're showing the invite. noticesToShow.forEach(notice => getConfigStore().set( diff --git a/packages/gatsby/src/utils/start-server.ts b/packages/gatsby/src/utils/start-server.ts index 65ac90d0901de..71372741cb472 100644 --- a/packages/gatsby/src/utils/start-server.ts +++ b/packages/gatsby/src/utils/start-server.ts @@ -12,7 +12,6 @@ import { slash, uuid } from "gatsby-core-utils" import http from "http" import https from "https" import cors from "cors" -import telemetry from "gatsby-telemetry" import launchEditor from "react-dev-utils/launchEditor" import { codeFrameColumns } from "@babel/code-frame" import * as fs from "fs-extra" @@ -153,7 +152,6 @@ export async function startServer( * Set up the express app. **/ app.use(compression()) - app.use(telemetry.expressMiddleware(`DEVELOP`)) app.use( webpackHotMiddleware(compiler, { log: false, @@ -313,14 +311,7 @@ export async function startServer( let pageData: IPageDataWithQueryResult // TODO move to query-engine if (process.env.GATSBY_QUERY_ON_DEMAND) { - const start = Date.now() - pageData = await getPageDataExperimental(page.path) - - telemetry.trackCli(`RUN_QUERY_ON_DEMAND`, { - name: `getPageData`, - duration: Date.now() - start, - }) } else { pageData = await readPageData( path.join(store.getState().program.directory, `public`), @@ -655,8 +646,6 @@ export async function startServer( // Render an HTML page and serve it. if (process.env.GATSBY_EXPERIMENTAL_DEV_SSR) { app.get(`*`, async (req, res, next) => { - telemetry.trackFeatureIsUsed(`GATSBY_EXPERIMENTAL_DEV_SSR`) - const pathObj = findPageByPath(store.getState(), decodeURI(req.path)) if (!pathObj) { diff --git a/packages/gatsby/src/utils/websocket-manager.ts b/packages/gatsby/src/utils/websocket-manager.ts index 81da82b5a21eb..6681d5758fcce 100644 --- a/packages/gatsby/src/utils/websocket-manager.ts +++ b/packages/gatsby/src/utils/websocket-manager.ts @@ -6,9 +6,7 @@ import { clearDirtyQueriesListToEmitViaWebsocket } from "../redux/actions/intern import { Server as HTTPSServer } from "https" import { Server as HTTPServer } from "http" import { IPageDataWithQueryResult } from "../utils/page-data" -import telemetry from "gatsby-telemetry" import url from "url" -import { createHash } from "crypto" import { findPageByPath } from "./find-page-by-path" import { Server as SocketIO, Socket } from "socket.io" import { getPageMode } from "./page-mode" @@ -25,10 +23,6 @@ export interface IStaticQueryResult { type QueryResultsMap = Map -function hashPaths(paths: Array): Array { - return paths.map(path => createHash(`sha256`).update(path).digest(`hex`)) -} - interface IClientInfo { activePath: string | null socket: Socket @@ -166,38 +160,12 @@ export class WebsocketManager { if (this.websocket) { this.websocket.send({ type: `staticQueryResult`, payload: data }) - - if (this.clients.size > 0) { - telemetry.trackCli( - `WEBSOCKET_EMIT_STATIC_PAGE_DATA_UPDATE`, - { - siteMeasurements: { - clientsCount: this.clients.size, - paths: hashPaths(Array.from(this.activePaths)), - }, - }, - { debounce: true } - ) - } } } emitPageData = (data: IPageOrSliceQueryResult): void => { if (this.websocket) { this.websocket.send({ type: `pageQueryResult`, payload: data }) - - if (this.clients.size > 0) { - telemetry.trackCli( - `WEBSOCKET_EMIT_PAGE_DATA_UPDATE`, - { - siteMeasurements: { - clientsCount: this.clients.size, - paths: hashPaths(Array.from(this.activePaths)), - }, - }, - { debounce: true } - ) - } } } diff --git a/packages/gatsby/src/utils/worker/__tests__/config.ts b/packages/gatsby/src/utils/worker/__tests__/config.ts index df8bcfa3078fb..c8444d1ff8cc5 100644 --- a/packages/gatsby/src/utils/worker/__tests__/config.ts +++ b/packages/gatsby/src/utils/worker/__tests__/config.ts @@ -5,15 +5,6 @@ import { compileGatsbyFiles } from "../../parcel/compile-gatsby-files" let worker: GatsbyTestWorkerPool | undefined -jest.mock(`gatsby-telemetry`, () => { - return { - decorateEvent: jest.fn(), - trackCli: jest.fn(), - isTrackingEnabled: jest.fn(), - trackError: jest.fn(), - } -}) - beforeEach(() => { store.dispatch({ type: `DELETE_CACHE` }) }) diff --git a/packages/gatsby/src/utils/worker/__tests__/datastore.ts b/packages/gatsby/src/utils/worker/__tests__/datastore.ts index 5b915cafeb7d0..5680632d6c379 100644 --- a/packages/gatsby/src/utils/worker/__tests__/datastore.ts +++ b/packages/gatsby/src/utils/worker/__tests__/datastore.ts @@ -5,15 +5,6 @@ import { getDataStore } from "../../../datastore" jest.setTimeout(15000) -jest.mock(`gatsby-telemetry`, () => { - return { - decorateEvent: jest.fn(), - trackError: jest.fn(), - trackCli: jest.fn(), - isTrackingEnabled: jest.fn(), - } -}) - jest.mock(`gatsby-cli/lib/reporter`, () => { return {} }) diff --git a/packages/gatsby/src/utils/worker/__tests__/jobs.ts b/packages/gatsby/src/utils/worker/__tests__/jobs.ts index 4bb20e06f41bb..55ca9be133425 100644 --- a/packages/gatsby/src/utils/worker/__tests__/jobs.ts +++ b/packages/gatsby/src/utils/worker/__tests__/jobs.ts @@ -7,15 +7,6 @@ import type { MessagesFromChild, MessagesFromParent } from "../messaging" import { getReduxJobs, getJobsMeta } from "./test-helpers/child-for-tests" import { compileGatsbyFiles } from "../../parcel/compile-gatsby-files" -jest.mock(`gatsby-telemetry`, () => { - return { - decorateEvent: jest.fn(), - trackCli: jest.fn(), - isTrackingEnabled: jest.fn(), - trackError: jest.fn(), - } -}) - // jest.mock(`gatsby-cli/lib/reporter`, () => jest.fn()) let worker: GatsbyTestWorkerPool | undefined diff --git a/packages/gatsby/src/utils/worker/__tests__/queries.ts b/packages/gatsby/src/utils/worker/__tests__/queries.ts index 12b9668d6580d..73d30de13ff67 100644 --- a/packages/gatsby/src/utils/worker/__tests__/queries.ts +++ b/packages/gatsby/src/utils/worker/__tests__/queries.ts @@ -42,15 +42,6 @@ jest.mock(`chokidar`, () => { return chokidar }) -jest.mock(`gatsby-telemetry`, () => { - return { - decorateEvent: jest.fn(), - trackError: jest.fn(), - trackCli: jest.fn(), - isTrackingEnabled: jest.fn(), - } -}) - const dummyKeys = `a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z`.split( `,` ) diff --git a/packages/gatsby/src/utils/worker/__tests__/schema.ts b/packages/gatsby/src/utils/worker/__tests__/schema.ts index a75a7c32ce9b2..661c839a5c610 100644 --- a/packages/gatsby/src/utils/worker/__tests__/schema.ts +++ b/packages/gatsby/src/utils/worker/__tests__/schema.ts @@ -35,15 +35,6 @@ jest.mock(`chokidar`, () => { return chokidar }) -jest.mock(`gatsby-telemetry`, () => { - return { - decorateEvent: jest.fn(), - trackError: jest.fn(), - trackCli: jest.fn(), - isTrackingEnabled: jest.fn(), - } -}) - describe(`worker (schema)`, () => { let stateFromWorker: CombinedState diff --git a/packages/gatsby/src/utils/worker/__tests__/share-state.ts b/packages/gatsby/src/utils/worker/__tests__/share-state.ts index 37e6742e4d214..f2b5584050637 100644 --- a/packages/gatsby/src/utils/worker/__tests__/share-state.ts +++ b/packages/gatsby/src/utils/worker/__tests__/share-state.ts @@ -7,15 +7,6 @@ import { } from "../../../redux" import { GatsbyStateKeys } from "../../../redux/types" -jest.mock(`gatsby-telemetry`, () => { - return { - decorateEvent: jest.fn(), - trackError: jest.fn(), - trackCli: jest.fn(), - isTrackingEnabled: jest.fn(), - } -}) - let worker: GatsbyTestWorkerPool | undefined const dummyPagePayload = { diff --git a/yarn.lock b/yarn.lock index 8acc2a3c20ac9..6e64fb3a2a9f3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4417,18 +4417,6 @@ resolved "https://registry.yarnpkg.com/@trysound/sax/-/sax-0.2.0.tgz#cccaab758af56761eb7bf37af6f03f326dd798ad" integrity sha512-L7z9BgrNEcYyUYtF+HaEfiS5ebkh9jXqbszz7pC0hRBPaatV0XjSD3+eHrpqFemQfgwiFF0QPIarnIihIDn7OA== -"@turist/fetch@^7.2.0": - version "7.2.0" - resolved "https://registry.yarnpkg.com/@turist/fetch/-/fetch-7.2.0.tgz#57df869df1cd9b299588554eec4b8543effcc714" - integrity sha512-2x7EGw+6OJ29phunsbGvtxlNmSfcuPcyYudkMbi8gARCP9eJ1CtuMvnVUHL//O9Ixi9SJiug8wNt6lj86pN8XQ== - dependencies: - "@types/node-fetch" "2" - -"@turist/time@^0.0.2": - version "0.0.2" - resolved "https://registry.yarnpkg.com/@turist/time/-/time-0.0.2.tgz#32fe0ce708ea0f4512776bd313409f1459976dda" - integrity sha512-qLOvfmlG2vCVw5fo/oz8WAZYlpe5a5OurgTj3diIxJCdjRHpapC+vQCz3er9LV79Vcat+DifBjeAhOAdmndtDQ== - "@types/acorn@^4.0.0": version "4.0.6" resolved "https://registry.yarnpkg.com/@types/acorn/-/acorn-4.0.6.tgz#d61ca5480300ac41a7d973dd5b84d0a591154a22" @@ -4918,7 +4906,7 @@ resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.31.tgz#31b7ca6407128a3d2bbc27fe2d21b345397f6197" integrity sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA== -"@types/node-fetch@2", "@types/node-fetch@^2.6.4": +"@types/node-fetch@^2.6.4": version "2.6.4" resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.4.tgz#1bc3a26de814f6bf466b25aeb1473fa1afe6a660" integrity sha512-1ZX9fcN4Rvkvgv4E6PAY5WXUFWFcRWxZa3EW83UjycOB9ljJCedb2CupIP4RZMEwF/M3eTcCihbBRgwtGbg5Rg== @@ -14155,7 +14143,7 @@ is-directory@^0.3.1: version "0.3.1" resolved "https://registry.yarnpkg.com/is-directory/-/is-directory-0.3.1.tgz#61339b6f2475fc772fd9c9d83f5c8575dc154ae1" -is-docker@^2.0.0, is-docker@^2.1.1, is-docker@^2.2.1: +is-docker@^2.0.0, is-docker@^2.1.1: version "2.2.1" resolved "https://registry.yarnpkg.com/is-docker/-/is-docker-2.2.1.tgz#33eeabe23cfe86f14bde4408a02c0cfb853acdaa" integrity sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==