Skip to content

Commit

Permalink
🔊 Add SDK setup telemetry (#3045)
Browse files Browse the repository at this point in the history
  • Loading branch information
amortemousque authored Oct 1, 2024
1 parent 1a0f830 commit cd768fe
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/domain/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { StatusType, TelemetryType } from './rawTelemetryEvent.types'

// replaced at build time
declare const __BUILD_ENV__SDK_VERSION__: string
declare const __BUILD_ENV__SDK_SETUP__: string

const ALLOWED_FRAME_URLS = [
'https://www.datadoghq-browser-agent.com',
Expand Down Expand Up @@ -106,6 +107,7 @@ export function startTelemetry(telemetryService: TelemetryService, configuration
telemetry: combine(event, {
runtime_env: runtimeEnvInfo,
connectivity: getConnectivity(),
sdk_setup: __BUILD_ENV__SDK_SETUP__,
}),
experimental_features: arrayFrom(getExperimentalFeatures()),
},
Expand Down
2 changes: 1 addition & 1 deletion packages/logs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"types": "cjs/entries/main.d.ts",
"scripts": {
"build": "run-p build:cjs build:esm build:bundle",
"build:bundle": "rm -rf bundle && webpack --mode=production",
"build:bundle": "rm -rf bundle && SDK_SETUP=cdn webpack --mode=production",
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json && yarn replace-build-env cjs",
"build:esm": "rm -rf esm && tsc -p tsconfig.esm.json && yarn replace-build-env esm",
"replace-build-env": "node ../../scripts/build/replace-build-env.js"
Expand Down
2 changes: 1 addition & 1 deletion packages/rum-slim/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"types": "cjs/entries/main.d.ts",
"scripts": {
"build": "run-p build:cjs build:esm build:bundle",
"build:bundle": "rm -rf bundle && webpack --mode=production",
"build:bundle": "rm -rf bundle && SDK_SETUP=cdn webpack --mode=production",
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json",
"build:esm": "rm -rf esm && tsc -p tsconfig.esm.json"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/rum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"types": "cjs/entries/main.d.ts",
"scripts": {
"build": "run-p build:cjs build:esm build:bundle",
"build:bundle": "rm -rf bundle && webpack --mode=production",
"build:bundle": "rm -rf bundle && SDK_SETUP=cdn webpack --mode=production",
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json && yarn replace-build-env cjs",
"build:esm": "rm -rf esm && tsc -p tsconfig.esm.json && yarn replace-build-env esm",
"replace-build-env": "node ../../scripts/build/replace-build-env.js"
Expand Down
17 changes: 17 additions & 0 deletions scripts/lib/build-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ const BUILD_MODES = [
'canary',
]

/**
* Allows to define which sdk setup to send to the telemetry.
*/
const SDK_SETUPS = ['npm', 'cdn']

const buildEnvCache = new Map()

const buildEnvFactories = {
Expand All @@ -35,6 +40,7 @@ const buildEnvFactories = {
return 'dev'
}
},
SDK_SETUP: () => getSdkSetup(),
WORKER_STRING: () => {
const workerPath = path.join(__dirname, '../../packages/worker')
// Make sure the worker is built
Expand Down Expand Up @@ -70,3 +76,14 @@ function getBuildMode() {
console.log(`Invalid build mode "${process.env.BUILD_MODE}". Possible build modes are: ${BUILD_MODES.join(', ')}`)
process.exit(1)
}

function getSdkSetup() {
if (!process.env.SDK_SETUP) {
return SDK_SETUPS[0] // npm
}
if (SDK_SETUPS.includes(process.env.SDK_SETUP)) {
return process.env.SDK_SETUP
}
console.log(`Invalid SDK setup "${process.env.SDK_SETUP}". Possible SDK setups are: ${SDK_SETUPS.join(', ')}`)
process.exit(1)
}

0 comments on commit cd768fe

Please sign in to comment.