Skip to content

Commit

Permalink
add error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
benStre committed Nov 30, 2023
1 parent f08cc92 commit c63f411
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions utils/error-reporting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Compiler } from "../compiler/compiler.ts";
import { sendDatexViaHTTPChannel } from "../network/datex-http-channel.ts";
import { Runtime } from "../runtime/runtime.ts";
import { getCallerInfo } from "../utils/caller_metadata.ts";
import { logger } from "./global_values.ts";

export async function sendReport(id: string, reportData:Record<string,any>) {
if (!enabled) return;

const report = {
id,
timestamp: new Date(),
metaData: {
datexcoreVersion: Runtime.VERSION,
uixVersion: globalThis.UIX?.version,
denoVersion: globalThis.Deno?.version.deno,
tsVersion: globalThis.Deno?.version.typescript,
v8Version: globalThis.Deno?.version.v8,
userAgent: JSON.parse(JSON.stringify(window.navigator.userAgentData ?? window.navigator.userAgent))
},
reportData,
stack: getCallerInfo()
}

console.log("report", report);

const dx = `@+unyt_status.Reporting.sendReport(?)`
const dxb = <ArrayBuffer> await Compiler.compile(dx, [report], {sign: false, encrypt: false});
sendDatexViaHTTPChannel(dxb, "https://status.unyt.org")
}

let enabled = false;

export function enableErrorReporting(enable = true) {
logger.debug("error reporting to unyt.org " + (enable ? "enabled" : "disabled"));
enabled = enable;
}

0 comments on commit c63f411

Please sign in to comment.