|
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(); |
| 26 | + } |
| 27 | + try { |
| 28 | + const metricsUrl = getMetricsUrl(); |
| 29 | + if (!metricsUrl) { |
| 30 | + return false; |
| 31 | + } |
| 32 | + const url = `${metricsUrl}/metrics/counter/add/${metricsName}`; |
| 33 | + const params = { value, labels }; |
| 34 | + const response = await fetch(url, { |
| 35 | + method: 'POST', |
| 36 | + body: JSON.stringify(params), |
| 37 | + credentials: 'omit', |
| 38 | + }); |
| 39 | + if (!response.ok) { |
| 40 | + const data = await response.json(); // { code: number; message: string; } |
| 41 | + console.error(`Cannot report metrics with addCounter: ${response.status} ${response.statusText}`, data); |
| 42 | + return false; |
| 43 | + } |
| 44 | + return true; |
| 45 | + } catch (err) { |
| 46 | + console.error('Cannot report metrics with addCounter, error:', err); |
| 47 | + return false; |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + const onVsCodeWorkbenchError = (event) => { |
| 52 | + if (typeof event?.target?.getAttribute !== 'function') { |
| 53 | + gitpodMetricsAddCounter('gitpod_supervisor_frontend_error_total'); |
| 54 | + return; |
| 55 | + } |
| 56 | + const labels = {}; |
| 57 | + |
| 58 | + // We take a look at what is the resource that was attempted to load; |
| 59 | + const resourceSource = event.target.getAttribute('src') || event.target.getAttribute('href'); |
| 60 | + |
| 61 | + // If the event has a `target`, it means that it wasn't a script error |
| 62 | + if (resourceSource) { |
| 63 | + labels['resource'] = 'vscode-web-workbench'; |
| 64 | + labels['error'] = 'LoadError'; |
| 65 | + } else { |
| 66 | + labels['error'] = 'Unknown'; |
| 67 | + } |
| 68 | + gitpodMetricsAddCounter('gitpod_supervisor_frontend_error_total', labels); |
| 69 | + }; |
| 70 | + |
6 | 71 | performance.mark('code/didStartRenderer');
|
7 | 72 | </script>
|
8 | 73 | <meta charset="utf-8" />
|
|
28 | 93 | <!-- Workbench Icon/Manifest/CSS -->
|
29 | 94 | <link rel="icon" href="/favicon.ico" type="image/x-icon" />
|
30 | 95 | <link rel="manifest" href="/manifest.json" />
|
31 |
| - <link data-name="vs/workbench/workbench.web.main" rel="stylesheet" href="./static/out/vs/workbench/workbench.web.main.css"> |
| 96 | + <link data-name="vs/workbench/workbench.web.main" rel="stylesheet" href="./static/out/vs/workbench/workbench.web.main.css" onerror="onVsCodeWorkbenchError(event)"> |
32 | 97 |
|
33 | 98 | </head>
|
34 | 99 |
|
35 | 100 | <body aria-label="">
|
36 | 101 | </body>
|
37 | 102 |
|
38 | 103 | <!-- Startup (do not modify order of script tags!) -->
|
39 |
| - <script type="text/javascript" src="/_supervisor/frontend/main.js" charset="utf-8"></script> |
40 |
| - <script src="./static/out/vs/loader.js"></script> |
41 |
| - <script src="./static/out/vs/webPackagePaths.js"></script> |
| 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> |
42 | 107 | <script>
|
43 | 108 | Object.keys(self.webPackagePaths).map(function (key, index) {
|
44 | 109 | self.webPackagePaths[key] = `${window.location.origin}/static/node_modules/${key}/${self.webPackagePaths[key]}`;
|
|
62 | 127 | <script>
|
63 | 128 | performance.mark('code/willLoadWorkbenchMain');
|
64 | 129 | </script>
|
65 |
| - <script src="./static/out/vs/workbench/workbench.web.main.nls.js"></script> |
66 |
| - <script src="./static/out/vs/workbench/workbench.web.main.js"></script> |
67 |
| - <script src="./static/out/vs/gitpod/browser/workbench/workbench.js"></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> |
68 | 133 | </html>
|
0 commit comments