@tacko/telemetry-core 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -2
- package/package.json +1 -1
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAsDF,wBAAgB,IAAI,CAAC,CAAC,EAAE,eAAe,GAAG,IAAI,CAS7C;AAED,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAEhD;AAwDD,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACnC,IAAI,CAqBN;AAED,wBAAgB,UAAU,CACxB,KAAK,EAAE,KAAK,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,EAClD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,IAAI,CAcN;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEzC;AAED,wBAAgB,SAAS,IAAI,MAAM,GAAG,IAAI,CAEzC;AAED,wBAAgB,eAAe,IAAI,eAAe,GAAG,IAAI,CAExD"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,39 @@
|
|
|
1
|
+
const REPORTED = Symbol.for("telemetry.reported");
|
|
1
2
|
let config = null;
|
|
2
3
|
let userId = null;
|
|
4
|
+
let browserHandlersInstalled = false;
|
|
3
5
|
const DEFAULT_BATCH_INTERVAL = 5000;
|
|
4
6
|
const DEFAULT_BATCH_SIZE = 10;
|
|
5
7
|
const eventQueue = [];
|
|
6
8
|
let flushTimer = null;
|
|
9
|
+
function installBrowserErrorHandlers() {
|
|
10
|
+
if (browserHandlersInstalled || typeof window === "undefined")
|
|
11
|
+
return;
|
|
12
|
+
browserHandlersInstalled = true;
|
|
13
|
+
window.onerror = (message, source, lineno, colno, error) => {
|
|
14
|
+
const cfg = getConfigOrNull();
|
|
15
|
+
if (!cfg)
|
|
16
|
+
return false;
|
|
17
|
+
const err = error && error instanceof Error
|
|
18
|
+
? error
|
|
19
|
+
: new Error(typeof message === "string" ? message : String(message));
|
|
20
|
+
trackError(err, {
|
|
21
|
+
source: "window.onerror",
|
|
22
|
+
filename: source,
|
|
23
|
+
lineno,
|
|
24
|
+
colno,
|
|
25
|
+
});
|
|
26
|
+
return false; // let other handlers run
|
|
27
|
+
};
|
|
28
|
+
window.addEventListener("unhandledrejection", (event) => {
|
|
29
|
+
const cfg = getConfigOrNull();
|
|
30
|
+
if (!cfg)
|
|
31
|
+
return;
|
|
32
|
+
const reason = event.reason;
|
|
33
|
+
const err = reason instanceof Error ? reason : new Error(reason != null ? String(reason) : "Unhandled rejection");
|
|
34
|
+
trackError(err, { source: "unhandledrejection" });
|
|
35
|
+
});
|
|
36
|
+
}
|
|
7
37
|
export function init(c) {
|
|
8
38
|
config = { ...c };
|
|
9
39
|
const interval = c.batchInterval ?? DEFAULT_BATCH_INTERVAL;
|
|
@@ -13,6 +43,7 @@ export function init(c) {
|
|
|
13
43
|
if (typeof t.unref === "function")
|
|
14
44
|
t.unref();
|
|
15
45
|
}
|
|
46
|
+
installBrowserErrorHandlers();
|
|
16
47
|
}
|
|
17
48
|
export function identify(id) {
|
|
18
49
|
userId = id;
|
|
@@ -95,8 +126,15 @@ export function trackEvent(name, properties) {
|
|
|
95
126
|
}
|
|
96
127
|
}
|
|
97
128
|
export function trackError(error, context) {
|
|
98
|
-
|
|
99
|
-
|
|
129
|
+
if (!getConfigOrNull())
|
|
130
|
+
return;
|
|
131
|
+
const err = error instanceof Error ? error : { message: error.message, stack: error.stack };
|
|
132
|
+
if (err && typeof err === "object" && err[REPORTED])
|
|
133
|
+
return;
|
|
134
|
+
const message = err instanceof Error ? err.message : err.message;
|
|
135
|
+
const stack = err instanceof Error ? err.stack : err.stack;
|
|
136
|
+
if (err instanceof Error)
|
|
137
|
+
err[REPORTED] = true;
|
|
100
138
|
send("/ingest/error", {
|
|
101
139
|
message,
|
|
102
140
|
stack: stack ?? undefined,
|