@justanalyticsapp/node 0.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.
Files changed (52) hide show
  1. package/dist/client.d.ts +286 -0
  2. package/dist/client.js +681 -0
  3. package/dist/client.js.map +1 -0
  4. package/dist/context.d.ts +126 -0
  5. package/dist/context.js +170 -0
  6. package/dist/context.js.map +1 -0
  7. package/dist/errors.d.ts +135 -0
  8. package/dist/errors.js +180 -0
  9. package/dist/errors.js.map +1 -0
  10. package/dist/index.d.ts +301 -0
  11. package/dist/index.js +314 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/integrations/express.d.ts +77 -0
  14. package/dist/integrations/express.js +87 -0
  15. package/dist/integrations/express.js.map +1 -0
  16. package/dist/integrations/http.d.ts +129 -0
  17. package/dist/integrations/http.js +465 -0
  18. package/dist/integrations/http.js.map +1 -0
  19. package/dist/integrations/metrics.d.ts +110 -0
  20. package/dist/integrations/metrics.js +313 -0
  21. package/dist/integrations/metrics.js.map +1 -0
  22. package/dist/integrations/next.d.ts +252 -0
  23. package/dist/integrations/next.js +480 -0
  24. package/dist/integrations/next.js.map +1 -0
  25. package/dist/integrations/pg.d.ts +169 -0
  26. package/dist/integrations/pg.js +616 -0
  27. package/dist/integrations/pg.js.map +1 -0
  28. package/dist/integrations/pino.d.ts +52 -0
  29. package/dist/integrations/pino.js +153 -0
  30. package/dist/integrations/pino.js.map +1 -0
  31. package/dist/integrations/redis.d.ts +190 -0
  32. package/dist/integrations/redis.js +597 -0
  33. package/dist/integrations/redis.js.map +1 -0
  34. package/dist/integrations/winston.d.ts +48 -0
  35. package/dist/integrations/winston.js +99 -0
  36. package/dist/integrations/winston.js.map +1 -0
  37. package/dist/logger.d.ts +148 -0
  38. package/dist/logger.js +162 -0
  39. package/dist/logger.js.map +1 -0
  40. package/dist/span.d.ts +192 -0
  41. package/dist/span.js +197 -0
  42. package/dist/span.js.map +1 -0
  43. package/dist/transport.d.ts +246 -0
  44. package/dist/transport.js +654 -0
  45. package/dist/transport.js.map +1 -0
  46. package/dist/utils/headers.d.ts +60 -0
  47. package/dist/utils/headers.js +93 -0
  48. package/dist/utils/headers.js.map +1 -0
  49. package/dist/utils/id.d.ts +23 -0
  50. package/dist/utils/id.js +36 -0
  51. package/dist/utils/id.js.map +1 -0
  52. package/package.json +65 -0
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @file packages/node-sdk/src/utils/headers.ts
3
+ * @description W3C Trace Context traceparent header parsing and serialization.
4
+ *
5
+ * Implements Story 035 - Node.js SDK Core
6
+ *
7
+ * Format: "00-{traceId}-{spanId}-{flags}"
8
+ * - version: "00" (only supported version)
9
+ * - traceId: 32-char lowercase hex (128-bit, must not be all zeros)
10
+ * - spanId: 16-char lowercase hex (64-bit, must not be all zeros)
11
+ * - flags: 2-char hex ("01" = sampled, "00" = not sampled)
12
+ *
13
+ * References:
14
+ * - W3C Trace Context: https://www.w3.org/TR/trace-context/
15
+ */
16
+ /** Parsed W3C traceparent header data */
17
+ export interface TraceparentData {
18
+ /** Version field, always "00" */
19
+ version: string;
20
+ /** 32-character hex trace ID */
21
+ traceId: string;
22
+ /** 16-character hex parent span ID */
23
+ parentSpanId: string;
24
+ /** 2-character hex trace flags ("01" = sampled, "00" = not sampled) */
25
+ traceFlags: string;
26
+ }
27
+ /**
28
+ * Parse a W3C traceparent header string.
29
+ *
30
+ * Format: "00-{traceId}-{spanId}-{flags}"
31
+ *
32
+ * Returns `null` for invalid or malformed headers (does not throw).
33
+ *
34
+ * @param header - The traceparent header string to parse
35
+ * @returns Parsed traceparent data, or null if invalid
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const data = parseTraceparent('00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01');
40
+ * // { version: '00', traceId: '4bf92f...', parentSpanId: '00f067...', traceFlags: '01' }
41
+ * ```
42
+ */
43
+ export declare function parseTraceparent(header: string): TraceparentData | null;
44
+ /**
45
+ * Serialize a W3C traceparent header string.
46
+ *
47
+ * Produces: "00-{traceId}-{spanId}-{flags}"
48
+ *
49
+ * @param traceId - 32-character hex trace ID
50
+ * @param spanId - 16-character hex span ID
51
+ * @param sampled - Whether the trace is sampled (default: true). true = "01", false = "00"
52
+ * @returns W3C traceparent header string
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const header = serializeTraceparent('4bf92f3577b34da6a3ce929d0e0e4736', '00f067aa0ba902b7');
57
+ * // "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
58
+ * ```
59
+ */
60
+ export declare function serializeTraceparent(traceId: string, spanId: string, sampled?: boolean): string;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ /**
3
+ * @file packages/node-sdk/src/utils/headers.ts
4
+ * @description W3C Trace Context traceparent header parsing and serialization.
5
+ *
6
+ * Implements Story 035 - Node.js SDK Core
7
+ *
8
+ * Format: "00-{traceId}-{spanId}-{flags}"
9
+ * - version: "00" (only supported version)
10
+ * - traceId: 32-char lowercase hex (128-bit, must not be all zeros)
11
+ * - spanId: 16-char lowercase hex (64-bit, must not be all zeros)
12
+ * - flags: 2-char hex ("01" = sampled, "00" = not sampled)
13
+ *
14
+ * References:
15
+ * - W3C Trace Context: https://www.w3.org/TR/trace-context/
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.parseTraceparent = parseTraceparent;
19
+ exports.serializeTraceparent = serializeTraceparent;
20
+ /** Regex for validating a 32-char lowercase hex string */
21
+ const TRACE_ID_REGEX = /^[0-9a-f]{32}$/;
22
+ /** Regex for validating a 16-char lowercase hex string */
23
+ const SPAN_ID_REGEX = /^[0-9a-f]{16}$/;
24
+ /** Regex for validating a 2-char lowercase hex string */
25
+ const FLAGS_REGEX = /^[0-9a-f]{2}$/;
26
+ /** All-zero trace ID (invalid per W3C spec) */
27
+ const ZERO_TRACE_ID = '00000000000000000000000000000000';
28
+ /** All-zero span ID (invalid per W3C spec) */
29
+ const ZERO_SPAN_ID = '0000000000000000';
30
+ /**
31
+ * Parse a W3C traceparent header string.
32
+ *
33
+ * Format: "00-{traceId}-{spanId}-{flags}"
34
+ *
35
+ * Returns `null` for invalid or malformed headers (does not throw).
36
+ *
37
+ * @param header - The traceparent header string to parse
38
+ * @returns Parsed traceparent data, or null if invalid
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * const data = parseTraceparent('00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01');
43
+ * // { version: '00', traceId: '4bf92f...', parentSpanId: '00f067...', traceFlags: '01' }
44
+ * ```
45
+ */
46
+ function parseTraceparent(header) {
47
+ if (!header || typeof header !== 'string') {
48
+ return null;
49
+ }
50
+ const parts = header.split('-');
51
+ if (parts.length !== 4) {
52
+ return null;
53
+ }
54
+ const [version, traceId, parentSpanId, traceFlags] = parts;
55
+ // Validate version (only "00" supported)
56
+ if (version !== '00') {
57
+ return null;
58
+ }
59
+ // Validate traceId: 32 hex chars, not all zeros
60
+ if (!TRACE_ID_REGEX.test(traceId) || traceId === ZERO_TRACE_ID) {
61
+ return null;
62
+ }
63
+ // Validate parentSpanId: 16 hex chars, not all zeros
64
+ if (!SPAN_ID_REGEX.test(parentSpanId) || parentSpanId === ZERO_SPAN_ID) {
65
+ return null;
66
+ }
67
+ // Validate traceFlags: 2 hex chars
68
+ if (!FLAGS_REGEX.test(traceFlags)) {
69
+ return null;
70
+ }
71
+ return { version, traceId, parentSpanId, traceFlags };
72
+ }
73
+ /**
74
+ * Serialize a W3C traceparent header string.
75
+ *
76
+ * Produces: "00-{traceId}-{spanId}-{flags}"
77
+ *
78
+ * @param traceId - 32-character hex trace ID
79
+ * @param spanId - 16-character hex span ID
80
+ * @param sampled - Whether the trace is sampled (default: true). true = "01", false = "00"
81
+ * @returns W3C traceparent header string
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const header = serializeTraceparent('4bf92f3577b34da6a3ce929d0e0e4736', '00f067aa0ba902b7');
86
+ * // "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
87
+ * ```
88
+ */
89
+ function serializeTraceparent(traceId, spanId, sampled = true) {
90
+ const flags = sampled ? '01' : '00';
91
+ return `00-${traceId}-${spanId}-${flags}`;
92
+ }
93
+ //# sourceMappingURL=headers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/utils/headers.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AA6CH,4CAiCC;AAkBD,oDAOC;AAzFD,0DAA0D;AAC1D,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAExC,0DAA0D;AAC1D,MAAM,aAAa,GAAG,gBAAgB,CAAC;AAEvC,yDAAyD;AACzD,MAAM,WAAW,GAAG,eAAe,CAAC;AAEpC,+CAA+C;AAC/C,MAAM,aAAa,GAAG,kCAAkC,CAAC;AAEzD,8CAA8C;AAC9C,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAExC;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,gBAAgB,CAAC,MAAc;IAC7C,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC;IAE3D,yCAAyC;IACzC,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,gDAAgD;IAChD,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,OAAO,KAAK,aAAa,EAAE,CAAC;QAC/D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,qDAAqD;IACrD,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,YAAY,KAAK,YAAY,EAAE,CAAC;QACvE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,mCAAmC;IACnC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC;AACxD,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,oBAAoB,CAClC,OAAe,EACf,MAAc,EACd,UAAmB,IAAI;IAEvB,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACpC,OAAO,MAAM,OAAO,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @file packages/node-sdk/src/utils/id.ts
3
+ * @description Cryptographically random ID generation for trace and span IDs.
4
+ *
5
+ * Implements Story 035 - Node.js SDK Core
6
+ *
7
+ * Uses Node.js built-in `crypto.randomBytes` for 128-bit trace IDs (32 hex chars)
8
+ * and 64-bit span IDs (16 hex chars), per W3C Trace Context specification.
9
+ */
10
+ /**
11
+ * Generate a 32-character lowercase hex trace ID.
12
+ * Uses `crypto.randomBytes(16)` for 128 bits of cryptographic randomness.
13
+ *
14
+ * @returns 32-character lowercase hex string (e.g. "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6")
15
+ */
16
+ export declare function generateTraceId(): string;
17
+ /**
18
+ * Generate a 16-character lowercase hex span ID.
19
+ * Uses `crypto.randomBytes(8)` for 64 bits of cryptographic randomness.
20
+ *
21
+ * @returns 16-character lowercase hex string (e.g. "a1b2c3d4e5f6a7b8")
22
+ */
23
+ export declare function generateSpanId(): string;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /**
3
+ * @file packages/node-sdk/src/utils/id.ts
4
+ * @description Cryptographically random ID generation for trace and span IDs.
5
+ *
6
+ * Implements Story 035 - Node.js SDK Core
7
+ *
8
+ * Uses Node.js built-in `crypto.randomBytes` for 128-bit trace IDs (32 hex chars)
9
+ * and 64-bit span IDs (16 hex chars), per W3C Trace Context specification.
10
+ */
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.generateTraceId = generateTraceId;
16
+ exports.generateSpanId = generateSpanId;
17
+ const crypto_1 = __importDefault(require("crypto"));
18
+ /**
19
+ * Generate a 32-character lowercase hex trace ID.
20
+ * Uses `crypto.randomBytes(16)` for 128 bits of cryptographic randomness.
21
+ *
22
+ * @returns 32-character lowercase hex string (e.g. "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6")
23
+ */
24
+ function generateTraceId() {
25
+ return crypto_1.default.randomBytes(16).toString('hex');
26
+ }
27
+ /**
28
+ * Generate a 16-character lowercase hex span ID.
29
+ * Uses `crypto.randomBytes(8)` for 64 bits of cryptographic randomness.
30
+ *
31
+ * @returns 16-character lowercase hex string (e.g. "a1b2c3d4e5f6a7b8")
32
+ */
33
+ function generateSpanId() {
34
+ return crypto_1.default.randomBytes(8).toString('hex');
35
+ }
36
+ //# sourceMappingURL=id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id.js","sourceRoot":"","sources":["../../src/utils/id.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;AAUH,0CAEC;AAQD,wCAEC;AApBD,oDAA4B;AAE5B;;;;;GAKG;AACH,SAAgB,eAAe;IAC7B,OAAO,gBAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAChD,CAAC;AAED;;;;;GAKG;AACH,SAAgB,cAAc;IAC5B,OAAO,gBAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC/C,CAAC"}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@justanalyticsapp/node",
3
+ "version": "0.1.0",
4
+ "description": "JustAnalytics Node.js SDK for distributed tracing and observability",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "require": "./dist/index.js",
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ },
13
+ "./next": {
14
+ "require": "./dist/integrations/next.js",
15
+ "import": "./dist/integrations/next.js",
16
+ "types": "./dist/integrations/next.d.ts"
17
+ },
18
+ "./winston": {
19
+ "require": "./dist/integrations/winston.js",
20
+ "import": "./dist/integrations/winston.js",
21
+ "types": "./dist/integrations/winston.d.ts"
22
+ },
23
+ "./pino": {
24
+ "require": "./dist/integrations/pino.js",
25
+ "import": "./dist/integrations/pino.js",
26
+ "types": "./dist/integrations/pino.d.ts"
27
+ }
28
+ },
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "engines": {
33
+ "node": ">=18.0.0"
34
+ },
35
+ "scripts": {
36
+ "build": "tsc",
37
+ "clean": "rm -rf dist",
38
+ "prepublishOnly": "npm run clean && npm run build"
39
+ },
40
+ "keywords": [
41
+ "analytics",
42
+ "tracing",
43
+ "observability",
44
+ "apm",
45
+ "justanalytics",
46
+ "logging"
47
+ ],
48
+ "license": "MIT",
49
+ "peerDependencies": {
50
+ "winston-transport": ">=4.0.0",
51
+ "pino-abstract-transport": ">=1.0.0"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "winston-transport": {
55
+ "optional": true
56
+ },
57
+ "pino-abstract-transport": {
58
+ "optional": true
59
+ }
60
+ },
61
+ "devDependencies": {
62
+ "@types/node": "^20.0.0",
63
+ "typescript": "^5.3.0"
64
+ }
65
+ }