@tacko/telemetry-node 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,15 @@
1
+ import { identify, trackEvent, trackError as coreTrackError, type TelemetryConfig } from "@tacko/telemetry-core";
2
+ export type TelemetryNodeConfig = TelemetryConfig & {
3
+ app: string;
4
+ platform?: string;
5
+ };
6
+ export declare function init(config: TelemetryNodeConfig): void;
7
+ export { identify, trackEvent, coreTrackError as trackError };
8
+ export declare function getConfig(): TelemetryConfig | null;
9
+ export declare function middleware(opts?: {
10
+ trackRequestBody?: boolean;
11
+ }): (req: {
12
+ method?: string;
13
+ url?: string;
14
+ body?: unknown;
15
+ }, _res: unknown, next: () => void) => void;
package/dist/index.js ADDED
@@ -0,0 +1,59 @@
1
+ import { init as coreInit, identify, trackEvent, trackError as coreTrackError, getConfigOrNull, } from "@tacko/telemetry-core";
2
+ let installed = false;
3
+ function installGlobalHandlers() {
4
+ if (installed)
5
+ return;
6
+ installed = true;
7
+ process.on("uncaughtException", (err) => {
8
+ coreTrackError(err, { source: "uncaughtException" });
9
+ throw err;
10
+ });
11
+ process.on("unhandledRejection", (reason) => {
12
+ const err = reason instanceof Error ? reason : new Error(String(reason));
13
+ coreTrackError(err, { source: "unhandledRejection" });
14
+ });
15
+ }
16
+ export function init(config) {
17
+ coreInit({ ...config, platform: config.platform ?? "node" });
18
+ installGlobalHandlers();
19
+ }
20
+ export { identify, trackEvent, coreTrackError as trackError };
21
+ export function getConfig() {
22
+ return getConfigOrNull();
23
+ }
24
+ export function middleware(opts) {
25
+ const trackRequestBody = opts?.trackRequestBody ?? false;
26
+ return function telemetryMiddleware(req, _res, next) {
27
+ const cfg = getConfigOrNull();
28
+ if (!cfg) {
29
+ next();
30
+ return;
31
+ }
32
+ const start = Date.now();
33
+ const method = req.method ?? "GET";
34
+ const url = req.url ?? "";
35
+ let finished = false;
36
+ const done = () => {
37
+ if (finished)
38
+ return;
39
+ finished = true;
40
+ const duration = Date.now() - start;
41
+ trackEvent("$request", {
42
+ method,
43
+ url,
44
+ duration_ms: duration,
45
+ ...(trackRequestBody && req.body ? { body: req.body } : {}),
46
+ });
47
+ };
48
+ const reqWithOn = req;
49
+ if (typeof reqWithOn.on === "function") {
50
+ reqWithOn.on("end", done);
51
+ reqWithOn.on("close", done);
52
+ }
53
+ else {
54
+ next();
55
+ done();
56
+ }
57
+ next();
58
+ };
59
+ }
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@tacko/telemetry-node",
3
+ "version": "1.0.0",
4
+ "description": "Telemetry Tracker SDK for Node.js: global error handlers, request middleware.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/unjica/telemetry-tracker.git",
9
+ "directory": "packages/telemetry-node"
10
+ },
11
+ "type": "module",
12
+ "main": "dist/index.js",
13
+ "types": "dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/index.js",
17
+ "types": "./dist/index.d.ts"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "keywords": [
24
+ "telemetry",
25
+ "node",
26
+ "server",
27
+ "errors",
28
+ "middleware"
29
+ ],
30
+ "dependencies": {
31
+ "@tacko/telemetry-core": "^1.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^22.9.0",
35
+ "typescript": "^5.6.3"
36
+ },
37
+ "scripts": {
38
+ "build": "tsc",
39
+ "dev": "tsc --watch"
40
+ }
41
+ }