-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* ✨[RUM-3151] Report bundle sizes to logs * added ddsource in request and PostBundleSize is now async * fix lint error * added branch new method * Changed name intake, source version file and commit retrieve process * added browser-sdk-version function / added error.cause to run main function * added function printErrorWithCause * deleted getter and added a simple return of lerna version. Changed fetch wrapper into fetch in export bundle script. Deleted local preferences in gitignore * build env getbrowserversion * changed export name BrowserSdkVersion * changed browserSdkVersion export name
- Loading branch information
1 parent
f6d3465
commit 84cd328
Showing
7 changed files
with
76 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const { browserSdkVersion } = require('./lib/browser-sdk-version') | ||
const { getOrg2ApiKey } = require('./lib/secrets') | ||
const { runMain, fetch } = require('./lib/execution-utils') | ||
|
||
const rumPath = path.join(__dirname, '../packages/rum/bundle/datadog-rum.js') | ||
const logsPath = path.join(__dirname, '../packages/logs/bundle/datadog-logs.js') | ||
const rumSlimPath = path.join(__dirname, '../packages/rum-slim/bundle/datadog-rum-slim.js') | ||
const workerPath = path.join(__dirname, '../packages/worker/bundle/worker.js') | ||
|
||
const LOG_INTAKE_URL = 'https://http-intake.logs.datadoghq.com/api/v2/logs' | ||
const LOG_INTAKE_REQUEST_HEADERS = { | ||
'DD-API-KEY': getOrg2ApiKey(), | ||
'Content-Type': 'application/json', | ||
} | ||
|
||
runMain(async () => { | ||
const logData = [ | ||
{ | ||
message: 'Browser SDK bundles sizes', | ||
service: 'browser-sdk', | ||
ddsource: 'browser-sdk', | ||
env: 'ci', | ||
bundle_sizes: { | ||
rum: getBundleSize(rumPath), | ||
logs: getBundleSize(logsPath), | ||
rum_slim: getBundleSize(rumSlimPath), | ||
worker: getBundleSize(workerPath), | ||
}, | ||
version: browserSdkVersion, | ||
commit: process.env.CI_COMMIT_SHORT_SHA, | ||
branch: process.env.CI_COMMIT_REF_NAME, | ||
}, | ||
] | ||
await sendLogToOrg2(logData) | ||
}) | ||
|
||
function getBundleSize(pathBundle) { | ||
try { | ||
const file = fs.statSync(pathBundle) | ||
return file.size | ||
} catch (error) { | ||
throw new Error('Failed to get bundle size', { cause: error }) | ||
} | ||
} | ||
|
||
async function sendLogToOrg2(bundleData = {}) { | ||
await fetch(LOG_INTAKE_URL, { | ||
method: 'POST', | ||
headers: LOG_INTAKE_REQUEST_HEADERS, | ||
body: JSON.stringify(bundleData), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const lernaJson = require('../../lerna.json') | ||
|
||
module.exports = { | ||
browserSdkVersion: lernaJson.version, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters