|  | 
| 2 | 2 | <!DOCTYPE html> | 
| 3 | 3 | <html> | 
| 4 | 4 | 	<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> | 
| 5 | 67 | 		<script> | 
| 6 | 68 | 			performance.mark('code/didStartRenderer') | 
| 7 | 69 | 		</script> | 
|  | 
| 34 | 96 | 	</body> | 
| 35 | 97 | 
 | 
| 36 | 98 | 	<!-- 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> | 
| 39 | 101 | 	<script> | 
| 40 | 102 | 		const baseUrl = new URL('{{WORKBENCH_WEB_BASE_URL}}', window.location.origin).toString(); | 
| 41 | 103 | 		Object.keys(self.webPackagePaths).map(function (key, index) { | 
|  | 
| 65 | 127 | 		performance.mark('code/willLoadWorkbenchMain'); | 
| 66 | 128 | 	</script> | 
| 67 | 129 | 	<script> | 
| 68 |  | -		require(['vs/gitpod/browser/workbench/workbench'], function() {}); | 
|  | 130 | +		require(['vs/gitpod/browser/workbench/workbench'], () => {}); | 
| 69 | 131 | 	</script> | 
| 70 | 132 | </html> | 
0 commit comments