Skip to content

Commit 815cfe0

Browse files
committed
track loading and failed windows
1 parent 8a04b4e commit 815cfe0

File tree

5 files changed

+87
-7
lines changed

5 files changed

+87
-7
lines changed

product.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,5 +695,8 @@
695695
},
696696
"linkProtectionTrustedDomains": [
697697
"https://open-vsx.org"
698-
]
698+
],
699+
"gitpodPreview": {
700+
"host": "filiptroni52200c8eb9.preview.gitpod-dev.com"
701+
}
699702
}

src/vs/gitpod/browser/workbench/workbench-dev.html

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,68 @@
22
<!DOCTYPE html>
33
<html>
44
<head>
5+
<script>
6+
async function gitpodMetricsAddCounter(metricsName, labels, value) {
7+
function getMetricsUrl() {
8+
const gitpodHost = "{{GITPOD_HOST}}";
9+
if (!gitpodHost) {
10+
return '';
11+
}
12+
return `https://ide.${gitpodHost}/metrics-api`;
13+
}
14+
try {
15+
const metricsUrl = getMetricsUrl();
16+
if (!metricsUrl) {
17+
return false;
18+
}
19+
const url = `${metricsUrl}/metrics/counter/add/${metricsName}`;
20+
const params = { value, labels };
21+
const response = await fetch(url, {
22+
method: 'POST',
23+
body: JSON.stringify(params),
24+
credentials: 'omit',
25+
});
26+
if (!response.ok) {
27+
const data = await response.json(); // { code: number; message: string; }
28+
console.error(`Cannot report metrics with addCounter: ${response.status} ${response.statusText}`, data);
29+
return false;
30+
}
31+
return true;
32+
} catch (err) {
33+
console.error('Cannot report metrics with addCounter, error:', err);
34+
return false;
35+
}
36+
}
37+
38+
// sum(rate(gitpod_vscode_web_load_total{status='failed'}[2m]))/sum(rate(gitpod_vscode_web_load_total{status='loading'}[2m]))
39+
const gitpodVSCodeWebLoadTotal = 'gitpod_vscode_web_load_total';
40+
gitpodMetricsAddCounter(gitpodVSCodeWebLoadTotal, { status: 'loading' });
41+
let vscodeWebFailedToLoad = false;
42+
const onVsCodeWorkbenchError = (event) => {
43+
if (!vscodeWebFailedToLoad) {
44+
vscodeWebFailedToLoad = true;
45+
gitpodMetricsAddCounter(gitpodVSCodeWebLoadTotal, { status: 'failed' });
46+
}
47+
48+
if (typeof event?.target?.getAttribute !== 'function') {
49+
gitpodMetricsAddCounter('gitpod_supervisor_frontend_error_total');
50+
return;
51+
}
52+
const labels = {};
53+
54+
// We take a look at what is the resource that was attempted to load;
55+
const resourceSource = event.target.getAttribute('src') || event.target.getAttribute('href');
56+
57+
// If the event has a `target`, it means that it wasn't a script error
58+
if (resourceSource) {
59+
labels['resource'] = 'vscode-web-workbench';
60+
labels['error'] = 'LoadError';
61+
} else {
62+
labels['error'] = 'Unknown';
63+
}
64+
gitpodMetricsAddCounter('gitpod_supervisor_frontend_error_total', labels);
65+
};
66+
</script>
567
<script>
668
performance.mark('code/didStartRenderer')
769
</script>
@@ -34,8 +96,8 @@
3496
</body>
3597

3698
<!-- Startup (do not modify order of script tags!) -->
37-
<script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/loader.js"></script>
38-
<script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/webPackagePaths.js"></script>
99+
<script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/loader.js" onerror="onVsCodeWorkbenchError(event)"></script>
100+
<script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/webPackagePaths.js" onerror="onVsCodeWorkbenchError(event)"></script>
39101
<script>
40102
const baseUrl = new URL('{{WORKBENCH_WEB_BASE_URL}}', window.location.origin).toString();
41103
Object.keys(self.webPackagePaths).map(function (key, index) {
@@ -65,6 +127,6 @@
65127
performance.mark('code/willLoadWorkbenchMain');
66128
</script>
67129
<script>
68-
require(['vs/gitpod/browser/workbench/workbench'], function() {});
130+
require(['vs/gitpod/browser/workbench/workbench'], () => {});
69131
</script>
70132
</html>

src/vs/gitpod/browser/workbench/workbench.html

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,16 @@
4848
}
4949
}
5050

