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 3fd698d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/dashboard/src/service/service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function testPublicAPI(service: any): void {
backoff = BASE_BACKOFF;
}
} catch (e) {
if (ConnectError.from(e).code === Code.Canceled) {
if (e instanceof ConnectError && e.code === Code.DeadlineExceeded) {
// timeout is expected, continue as usual
backoff = BASE_BACKOFF;
} else {
Expand Down
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 3fd698d

Please sign in to comment.