@obzerver/node 0.0.0-stage → 0.6.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 (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +97 -2
  3. package/dist/agent-types.d.ts +28 -0
  4. package/dist/agent-types.js +6 -0
  5. package/dist/agent-types.js.map +1 -0
  6. package/dist/agent.d.ts +97 -0
  7. package/dist/agent.js +651 -0
  8. package/dist/agent.js.map +1 -0
  9. package/dist/context.d.ts +86 -0
  10. package/dist/context.js +136 -0
  11. package/dist/context.js.map +1 -0
  12. package/dist/errors.d.ts +18 -0
  13. package/dist/errors.js +108 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/glob.d.ts +7 -0
  16. package/dist/glob.js +56 -0
  17. package/dist/glob.js.map +1 -0
  18. package/dist/index.d.ts +76 -0
  19. package/dist/index.js +89 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/instrument/classes.d.ts +18 -0
  22. package/dist/instrument/classes.js +103 -0
  23. package/dist/instrument/classes.js.map +1 -0
  24. package/dist/instrument/console.d.ts +11 -0
  25. package/dist/instrument/console.js +68 -0
  26. package/dist/instrument/console.js.map +1 -0
  27. package/dist/instrument/db.d.ts +7 -0
  28. package/dist/instrument/db.js +155 -0
  29. package/dist/instrument/db.js.map +1 -0
  30. package/dist/instrument/express.d.ts +3 -0
  31. package/dist/instrument/express.js +133 -0
  32. package/dist/instrument/express.js.map +1 -0
  33. package/dist/instrument/fastify.d.ts +35 -0
  34. package/dist/instrument/fastify.js +88 -0
  35. package/dist/instrument/fastify.js.map +1 -0
  36. package/dist/instrument/http.d.ts +10 -0
  37. package/dist/instrument/http.js +149 -0
  38. package/dist/instrument/http.js.map +1 -0
  39. package/dist/instrument/jobs.d.ts +15 -0
  40. package/dist/instrument/jobs.js +90 -0
  41. package/dist/instrument/jobs.js.map +1 -0
  42. package/dist/options.d.ts +110 -0
  43. package/dist/options.js +3 -0
  44. package/dist/options.js.map +1 -0
  45. package/dist/protocol.d.ts +146 -0
  46. package/dist/protocol.js +4 -0
  47. package/dist/protocol.js.map +1 -0
  48. package/dist/redact.d.ts +12 -0
  49. package/dist/redact.js +54 -0
  50. package/dist/redact.js.map +1 -0
  51. package/dist/register.d.ts +1 -0
  52. package/dist/register.js +9 -0
  53. package/dist/register.js.map +1 -0
  54. package/dist/release.d.ts +32 -0
  55. package/dist/release.js +141 -0
  56. package/dist/release.js.map +1 -0
  57. package/dist/runtime.d.ts +37 -0
  58. package/dist/runtime.js +142 -0
  59. package/dist/runtime.js.map +1 -0
  60. package/dist/transport.d.ts +32 -0
  61. package/dist/transport.js +122 -0
  62. package/dist/transport.js.map +1 -0
  63. package/package.json +51 -4
@@ -0,0 +1,146 @@
1
+ export interface StackFrame {
2
+ fn: string;
3
+ file: string;
4
+ rel: string;
5
+ line: number;
6
+ col: number;
7
+ inApp: boolean;
8
+ context?: {
9
+ start: number;
10
+ lines: string[];
11
+ };
12
+ }
13
+ export interface WireSpan {
14
+ id: string;
15
+ parentId: string | null;
16
+ name: string;
17
+ kind: SpanKind;
18
+ /** ms offset from the trace start */
19
+ start: number;
20
+ duration: number;
21
+ /** duration minus the union of child intervals */
22
+ self: number;
23
+ /** >1 when repeated sibling spans were collapsed into one */
24
+ count?: number;
25
+ attrs?: Record<string, unknown>;
26
+ error?: string;
27
+ }
28
+ export type SpanKind = 'request' | 'job' | 'middleware' | 'handler' | 'function' | 'custom' | 'db' | 'http';
29
+ export interface CaptureData {
30
+ reason: 'failed' | 'error' | 'slow';
31
+ headers?: Record<string, unknown>;
32
+ query?: string;
33
+ body?: string;
34
+ }
35
+ export interface WireTrace {
36
+ traceId: string;
37
+ spanId: string;
38
+ parentSpanId: string | null;
39
+ kind: 'http' | 'job';
40
+ name: string;
41
+ method: string | null;
42
+ route: string | null;
43
+ path: string | null;
44
+ status: number | null;
45
+ ts: number;
46
+ duration: number;
47
+ userId: string | null;
48
+ failed: boolean;
49
+ errorClass: string | null;
50
+ fingerprint: string | null;
51
+ errorMessage: string | null;
52
+ tags?: Record<string, unknown>;
53
+ capture?: CaptureData;
54
+ queue: string | null;
55
+ queueWait: number | null;
56
+ attempt: number | null;
57
+ sampled: boolean;
58
+ spans?: WireSpan[];
59
+ }
60
+ export interface WireError {
61
+ ts: number;
62
+ class: string;
63
+ message: string;
64
+ stack: string;
65
+ frames: StackFrame[];
66
+ fingerprint: string;
67
+ status: number | null;
68
+ handled: boolean;
69
+ code: string | null;
70
+ httpStatus?: number | null;
71
+ traceId?: string | null;
72
+ operation?: string | null;
73
+ kind?: string;
74
+ userId?: string | null;
75
+ version?: string | null;
76
+ }
77
+ export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
78
+ export interface WireLog {
79
+ ts: number;
80
+ level: LogLevel | string;
81
+ message: string;
82
+ logger: string | null;
83
+ traceId: string | null;
84
+ spanId: string | null;
85
+ attrs?: Record<string, unknown>;
86
+ }
87
+ export interface WireRuntime {
88
+ ts: number;
89
+ cpu: number;
90
+ rss: number;
91
+ heapUsed: number;
92
+ heapTotal: number;
93
+ external: number;
94
+ elDelayP50: number;
95
+ elDelayP99: number;
96
+ elDelayMax: number;
97
+ elu: number;
98
+ gcCount: number;
99
+ gcMs: number;
100
+ handles: number | null;
101
+ inflight: number;
102
+ }
103
+ export type MetricType = 'counter' | 'gauge' | 'summary';
104
+ export interface WireMetric {
105
+ ts: number;
106
+ name: string;
107
+ type: MetricType;
108
+ labels: Record<string, string>;
109
+ value: number;
110
+ count: number;
111
+ sum?: number;
112
+ min?: number | null;
113
+ max?: number | null;
114
+ }
115
+ export interface ServiceInfo {
116
+ id: string;
117
+ version: string | null;
118
+ instance: string;
119
+ environment?: string;
120
+ node?: string;
121
+ host?: string;
122
+ pid?: number;
123
+ frameworks?: string[];
124
+ }
125
+ export interface IngestPayload {
126
+ sdk?: {
127
+ name: string;
128
+ version: string;
129
+ };
130
+ service: ServiceInfo;
131
+ sentAt?: number;
132
+ dropped?: number;
133
+ traces?: WireTrace[];
134
+ errors?: WireError[];
135
+ logs?: WireLog[];
136
+ runtime?: WireRuntime[];
137
+ metrics?: WireMetric[];
138
+ }
139
+ export type QueueKind = 'traces' | 'errors' | 'logs' | 'runtime' | 'metrics';
140
+ export interface QueueItems {
141
+ traces: WireTrace;
142
+ errors: WireError;
143
+ logs: WireLog;
144
+ runtime: WireRuntime;
145
+ metrics: WireMetric;
146
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ // Wire format between @obzerver/node and @obzerver/server (POST /v1/ingest, gzip JSON).
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":";AAAA,wFAAwF"}
@@ -0,0 +1,12 @@
1
+ export interface RedactionOptions {
2
+ enabled?: boolean;
3
+ useDefaultPatterns?: boolean;
4
+ keys?: string[];
5
+ patterns?: RegExp[];
6
+ replacement?: string;
7
+ }
8
+ export interface Redactor {
9
+ string(s: string): string;
10
+ value<T>(v: T): T;
11
+ }
12
+ export declare function createRedactor(opts?: RedactionOptions | false): Redactor;
package/dist/redact.js ADDED
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createRedactor = createRedactor;
4
+ const DEFAULT_KEYS = [
5
+ 'authorization', 'cookie', 'set-cookie', 'password', 'passwd', 'pwd', 'secret', 'token',
6
+ 'access_token', 'refresh_token', 'id_token', 'api_key', 'apikey', 'x-api-key', 'client_secret',
7
+ 'private_key', 'credit_card', 'card_number', 'cvv', 'ssn', 'x-obzerver-key',
8
+ ];
9
+ const DEFAULT_PATTERNS = [
10
+ /\bBearer\s+[A-Za-z0-9\-._~+/]+=*/g,
11
+ /\beyJ[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,}\b/g, // JWT
12
+ /\b(AKIA|ASIA)[0-9A-Z]{16}\b/g, // AWS key id
13
+ /-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z ]*PRIVATE KEY-----/g,
14
+ /\b(password|passwd|secret|token|api[_-]?key)=([^&\s"']+)/gi,
15
+ /\b(?:\d[ -]?){13,19}\b/g, // card numbers
16
+ ];
17
+ function createRedactor(opts = {}) {
18
+ if (opts === false || opts.enabled === false) {
19
+ return { string: (s) => s, value: (v) => v };
20
+ }
21
+ const replacement = opts.replacement || '[REDACTED]';
22
+ const defaults = opts.useDefaultPatterns !== false;
23
+ const keys = new Set([...(defaults ? DEFAULT_KEYS : []), ...(opts.keys || [])].map((k) => k.toLowerCase()));
24
+ const patterns = [...(defaults ? DEFAULT_PATTERNS : []), ...(opts.patterns || [])];
25
+ const string = (s) => {
26
+ if (typeof s !== 'string' || !s)
27
+ return s;
28
+ let out = s;
29
+ for (const p of patterns) {
30
+ p.lastIndex = 0;
31
+ out = out.replace(p, (m, k) => (typeof k === 'string' && m.includes('=') && !/^\d/.test(m) ? `${k}=${replacement}` : replacement));
32
+ }
33
+ return out;
34
+ };
35
+ const walk = (v, depth) => {
36
+ if (v == null)
37
+ return v;
38
+ if (typeof v === 'string')
39
+ return string(v);
40
+ if (typeof v !== 'object')
41
+ return v;
42
+ if (depth > 6)
43
+ return '[depth]';
44
+ if (Array.isArray(v))
45
+ return v.slice(0, 100).map((x) => walk(x, depth + 1));
46
+ const out = {};
47
+ for (const [k, val] of Object.entries(v)) {
48
+ out[k] = keys.has(k.toLowerCase()) ? replacement : walk(val, depth + 1);
49
+ }
50
+ return out;
51
+ };
52
+ return { string, value: (v) => walk(v, 0) };
53
+ }
54
+ //# sourceMappingURL=redact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redact.js","sourceRoot":"","sources":["../src/redact.ts"],"names":[],"mappings":";;AA4BA,wCAiCC;AAhDD,MAAM,YAAY,GAAG;IACnB,eAAe,EAAE,QAAQ,EAAE,YAAY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,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,CAA4B,CAAC,EAAE,CAAC;YACpE,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;QAC1E,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAK,CAAI,EAAK,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAM,EAAE,CAAC;AAC7D,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Zero-config entry:
4
+ // node -r @obzerver/node/register app.js
5
+ // node --import @obzerver/node/register app.ts
6
+ // Configure with OBZERVER_KEY, OBZERVER_ENDPOINT, OBZERVER_SERVICE, OBZERVER_VERSION.
7
+ const index_1 = require("./index");
8
+ index_1.default.init();
9
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":";;AAAA,qBAAqB;AACrB,2CAA2C;AAC3C,iDAAiD;AACjD,sFAAsF;AACtF,mCAA+B;AAE/B,eAAQ,CAAC,IAAI,EAAE,CAAC"}
@@ -0,0 +1,32 @@
1
+ /** Where the release identifier came from (shown with `debug: true`). */
2
+ export type ReleaseSource = 'option' | 'disabled' | 'env' | 'ci' | 'git' | 'container' | 'package.json' | 'none';
3
+ export interface Release {
4
+ version: string | null;
5
+ source: ReleaseSource;
6
+ /** The env var or file it was read from, when there is one. */
7
+ from?: string;
8
+ }
9
+ /** Commit SHAs exposed by CI systems and hosting platforms, most specific first. */
10
+ export declare const CI_COMMIT_VARS: readonly ["GIT_COMMIT_SHA", "GIT_SHA", "GIT_COMMIT", "GITHUB_SHA", "CI_COMMIT_SHA", "VERCEL_GIT_COMMIT_SHA", "RENDER_GIT_COMMIT", "RAILWAY_GIT_COMMIT_SHA", "CF_PAGES_COMMIT_SHA", "COMMIT_REF", "SOURCE_VERSION", "HEROKU_SLUG_COMMIT", "KOYEB_GIT_SHA", "BITBUCKET_COMMIT", "CIRCLE_SHA1", "BUILDKITE_COMMIT", "DRONE_COMMIT_SHA", "CODEBUILD_RESOLVED_SOURCE_VERSION"];
11
+ /** Revision names set by container platforms. */
12
+ export declare const CONTAINER_REVISION_VARS: readonly ["K_REVISION", "CONTAINER_APP_REVISION"];
13
+ export declare const MAX_RELEASE_LENGTH = 50;
14
+ /** Full commit SHAs are shortened to 12 characters; every value is capped at 50. */
15
+ export declare function normaliseRelease(value: string): string;
16
+ /** The git directory for `cwd` or its nearest ancestor: a `.git` folder, or a `.git` file (worktrees, submodules). */
17
+ export declare function findGitDir(cwd: string): string | null;
18
+ /** The checked-out commit, read straight from `.git` (no git binary needed). */
19
+ export declare function readGitCommit(cwd: string): {
20
+ sha: string;
21
+ gitDir: string;
22
+ } | null;
23
+ /**
24
+ * Release identifier, from the first of:
25
+ * 1. `serviceVersion` passed to init (`false` reports none)
26
+ * 2. `OBZERVER_VERSION`
27
+ * 3. a commit exposed by CI or the hosting platform (`GITHUB_SHA`, `VERCEL_GIT_COMMIT_SHA`, …)
28
+ * 4. the commit checked out in `.git`
29
+ * 5. a container platform revision (`K_REVISION`, …)
30
+ * 6. `version` in package.json
31
+ */
32
+ export declare function inferRelease(option: string | false | null | undefined, env: NodeJS.ProcessEnv, cwd: string, pkgVersion: string | undefined): Release;
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAX_RELEASE_LENGTH = exports.CONTAINER_REVISION_VARS = exports.CI_COMMIT_VARS = void 0;
4
+ exports.normaliseRelease = normaliseRelease;
5
+ exports.findGitDir = findGitDir;
6
+ exports.readGitCommit = readGitCommit;
7
+ exports.inferRelease = inferRelease;
8
+ const fs = require("node:fs");
9
+ const path = require("node:path");
10
+ /** Commit SHAs exposed by CI systems and hosting platforms, most specific first. */
11
+ exports.CI_COMMIT_VARS = [
12
+ 'GIT_COMMIT_SHA', 'GIT_SHA', 'GIT_COMMIT',
13
+ 'GITHUB_SHA', // GitHub Actions
14
+ 'CI_COMMIT_SHA', // GitLab CI
15
+ 'VERCEL_GIT_COMMIT_SHA',
16
+ 'RENDER_GIT_COMMIT',
17
+ 'RAILWAY_GIT_COMMIT_SHA',
18
+ 'CF_PAGES_COMMIT_SHA',
19
+ 'COMMIT_REF', // Netlify
20
+ 'SOURCE_VERSION', 'HEROKU_SLUG_COMMIT', // Heroku
21
+ 'KOYEB_GIT_SHA',
22
+ 'BITBUCKET_COMMIT',
23
+ 'CIRCLE_SHA1',
24
+ 'BUILDKITE_COMMIT',
25
+ 'DRONE_COMMIT_SHA',
26
+ 'CODEBUILD_RESOLVED_SOURCE_VERSION', // AWS CodeBuild
27
+ ];
28
+ /** Revision names set by container platforms. */
29
+ exports.CONTAINER_REVISION_VARS = [
30
+ 'K_REVISION', // Cloud Run, Knative
31
+ 'CONTAINER_APP_REVISION', // Azure Container Apps
32
+ ];
33
+ exports.MAX_RELEASE_LENGTH = 50;
34
+ const FULL_SHA = /^[0-9a-f]{40}$/i;
35
+ /** Full commit SHAs are shortened to 12 characters; every value is capped at 50. */
36
+ function normaliseRelease(value) {
37
+ const v = value.trim();
38
+ return (FULL_SHA.test(v) ? v.slice(0, 12) : v).slice(0, exports.MAX_RELEASE_LENGTH);
39
+ }
40
+ function readFile(file) {
41
+ try {
42
+ return fs.readFileSync(file, 'utf8');
43
+ }
44
+ catch {
45
+ return null;
46
+ }
47
+ }
48
+ /** The git directory for `cwd` or its nearest ancestor: a `.git` folder, or a `.git` file (worktrees, submodules). */
49
+ function findGitDir(cwd) {
50
+ let dir = path.resolve(cwd);
51
+ for (;;) {
52
+ const dotGit = path.join(dir, '.git');
53
+ try {
54
+ const st = fs.statSync(dotGit);
55
+ if (st.isDirectory())
56
+ return dotGit;
57
+ if (st.isFile()) {
58
+ const m = /^gitdir:\s*(.+)$/m.exec(readFile(dotGit) || '');
59
+ if (m)
60
+ return path.resolve(dir, m[1].trim());
61
+ }
62
+ }
63
+ catch { /* keep walking up */ }
64
+ const parent = path.dirname(dir);
65
+ if (parent === dir)
66
+ return null;
67
+ dir = parent;
68
+ }
69
+ }
70
+ /** The checked-out commit, read straight from `.git` (no git binary needed). */
71
+ function readGitCommit(cwd) {
72
+ const gitDir = findGitDir(cwd);
73
+ if (!gitDir)
74
+ return null;
75
+ const head = readFile(path.join(gitDir, 'HEAD'))?.trim();
76
+ if (!head)
77
+ return null;
78
+ if (/^[0-9a-f]{40}$/i.test(head))
79
+ return { sha: head, gitDir }; // detached HEAD
80
+ const ref = /^ref:\s*(.+)$/.exec(head)?.[1].trim();
81
+ if (!ref)
82
+ return null;
83
+ // A worktree keeps shared refs in its common dir.
84
+ const common = readFile(path.join(gitDir, 'commondir'))?.trim();
85
+ const dirs = [gitDir, ...(common ? [path.resolve(gitDir, common)] : [])];
86
+ for (const d of dirs) {
87
+ const loose = readFile(path.join(d, ref))?.trim();
88
+ if (loose && /^[0-9a-f]{40}$/i.test(loose))
89
+ return { sha: loose, gitDir };
90
+ }
91
+ for (const d of dirs) {
92
+ const packed = readFile(path.join(d, 'packed-refs'));
93
+ if (!packed)
94
+ continue;
95
+ for (const line of packed.split('\n')) {
96
+ const [sha, name] = line.trim().split(/\s+/);
97
+ if (name === ref && /^[0-9a-f]{40}$/i.test(sha))
98
+ return { sha, gitDir };
99
+ }
100
+ }
101
+ return null;
102
+ }
103
+ /**
104
+ * Release identifier, from the first of:
105
+ * 1. `serviceVersion` passed to init (`false` reports none)
106
+ * 2. `OBZERVER_VERSION`
107
+ * 3. a commit exposed by CI or the hosting platform (`GITHUB_SHA`, `VERCEL_GIT_COMMIT_SHA`, …)
108
+ * 4. the commit checked out in `.git`
109
+ * 5. a container platform revision (`K_REVISION`, …)
110
+ * 6. `version` in package.json
111
+ */
112
+ function inferRelease(option, env, cwd, pkgVersion) {
113
+ if (option === false)
114
+ return { version: null, source: 'disabled' };
115
+ if (typeof option === 'string' && option.trim())
116
+ return { version: normaliseRelease(option), source: 'option' };
117
+ const fromEnv = (names) => {
118
+ for (const n of names) {
119
+ const v = env[n]?.trim();
120
+ if (v)
121
+ return { v, n };
122
+ }
123
+ return null;
124
+ };
125
+ const own = fromEnv(['OBZERVER_VERSION']);
126
+ if (own)
127
+ return { version: normaliseRelease(own.v), source: 'env', from: own.n };
128
+ const ci = fromEnv(exports.CI_COMMIT_VARS);
129
+ if (ci)
130
+ return { version: normaliseRelease(ci.v), source: 'ci', from: ci.n };
131
+ const git = readGitCommit(cwd);
132
+ if (git)
133
+ return { version: normaliseRelease(git.sha), source: 'git', from: git.gitDir };
134
+ const rev = fromEnv(exports.CONTAINER_REVISION_VARS);
135
+ if (rev)
136
+ return { version: normaliseRelease(rev.v), source: 'container', from: rev.n };
137
+ if (pkgVersion)
138
+ return { version: normaliseRelease(pkgVersion), source: 'package.json' };
139
+ return { version: null, source: 'none' };
140
+ }
141
+ //# sourceMappingURL=release.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"release.js","sourceRoot":"","sources":["../src/release.ts"],"names":[],"mappings":";;;AA2CA,4CAGC;AAOD,gCAgBC;AAGD,sCAwBC;AAWD,oCAiBC;AA5HD,8BAA8B;AAC9B,kCAAkC;AAYlC,oFAAoF;AACvE,QAAA,cAAc,GAAG;IAC5B,gBAAgB,EAAE,SAAS,EAAE,YAAY;IACzC,YAAY,EAAE,iBAAiB;IAC/B,eAAe,EAAE,YAAY;IAC7B,uBAAuB;IACvB,mBAAmB;IACnB,wBAAwB;IACxB,qBAAqB;IACrB,YAAY,EAAE,UAAU;IACxB,gBAAgB,EAAE,oBAAoB,EAAE,SAAS;IACjD,eAAe;IACf,kBAAkB;IAClB,aAAa;IACb,kB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AO,EAAE,OAAO,EAAE,gBAAgB,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;IACzF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,37 @@
1
+ import type { AgentHooks } from './agent-types';
2
+ /** Samples CPU, memory, event loop delay/utilisation and GC on an interval. */
3
+ export declare class RuntimeSampler {
4
+ private readonly agent;
5
+ private readonly hist;
6
+ private lastCpu;
7
+ private lastTime;
8
+ private lastElu;
9
+ private gc;
10
+ private readonly obs;
11
+ private readonly timer;
12
+ constructor(agent: AgentHooks, intervalMs?: number);
13
+ sample(): void;
14
+ stop(): void;
15
+ }
16
+ export interface Counter {
17
+ inc(value?: number): void;
18
+ }
19
+ export interface Gauge {
20
+ set(value: number): void;
21
+ }
22
+ export interface Summary {
23
+ observe(value: number): void;
24
+ }
25
+ /** Counters, gauges and summaries, aggregated in-process and flushed as deltas. */
26
+ export declare class Metrics {
27
+ private readonly agent;
28
+ private readonly series;
29
+ private readonly timer;
30
+ constructor(agent: AgentHooks, intervalMs?: number);
31
+ private get;
32
+ counter(name: string, labels?: Record<string, string>): Counter;
33
+ gauge(name: string, labels?: Record<string, string>): Gauge;
34
+ summary(name: string, labels?: Record<string, string>): Summary;
35
+ flush(): void;
36
+ stop(): void;
37
+ }
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Metrics = exports.RuntimeSampler = void 0;
4
+ const node_perf_hooks_1 = require("node:perf_hooks");
5
+ /** Samples CPU, memory, event loop delay/utilisation and GC on an interval. */
6
+ class RuntimeSampler {
7
+ agent;
8
+ hist;
9
+ lastCpu = process.cpuUsage();
10
+ lastTime = process.hrtime.bigint();
11
+ lastElu = node_perf_hooks_1.performance.eventLoopUtilization();
12
+ gc = { count: 0, ms: 0 };
13
+ obs;
14
+ timer;
15
+ constructor(agent, intervalMs = 15000) {
16
+ this.agent = agent;
17
+ this.hist = (0, node_perf_hooks_1.monitorEventLoopDelay)({ resolution: 10 });
18
+ this.hist.enable();
19
+ let obs = null;
20
+ try {
21
+ obs = new node_perf_hooks_1.PerformanceObserver((list) => {
22
+ for (const e of list.getEntries()) {
23
+ this.gc.count++;
24
+ this.gc.ms += e.duration;
25
+ }
26
+ });
27
+ obs.observe({ entryTypes: ['gc'] });
28
+ }
29
+ catch {
30
+ obs = null;
31
+ }
32
+ this.obs = obs;
33
+ this.timer = setInterval(() => this.sample(), Math.max(5000, intervalMs));
34
+ this.timer.unref();
35
+ }
36
+ sample() {
37
+ const now = process.hrtime.bigint();
38
+ const elapsedUs = Number(now - this.lastTime) / 1000;
39
+ const cpu = process.cpuUsage(this.lastCpu);
40
+ const elu = node_perf_hooks_1.performance.eventLoopUtilization(this.lastElu);
41
+ const mem = process.memoryUsage();
42
+ const ms = (v) => (Number.isFinite(v) ? v / 1e6 : 0);
43
+ this.agent.transport?.push('runtime', {
44
+ ts: Date.now(),
45
+ cpu: Math.min(6400, ((cpu.user + cpu.system) / Math.max(1, elapsedUs)) * 100),
46
+ rss: mem.rss,
47
+ heapUsed: mem.heapUsed,
48
+ heapTotal: mem.heapTotal,
49
+ external: mem.external,
50
+ elDelayP50: ms(this.hist.percentile(50)),
51
+ elDelayP99: ms(this.hist.percentile(99)),
52
+ elDelayMax: ms(this.hist.max),
53
+ elu: elu.utilization * 100,
54
+ gcCount: this.gc.count,
55
+ gcMs: this.gc.ms,
56
+ handles: typeof process.getActiveResourcesInfo === 'function' ? process.getActiveResourcesInfo().length : null,
57
+ inflight: this.agent.inflight,
58
+ });
59
+ this.hist.reset();
60
+ this.gc = { count: 0, ms: 0 };
61
+ this.lastCpu = process.cpuUsage();
62
+ this.lastTime = now;
63
+ this.lastElu = node_perf_hooks_1.performance.eventLoopUtilization();
64
+ }
65
+ stop() { clearInterval(this.timer); this.hist.disable(); this.obs?.disconnect(); }
66
+ }
67
+ exports.RuntimeSampler = RuntimeSampler;
68
+ /** Counters, gauges and summaries, aggregated in-process and flushed as deltas. */
69
+ class Metrics {
70
+ agent;
71
+ series = new Map();
72
+ timer;
73
+ constructor(agent, intervalMs = 10000) {
74
+ this.agent = agent;
75
+ this.timer = setInterval(() => this.flush(), Math.max(5000, intervalMs));
76
+ this.timer.unref();
77
+ }
78
+ get(type, name, labels) {
79
+ const k = `${name}|${labels ? JSON.stringify(Object.entries(labels).sort()) : ''}`;
80
+ let s = this.series.get(k);
81
+ if (!s) {
82
+ if (this.series.size > 5000)
83
+ return null;
84
+ s = { type, name, labels: labels || {}, value: 0, count: 0, sum: 0, min: Infinity, max: -Infinity, dirty: false };
85
+ this.series.set(k, s);
86
+ }
87
+ return s;
88
+ }
89
+ counter(name, labels) {
90
+ return { inc: (v = 1) => { const s = this.get('counter', name, labels); if (s) {
91
+ s.value += v;
92
+ s.count++;
93
+ s.dirty = true;
94
+ } } };
95
+ }
96
+ gauge(name, labels) {
97
+ return { set: (v) => { const s = this.get('gauge', name, labels); if (s) {
98
+ s.value = v;
99
+ s.dirty = true;
100
+ } } };
101
+ }
102
+ summary(name, labels) {
103
+ return {
104
+ observe: (v) => {
105
+ const s = this.get('summary', name, labels);
106
+ if (!s)
107
+ return;
108
+ s.count++;
109
+ s.sum += v;
110
+ s.min = Math.min(s.min, v);
111
+ s.max = Math.max(s.max, v);
112
+ s.value = v;
113
+ s.dirty = true;
114
+ },
115
+ };
116
+ }
117
+ flush() {
118
+ const ts = Date.now();
119
+ for (const s of this.series.values()) {
120
+ if (!s.dirty && s.type !== 'gauge')
121
+ continue;
122
+ this.agent.transport?.push('metrics', {
123
+ ts, name: s.name, type: s.type, labels: s.labels,
124
+ value: s.type === 'summary' ? (s.count ? s.sum / s.count : 0) : s.value,
125
+ count: s.count, sum: s.sum,
126
+ min: Number.isFinite(s.min) ? s.min : null,
127
+ max: Number.isFinite(s.max) ? s.max : null,
128
+ });
129
+ if (s.type !== 'gauge') {
130
+ s.value = 0;
131
+ s.count = 0;
132
+ s.sum = 0;
133
+ s.min = Infinity;
134
+ s.max = -Infinity;
135
+ }
136
+ s.dirty = false;
137
+ }
138
+ }
139
+ stop() { clearInterval(this.timer); this.flush(); }
140
+ }
141
+ exports.Metrics = Metrics;
142
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":";;;AAAA,qDAA6I;AAI7I,+EAA+E;AAC/E,MAAa,cAAc;IASI;IARZ,IAAI,CAAoB;IACjC,OAAO,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC7B,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IACnC,OAAO,GAAyB,6BAAW,CAAC,oBAAoB,EAAE,CAAC;IACnE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;IAChB,GAAG,CAA6B;IAChC,KAAK,CAAiB;IAEvC,YAA6B,KAAiB,EAAE,UAAU,GAAG,KAAK;QAArC,UAAK,GAAL,KAAK,CAAY;QAC5C,IAAI,CAAC,IAAI,GAAG,IAAA,uCAAqB,EAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;QACtD,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACnB,IAAI,GAAG,GAA+B,IAAI,CAAC;QAC3C,IAAI,CAAC;YACH,GAAG,GAAG,IAAI,qCAAmB,CAAC,CAAC,IAAI,EAAE,EAAE;gBACrC,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;oBAAC,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;oBAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC;gBAAC,CAAC;YACnF,CAAC,CAAC,CAAC;YACH,GAAG,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,C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CAAC,CAAC;gBAAC,CAAC,CAAC,GAAG,GAAG,QAAQ,CAAC;gBAAC,CAAC,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC;YAAC,CAAC;YACrG,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC;QAClB,CAAC;IACH,CAAC;IAED,IAAI,KAAW,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CAC1D;AAvDD,0BAuDC"}
@@ -0,0 +1,32 @@
1
+ import type { IngestPayload, QueueItems, QueueKind } from './protocol';
2
+ export interface TransportOptions {
3
+ endpoint: string;
4
+ appKey: string;
5
+ flushInterval?: number;
6
+ maxTracesPerBatch?: number;
7
+ maxQueue?: number;
8
+ }
9
+ export type Queues = {
10
+ [K in QueueKind]: QueueItems[K][];
11
+ };
12
+ export declare class Transport {
13
+ private readonly log;
14
+ readonly endpoint: string;
15
+ private readonly appKey;
16
+ private readonly maxTracesPerBatch;
17
+ private readonly maxQueue;
18
+ private readonly timer;
19
+ meta: Pick<IngestPayload, 'sdk' | 'service'> | null;
20
+ readonly q: Queues;
21
+ private dropped;
22
+ private sending;
23
+ private failures;
24
+ constructor(opts: TransportOptions, log: (msg: string) => void);
25
+ push<K extends QueueKind>(kind: K, item: QueueItems[K]): void;
26
+ size(): number;
27
+ private takeBatch;
28
+ private requeue;
29
+ flush(): Promise<void>;
30
+ private post;
31
+ close(): Promise<void>;
32
+ }