|
3 | 3 | <html> |
4 | 4 | <head> |
5 | 5 | <script> |
6 | | - async function gitpodMetricsAddCounter(metricsName, labels, value) { |
7 | | - function getMetricsUrl() { |
8 | | - const baseWorkspaceIDRegex = '(([a-f][0-9a-f]{7}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})|([0-9a-z]{2,16}-[0-9a-z]{2,16}-[0-9a-z]{8,11}))'; |
9 | | - // this pattern matches URL prefixes of workspaces |
10 | | - const workspaceUrlPrefixRegex = RegExp(`^([0-9]{4,6}-)?${baseWorkspaceIDRegex}\\.`); |
11 | | - const url = new URL(window.location.href); |
12 | | - url.search = ''; |
13 | | - url.hash = ''; |
14 | | - url.pathname = ''; |
15 | | - if (url.host.match(workspaceUrlPrefixRegex)) { |
16 | | - url.host = url.host.split('.').splice(2).join('.'); |
17 | | - } else { |
18 | | - return; |
19 | | - } |
20 | | - const hostSegments = url.host.split('.'); |
21 | | - if (hostSegments[0] !== 'ide') { |
22 | | - url.host = 'ide.' + url.host; |
23 | | - } |
24 | | - url.pathname = '/metrics-api'; |
25 | | - return url.toString(); |
| 6 | + let workspaceId = null; |
| 7 | + let ideMetricsUrl = null; |
| 8 | + (() => { |
| 9 | + const baseWorkspaceIDRegex = '(([a-f][0-9a-f]{7}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})|([0-9a-z]{2,16}-[0-9a-z]{2,16}-[0-9a-z]{8,11}))'; |
| 10 | + // this pattern matches URL prefixes of workspaces |
| 11 | + const workspaceUrlPrefixRegex = RegExp(`^([0-9]{4,6}-)?${baseWorkspaceIDRegex}\\.`); |
| 12 | + const url = new URL(window.location.href); |
| 13 | + url.search = ''; |
| 14 | + url.hash = ''; |
| 15 | + url.pathname = ''; |
| 16 | + const result = url.host.match(workspaceUrlPrefixRegex); |
| 17 | + if (result) { |
| 18 | + workspaceId = result[4] |
| 19 | + url.host = url.host.split('.').splice(2).join('.'); |
| 20 | + } else { |
| 21 | + return; |
| 22 | + } |
| 23 | + const hostSegments = url.host.split('.'); |
| 24 | + if (hostSegments[0] !== 'ide') { |
| 25 | + url.host = 'ide.' + url.host; |
26 | 26 | } |
| 27 | + url.pathname = '/metrics-api'; |
| 28 | + ideMetricsUrl = url.toString() |
| 29 | + })(); |
| 30 | + |
| 31 | + async function gitpodMetricsAddCounter(metricsName, labels, value) { |
27 | 32 | try { |
28 | | - const metricsUrl = getMetricsUrl(); |
29 | | - if (!metricsUrl) { |
| 33 | + if (!ideMetricsUrl) { |
30 | 34 | return false; |
31 | 35 | } |
32 | | - const url = `${metricsUrl}/metrics/counter/add/${metricsName}`; |
| 36 | + const url = `${ideMetricsUrl}/metrics/counter/add/${metricsName}`; |
33 | 37 | const params = { value, labels }; |
34 | 38 | const response = await fetch(url, { |
35 | 39 | method: 'POST', |
|
48 | 52 | } |
49 | 53 | } |
50 | 54 |
|
| 55 | + async function gitpodMetricsReportError(error, properties) { |
| 56 | + try { |
| 57 | + if (!ideMetricsUrl) { |
| 58 | + return false; |
| 59 | + } |
| 60 | + const p = Object.assign({}, properties) |
| 61 | + p.error_name = error.name |
| 62 | + p.error_message = error.message |
| 63 | + const url = `${ideMetricsUrl}/reportError`; |
| 64 | + // TODO: Add quality as a params |
| 65 | + const params = { |
| 66 | + errorStack: error.stack ?? String(error), |
| 67 | + component: "vscode-workbench", |
| 68 | + version: "{{VERSION}}", |
| 69 | + workspaceId: workspaceId, |
| 70 | + properties: p, |
| 71 | + }; |
| 72 | + const response = await fetch(url, { |
| 73 | + method: 'POST', |
| 74 | + body: JSON.stringify(params), |
| 75 | + credentials: 'omit', |
| 76 | + }); |
| 77 | + if (!response.ok) { |
| 78 | + const data = await response.json(); |
| 79 | + console.error(`Cannot report error: ${response.status} ${response.statusText}`, data); |
| 80 | + return false; |
| 81 | + } |
| 82 | + return true; |
| 83 | + } catch (err) { |
| 84 | + console.error("Cannot report error, error:", err); |
| 85 | + return false; |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + // sum(rate(gitpod_vscode_web_load_total{status='failed'}[2m]))/sum(rate(gitpod_vscode_web_load_total{status='loading'}[2m])) |
| 90 | + const gitpodVSCodeWebLoadTotal = 'gitpod_vscode_web_load_total'; |
| 91 | + gitpodMetricsAddCounter(gitpodVSCodeWebLoadTotal, { status: 'loading' }); |
| 92 | + let hasVscodeWebLoadFailed = false; |
51 | 93 | const onVsCodeWorkbenchError = (event) => { |
| 94 | + if (!hasVscodeWebLoadFailed) { |
| 95 | + gitpodMetricsAddCounter(gitpodVSCodeWebLoadTotal, { status: 'failed' }); |
| 96 | + hasVscodeWebLoadFailed = true; |
| 97 | + } |
| 98 | + |
52 | 99 | if (typeof event?.target?.getAttribute !== 'function') { |
53 | 100 | gitpodMetricsAddCounter('gitpod_supervisor_frontend_error_total'); |
54 | 101 | return; |
|
62 | 109 | if (resourceSource) { |
63 | 110 | labels['resource'] = 'vscode-web-workbench'; |
64 | 111 | labels['error'] = 'LoadError'; |
| 112 | + gitpodMetricsReportError(new Error("LoadError"), { resource: labels['resource'], url: resourceSource }) |
65 | 113 | } else { |
66 | 114 | labels['error'] = 'Unknown'; |
67 | 115 | } |
68 | 116 | gitpodMetricsAddCounter('gitpod_supervisor_frontend_error_total', labels); |
69 | | - }; |
70 | 117 |
|
| 118 | + // TODO collect errors, we can capture resourceSource, error if possible with stack, message, name, and window URL |
| 119 | + }; |
| 120 | + </script> |
| 121 | + <script> |
71 | 122 | performance.mark('code/didStartRenderer'); |
72 | 123 | </script> |
73 | 124 | <meta charset="utf-8" /> |
|
101 | 152 | </body> |
102 | 153 |
|
103 | 154 | <!-- Startup (do not modify order of script tags!) --> |
104 | | - <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> |
| 155 | + <script type="text/javascript" src="/_supervisor/frontend/main.js" onerror="onVsCodeWorkbenchError(event)" charset="utf-8" crossorigin="anonymous"></script> |
| 156 | + <script src="./static/out/vs/loader.js" onerror="onVsCodeWorkbenchError(event)" crossorigin="anonymous"></script> |
| 157 | + <script src="./static/out/vs/webPackagePaths.js" onerror="onVsCodeWorkbenchError(event)" crossorigin="anonymous"></script> |
107 | 158 | <script> |
108 | 159 | Object.keys(self.webPackagePaths).map(function (key, index) { |
109 | 160 | self.webPackagePaths[key] = `${window.location.origin}/static/node_modules/${key}/${self.webPackagePaths[key]}`; |
|
127 | 178 | <script> |
128 | 179 | performance.mark('code/willLoadWorkbenchMain'); |
129 | 180 | </script> |
130 | | - <script src="./static/out/vs/workbench/workbench.web.main.nls.js" onerror="onVsCodeWorkbenchError(event)"></script> |
131 | | - <script src="./static/out/vs/workbench/workbench.web.main.js" onerror="onVsCodeWorkbenchError(event)"></script> |
132 | | - <script src="./static/out/vs/gitpod/browser/workbench/workbench.js" onerror="onVsCodeWorkbenchError(event)"></script> |
| 181 | + <script src="./static/out/vs/workbench/workbench.web.main.nls.js" onerror="onVsCodeWorkbenchError(event)" crossorigin="anonymous"></script> |
| 182 | + <script src="./static/out/vs/workbench/workbench.web.main.js" onerror="onVsCodeWorkbenchError(event)" crossorigin="anonymous"></script> |
| 183 | + <script src="./static/out/vs/gitpod/browser/workbench/workbench.js" onerror="onVsCodeWorkbenchError(event)" crossorigin="anonymous"></script> |
133 | 184 | </html> |
0 commit comments