@deeptracer/browser 0.2.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.cjs +74 -0
- package/dist/index.d.cts +39 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +46 -0
- package/package.json +32 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
captureConsole: () => captureConsole,
|
|
25
|
+
captureGlobalErrors: () => captureGlobalErrors
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
__reExport(index_exports, require("@deeptracer/core"), module.exports);
|
|
29
|
+
|
|
30
|
+
// src/global-errors.ts
|
|
31
|
+
function captureGlobalErrors(logger) {
|
|
32
|
+
window.addEventListener("error", (event) => {
|
|
33
|
+
logger.captureError(event.error || new Error(event.message || "Unknown error"), {
|
|
34
|
+
severity: "critical"
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
window.addEventListener("unhandledrejection", (event) => {
|
|
38
|
+
logger.captureError(
|
|
39
|
+
event.reason instanceof Error ? event.reason : new Error(String(event.reason)),
|
|
40
|
+
{ severity: "high" }
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/console.ts
|
|
46
|
+
var import_internal = require("@deeptracer/core/internal");
|
|
47
|
+
function captureConsole(logger) {
|
|
48
|
+
console.log = (...args) => {
|
|
49
|
+
logger.info(args.map(String).join(" "));
|
|
50
|
+
import_internal._originalConsole.log(...args);
|
|
51
|
+
};
|
|
52
|
+
console.info = (...args) => {
|
|
53
|
+
logger.info(args.map(String).join(" "));
|
|
54
|
+
import_internal._originalConsole.info(...args);
|
|
55
|
+
};
|
|
56
|
+
console.warn = (...args) => {
|
|
57
|
+
logger.warn(args.map(String).join(" "));
|
|
58
|
+
import_internal._originalConsole.warn(...args);
|
|
59
|
+
};
|
|
60
|
+
console.error = (...args) => {
|
|
61
|
+
logger.error(args.map(String).join(" "));
|
|
62
|
+
import_internal._originalConsole.error(...args);
|
|
63
|
+
};
|
|
64
|
+
console.debug = (...args) => {
|
|
65
|
+
logger.debug(args.map(String).join(" "));
|
|
66
|
+
import_internal._originalConsole.debug(...args);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
70
|
+
0 && (module.exports = {
|
|
71
|
+
captureConsole,
|
|
72
|
+
captureGlobalErrors,
|
|
73
|
+
...require("@deeptracer/core")
|
|
74
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Logger } from '@deeptracer/core';
|
|
2
|
+
export * from '@deeptracer/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Automatically capture all uncaught exceptions and unhandled promise rejections
|
|
6
|
+
* via browser window events. Call once at application startup.
|
|
7
|
+
*
|
|
8
|
+
* Uncaught exceptions are reported with severity "critical".
|
|
9
|
+
* Unhandled rejections are reported with severity "high".
|
|
10
|
+
*
|
|
11
|
+
* @param logger - DeepTracer logger instance
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { createLogger, captureGlobalErrors } from "@deeptracer/browser"
|
|
16
|
+
*
|
|
17
|
+
* const logger = createLogger({ ... })
|
|
18
|
+
* captureGlobalErrors(logger)
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function captureGlobalErrors(logger: Logger): void;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Intercept all console.log/info/warn/error/debug calls and forward them
|
|
25
|
+
* to DeepTracer as log entries. Original console output is preserved.
|
|
26
|
+
*
|
|
27
|
+
* @param logger - DeepTracer logger instance
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { createLogger, captureConsole } from "@deeptracer/browser"
|
|
32
|
+
*
|
|
33
|
+
* const logger = createLogger({ ... })
|
|
34
|
+
* captureConsole(logger)
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
declare function captureConsole(logger: Logger): void;
|
|
38
|
+
|
|
39
|
+
export { captureConsole, captureGlobalErrors };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Logger } from '@deeptracer/core';
|
|
2
|
+
export * from '@deeptracer/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Automatically capture all uncaught exceptions and unhandled promise rejections
|
|
6
|
+
* via browser window events. Call once at application startup.
|
|
7
|
+
*
|
|
8
|
+
* Uncaught exceptions are reported with severity "critical".
|
|
9
|
+
* Unhandled rejections are reported with severity "high".
|
|
10
|
+
*
|
|
11
|
+
* @param logger - DeepTracer logger instance
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { createLogger, captureGlobalErrors } from "@deeptracer/browser"
|
|
16
|
+
*
|
|
17
|
+
* const logger = createLogger({ ... })
|
|
18
|
+
* captureGlobalErrors(logger)
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function captureGlobalErrors(logger: Logger): void;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Intercept all console.log/info/warn/error/debug calls and forward them
|
|
25
|
+
* to DeepTracer as log entries. Original console output is preserved.
|
|
26
|
+
*
|
|
27
|
+
* @param logger - DeepTracer logger instance
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { createLogger, captureConsole } from "@deeptracer/browser"
|
|
32
|
+
*
|
|
33
|
+
* const logger = createLogger({ ... })
|
|
34
|
+
* captureConsole(logger)
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
declare function captureConsole(logger: Logger): void;
|
|
38
|
+
|
|
39
|
+
export { captureConsole, captureGlobalErrors };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
export * from "@deeptracer/core";
|
|
3
|
+
|
|
4
|
+
// src/global-errors.ts
|
|
5
|
+
function captureGlobalErrors(logger) {
|
|
6
|
+
window.addEventListener("error", (event) => {
|
|
7
|
+
logger.captureError(event.error || new Error(event.message || "Unknown error"), {
|
|
8
|
+
severity: "critical"
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
window.addEventListener("unhandledrejection", (event) => {
|
|
12
|
+
logger.captureError(
|
|
13
|
+
event.reason instanceof Error ? event.reason : new Error(String(event.reason)),
|
|
14
|
+
{ severity: "high" }
|
|
15
|
+
);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/console.ts
|
|
20
|
+
import { _originalConsole } from "@deeptracer/core/internal";
|
|
21
|
+
function captureConsole(logger) {
|
|
22
|
+
console.log = (...args) => {
|
|
23
|
+
logger.info(args.map(String).join(" "));
|
|
24
|
+
_originalConsole.log(...args);
|
|
25
|
+
};
|
|
26
|
+
console.info = (...args) => {
|
|
27
|
+
logger.info(args.map(String).join(" "));
|
|
28
|
+
_originalConsole.info(...args);
|
|
29
|
+
};
|
|
30
|
+
console.warn = (...args) => {
|
|
31
|
+
logger.warn(args.map(String).join(" "));
|
|
32
|
+
_originalConsole.warn(...args);
|
|
33
|
+
};
|
|
34
|
+
console.error = (...args) => {
|
|
35
|
+
logger.error(args.map(String).join(" "));
|
|
36
|
+
_originalConsole.error(...args);
|
|
37
|
+
};
|
|
38
|
+
console.debug = (...args) => {
|
|
39
|
+
logger.debug(args.map(String).join(" "));
|
|
40
|
+
_originalConsole.debug(...args);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
captureConsole,
|
|
45
|
+
captureGlobalErrors
|
|
46
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@deeptracer/browser",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "DeepTracer SDK for browsers — window error handlers, fetch interceptor",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": ["dist", "README.md"],
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"keywords": ["deeptracer", "browser", "observability"],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/getdeeptracer/deeptracer-js.git",
|
|
22
|
+
"directory": "packages/browser"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@deeptracer/core": "0.2.0"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup",
|
|
30
|
+
"dev": "tsup --watch"
|
|
31
|
+
}
|
|
32
|
+
}
|