Skip to content

Commit

Permalink
[metrics] surface user agent and original error timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
akosyakov committed Sep 26, 2023
1 parent d4e5e0a commit 3c77b9d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion components/public-api/typescript/src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ export class MetricsReporter {
},
) {
this.metricsHost = `ide.${new URL(options.gitpodUrl).hostname}`;
if (typeof window !== "undefined") {
this.options.commonErrorDetails["userAgent"] = window.navigator.userAgent
}
}

updateCommonErrorDetails(update: { [key: string]: string | undefined }) {
Expand Down Expand Up @@ -305,6 +308,9 @@ export class MetricsReporter {
if (!enabled) {
return;
}
if (typeof window !== undefined && !window.navigator.onLine) {
return;
}

const metrics = await register.getMetricsAsJSON();
register.resetMetrics();
Expand Down Expand Up @@ -404,9 +410,14 @@ export class MetricsReporter {
return;
}
const properties = { ...data, ...this.options.commonErrorDetails };
properties["error_timestamp"] = new Date().toISOString();
properties["error_name"] = error.name;
properties["error_message"] = error.message;

if (typeof window !== undefined) {
properties["onLine"] = String(window.navigator.onLine);
}

const workspaceId = properties["workspaceId"];
const instanceId = properties["instanceId"];
const userId = properties["userId"];
Expand Down Expand Up @@ -456,7 +467,11 @@ export class MetricsReporter {

private async send(request: MetricsRequest | undefined): Promise<void> {
if (!request) {
return request;
return;
}
if (typeof window !== undefined && !window.navigator.onLine) {
this.push(request);
return;
}
this.sendQueue = this.sendQueue.then(async () => {
try {
Expand Down

0 comments on commit 3c77b9d

Please sign in to comment.