Skip to content

Commit ceb8f5c

Browse files
committed
feat: initial commit
Thanks to @vaind for their initial work on this at getsentry/sentry-javascript#6611. We wanted to extract this to a separate tool so it can be run outside of the `sentry-javascript` repo.
0 parents  commit ceb8f5c

27 files changed

+1910
-0
lines changed

.eslintrc.cjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
extends: ['../../.eslintrc.js'],
3+
ignorePatterns: ['test-apps'],
4+
overrides: [
5+
{
6+
files: ['*.ts'],
7+
rules: {
8+
'no-console': 'off',
9+
'@typescript-eslint/no-non-null-assertion': 'off',
10+
'import/no-unresolved': 'off',
11+
'@sentry-internal/sdk/no-optional-chaining': 'off',
12+
'@sentry-internal/sdk/no-nullish-coalescing': 'off',
13+
'@sentry-internal/sdk/no-unsupported-es6-methods': 'off',
14+
'jsdoc/require-jsdoc': 'off',
15+
},
16+
},
17+
],
18+
};

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
out
2+
node_modules
3+
build
4+
lib

.prettierrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"arrowParens": "avoid",
3+
"printWidth": 120,
4+
"proseWrap": "always",
5+
"singleQuote": true,
6+
"trailingComma": "all"
7+
}

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Overhead performance metrics
2+
3+
Evaluates Sentry & Replay impact on website performance by running a web app in Chromium via Playwright and collecting various metrics.
4+
5+
The general idea is to run a web app without Sentry, and then run the same app again with Sentry and another one with Sentry+Replay included.
6+
For the three scenarios, we collect some metrics (CPU, memory, vitals) and later compare them and post as a comment in a PR.
7+
Changes in the metrics, compared to previous runs from the main branch, should be evaluated on case-by-case basis when preparing and reviewing the PR.
8+
9+
10+
## Instructions
11+
12+
WIP
13+
14+
`npm install @server-internal/overhead`
15+
16+
`./sentry-overhead -f myScenario.js`
17+
18+
## Resources
19+
20+
* https://github.com/addyosmani/puppeteer-webperf
21+
* https://web.dev/

bin/cli.mjs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env node
2+
3+
import path from 'node:path';
4+
import { parseArgs } from "node:util";
5+
import * as url from 'node:url';
6+
7+
import {MetricsCollector, MetricsStats, printStats} from '../lib/index.js';
8+
9+
// From: https://exploringjs.com/nodejs-shell-scripting/ch_nodejs-path.html#detecting-if-module-is-main
10+
const modulePath = url.fileURLToPath(import.meta.url);
11+
if (import.meta.url.startsWith('file:')) { // (A)
12+
if (process.argv[1] === modulePath) { // (B)
13+
main();
14+
}
15+
}
16+
17+
18+
async function main() {
19+
const options = {
20+
'headless': {
21+
type: 'boolean',
22+
},
23+
'runs': {
24+
type: 'string',
25+
short: 'c'
26+
},
27+
'cpu': {
28+
type: 'string',
29+
},
30+
'network': {
31+
type: 'string',
32+
short: 'n',
33+
},
34+
'file': {
35+
type: 'string',
36+
short: 'f',
37+
multiple: true,
38+
},
39+
}
40+
41+
const {
42+
values: { headless, runs, cpu, network, file },
43+
} = parseArgs({options});
44+
45+
console.log({
46+
headless,
47+
runs,
48+
cpu,
49+
network,
50+
file
51+
})
52+
53+
if (!file || file.length < 1) {
54+
// need file!
55+
throw new Error('No scenario files given')
56+
}
57+
58+
59+
const modules = await Promise.all(file.map(async f => import(path.resolve('./', f))));
60+
const scenarios = modules.flatMap(m => Object.values(m))
61+
62+
const collector = new MetricsCollector();
63+
const result = await collector.execute({
64+
name: 'default',
65+
scenarios: scenarios.map(C => new C()),
66+
runs: runs ?? 1,
67+
tries: (runs ?? 1) * 5,
68+
async shouldAccept(results) {
69+
printStats(results);
70+
71+
const cpuUsage = MetricsStats.mean(results, MetricsStats.cpu);
72+
if (cpuUsage > 0.9) {
73+
console.error(
74+
`CPU usage too high to be accurate: ${(cpuUsage * 100).toFixed(2)} %.`,
75+
'Consider simplifying the scenario or changing the CPU throttling factor.',
76+
);
77+
return false;
78+
}
79+
return true;
80+
},
81+
});
82+
83+
result.writeToFile('out/latest-result.json');
84+
85+
// const resultsSet = new ResultsSet(outDir);
86+
// const latestResult = Result.readFromFile(latestResultFile);
87+
//
88+
// const analysis = await ResultsAnalyzer.analyze(latestResult, resultsSet);
89+
// printAnalysis(analysis, latestResult);
90+
}
91+

package.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"private": true,
3+
"version": "7.54.0",
4+
"name": "@sentry-internal/overhead",
5+
"main": "lib/index.js",
6+
"bin": {
7+
"sentry-overhead": "./bin/cli.mjs"
8+
},
9+
"author": "Sentry",
10+
"license": "MIT",
11+
"type": "module",
12+
"scripts": {
13+
"build": "tsc",
14+
"dev:collect": "ts-node-esm ./configs/dev/collect.ts",
15+
"dev:process": "ts-node-esm ./configs/dev/process.ts",
16+
"dev:run:replay": "npx chrome ./test-apps/booking-app/with-replay.html",
17+
"ci:collect": "ts-node-esm ./configs/ci/collect.ts",
18+
"ci:process": "ts-node-esm ./configs/ci/process.ts",
19+
"fix": "run-s fix:eslint fix:prettier",
20+
"fix:eslint": "eslint . --format stylish --fix",
21+
"fix:prettier": "prettier --write \"{src,test-apps,configs}/**/*.{ts,js,html,css}\"",
22+
"lint": "run-s lint:prettier lint:eslint",
23+
"lint:eslint": "eslint . --format stylish",
24+
"lint:prettier": "prettier --check \"{src,test-apps,configs}/**/*.{ts,js,html,css}\""
25+
},
26+
"dependencies": {
27+
"@types/node": "^18.11.17",
28+
"axios": "^1.2.2",
29+
"filesize": "^10.0.6",
30+
"fs-extra": "^11.1.0",
31+
"p-timeout": "^6.0.0",
32+
"playwright": "^1.35.1",
33+
"playwright-core": "^1.35.1",
34+
"simple-git": "^3.16.0",
35+
"simple-statistics": "^7.8.0",
36+
"typescript": "^4.9.4"
37+
},
38+
"devDependencies": {
39+
"prettier": "^2.8.8",
40+
"ts-node": "^10.9.1"
41+
},
42+
"volta": {
43+
"node": "18.16.0"
44+
}
45+
}

0 commit comments

Comments
 (0)