Skip to content

Commit

Permalink
[dashboard] add session id to error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
akosyakov committed Sep 20, 2023
1 parent a2b5b00 commit cc61b00
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
40 changes: 26 additions & 14 deletions components/dashboard/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,23 @@
* Licensed under the GNU Affero General Public License (AGPL).
* See License.AGPL.txt in the project root for license information.
*/

/*
* Resolver allows to reconstruct stack traces from obfuscated stack traces for the dashboard.
* Usage:
* node resolver.js < obfuscated-stack-trace.txt
*
* OR
*
* node resolver.js <<EOF
* obfuscated stack trace
* EOF
*/

//@ts-check
const path = require('path');
const fetch = require('node-fetch').default;
const { SourceMapConsumer } = require('source-map');
const path = require("path");
const fetch = require("node-fetch").default;
const { SourceMapConsumer } = require("source-map");

const sourceMapCache = {};

Expand All @@ -27,10 +40,10 @@ async function fetchSourceMap(jsUrl) {
// Extract source map URL from the JS file
const mapUrlMatch = jsContent.match(/\/\/#\s*sourceMappingURL=(.+)/);
if (!mapUrlMatch) {
throw new Error('Source map URL not found');
throw new Error("Source map URL not found");
}

const mapUrl = new URL(mapUrlMatch[1], jsUrl).href; // Resolve relative URL
const mapUrl = new URL(mapUrlMatch[1], jsUrl).href; // Resolve relative URL
const mapResponse = await fetch(mapUrl);
const mapData = await mapResponse.json();

Expand All @@ -40,7 +53,7 @@ async function fetchSourceMap(jsUrl) {
return mapData;
}

const BASE_PATH = '/workspace/gitpod/components';
const BASE_PATH = "/workspace/gitpod/components";

async function resolveLine(line) {
const jsUrl = extractJsUrlFromLine(line);
Expand All @@ -53,7 +66,7 @@ async function resolveLine(line) {
return line;
}

const functionName = matches[1] || '';
const functionName = matches[1] || "";
const lineNum = Number(matches[3]);
const colNum = Number(matches[4]);

Expand All @@ -69,18 +82,17 @@ async function resolveLine(line) {
return line;
}

let obfuscatedTrace = "";

let obfuscatedTrace = '';

process.stdin.on('data', function(data) {
process.stdin.on("data", function (data) {
obfuscatedTrace += data;
});

process.stdin.on('end', async function() {
const lines = obfuscatedTrace.split('\n');
process.stdin.on("end", async function () {
const lines = obfuscatedTrace.split("\n");
const resolvedLines = await Promise.all(lines.map(resolveLine));
const resolvedTrace = resolvedLines.join('\n');
console.log('\nResolved Stack Trace:\n');
const resolvedTrace = resolvedLines.join("\n");
console.log("\nResolved Stack Trace:\n");
console.log(resolvedTrace);
});

Expand Down
5 changes: 4 additions & 1 deletion components/dashboard/src/service/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { GitpodHostUrl } from "@gitpod/gitpod-protocol/lib/util/gitpod-host-url";
import { MetricsReporter } from "@gitpod/public-api/lib/metrics";
import { getExperimentsClient } from "../experiments/client";
import { v4 } from "uuid";

const originalConsoleError = console.error;

Expand Down Expand Up @@ -40,7 +41,9 @@ console.error = function (...args) {
reportError(...args);
};

let commonDetails = {};
const commonDetails = {
sessionId: v4(),
};
export function updateCommonErrorDetails(update: { [key: string]: string | undefined }) {
Object.assign(commonDetails, update);
}
Expand Down

0 comments on commit cc61b00

Please sign in to comment.