51+
// sum(rate(gitpod_vscode_web_load_total{status='failed'}[2m]))/sum(rate(gitpod_vscode_web_load_total{status='loading'}[2m]))
52+
const gitpodVSCodeWebLoadTotal = 'gitpod_vscode_web_load_total';
53+
gitpodMetricsAddCounter(gitpodVSCodeWebLoadTotal, { status: 'loading' });
54+
let vscodeWebFailedToLoad = false;
5155
const onVsCodeWorkbenchError = (event) => {
56+
if (!vscodeWebFailedToLoad) {
57+
vscodeWebFailedToLoad = true;
58+
gitpodMetricsAddCounter(gitpodVSCodeWebLoadTotal, { status: 'failed' });
59+
}
60+
5261
if (typeof event?.target?.getAttribute !== 'function') {
5362
gitpodMetricsAddCounter('gitpod_supervisor_frontend_error_total');
5463
return;
@@ -66,8 +75,11 @@
6675
labels['error'] = 'Unknown';
6776
}
6877
gitpodMetricsAddCounter('gitpod_supervisor_frontend_error_total', labels);
69-
};
7078

79+
// TODO collect errors, we can capture resourceSource, error if possible with stack, message, name, and window URL
80+
};
81+
</script>
82+
<script>
7183
performance.mark('code/didStartRenderer');
7284
</script>
7385
<meta charset="utf-8" />
@@ -102,8 +114,8 @@
102114

103115
<!-- Startup (do not modify order of script tags!) -->
104116
<script type="text/javascript" src="/_supervisor/frontend/main.js" onerror="onVsCodeWorkbenchError(event)" charset="utf-8"></script>
105-
<script src="./static/out/vs/loader.js" onerror="onVsCodeWorkbenchError(event)" ></script>
106-
<script src="./static/out/vs/webPackagePaths.js" onerror="onVsCodeWorkbenchError(event)" ></script>
117+
<script src="./static/out/vs/loader.js" onerror="onVsCodeWorkbenchError(event)"></script>
118+
<script src="./static/out/vs/webPackagePaths.js" onerror="onVsCodeWorkbenchError(event)"></script>
107119
<script>
108120
Object.keys(self.webPackagePaths).map(function (key, index) {
109121
self.webPackagePaths[key] = `${window.location.origin}/static/node_modules/${key}/${self.webPackagePaths[key]}`;

src/vs/gitpod/common/insightsHelper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export enum SenderKind {
2828
Node = 2
2929
}
3030

31+
// TODO map 'UnhandledError' to our error and report it both only for window and remote-server
32+
3133
export function mapMetrics(source: 'window' | 'remote-server', eventName: string, data: any): IDEMetric[] | undefined {
3234
const maybeMetrics = doMapMetrics(source, eventName, data);
3335
return maybeMetrics instanceof Array ? maybeMetrics : typeof maybeMetrics === 'object' ? [maybeMetrics] : undefined;

src/vs/server/node/webClientServer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ export class WebClientServer {
323323

324324
const nlsBaseUrl = this._productService.extensionsGallery?.nlsBaseUrl;
325325
const values: { [key: string]: string } = {
326+
GITPOD_HOST: this._productService.gitpodPreview?.host || '',
326327
WORKBENCH_WEB_CONFIGURATION: asJSON(workbenchWebConfiguration),
327328
WORKBENCH_AUTH_SESSION: authSessionInfo ? asJSON(authSessionInfo) : '',
328329
WORKBENCH_WEB_BASE_URL: this._staticRoute,

0 commit comments

Comments
 (0)