@tracewayapp/core 1.0.6 → 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.mts +32 -2
- package/dist/index.d.ts +32 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -6,6 +6,13 @@ interface ExceptionStackTrace {
|
|
|
6
6
|
attributes?: Record<string, string>;
|
|
7
7
|
isMessage: boolean;
|
|
8
8
|
sessionRecordingId?: string | null;
|
|
9
|
+
/**
|
|
10
|
+
* Persistent session UUID set by the SDK when `recordAllSessions: true`. Lets
|
|
11
|
+
* the backend link the exception to the parent `sessions` row and to all
|
|
12
|
+
* segments under that session — independent of the legacy
|
|
13
|
+
* `sessionRecordingId` (which is per-exception).
|
|
14
|
+
*/
|
|
15
|
+
sessionId?: string | null;
|
|
9
16
|
distributedTraceId?: string | null;
|
|
10
17
|
}
|
|
11
18
|
interface MetricRecord {
|
|
@@ -38,9 +45,32 @@ interface CollectionFrame {
|
|
|
38
45
|
metrics: MetricRecord[];
|
|
39
46
|
traces: Trace[];
|
|
40
47
|
sessionRecordings?: SessionRecordingPayload[];
|
|
48
|
+
/**
|
|
49
|
+
* Sessions started or ended in this frame. The backend upserts by id, so
|
|
50
|
+
* sending the same session twice (initial open with endedAt unset, final
|
|
51
|
+
* close with endedAt populated) is the intended pattern.
|
|
52
|
+
*/
|
|
53
|
+
sessions?: SessionPayload[];
|
|
54
|
+
}
|
|
55
|
+
interface SessionPayload {
|
|
56
|
+
/** SDK-generated session UUID; persistent for the page lifecycle. */
|
|
57
|
+
id: string;
|
|
58
|
+
startedAt: string;
|
|
59
|
+
endedAt?: string;
|
|
60
|
+
clientIP?: string;
|
|
61
|
+
attributes?: Record<string, string>;
|
|
62
|
+
distributedTraceId?: string;
|
|
41
63
|
}
|
|
42
64
|
interface SessionRecordingPayload {
|
|
43
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Per-exception ID. Empty/unset for always-on segments that are not tied
|
|
67
|
+
* to a specific exception.
|
|
68
|
+
*/
|
|
69
|
+
exceptionId?: string;
|
|
70
|
+
/** Parent session UUID — set when always-on session recording is active. */
|
|
71
|
+
sessionId?: string;
|
|
72
|
+
/** Monotonically increasing per-session segment counter starting at 0. */
|
|
73
|
+
segmentIndex?: number;
|
|
44
74
|
/** Replay frames (rrweb events on the web, MP4 chunks on native). */
|
|
45
75
|
events: unknown[];
|
|
46
76
|
/**
|
|
@@ -146,4 +176,4 @@ declare class EventBuffer<T extends TracewayEventBase> {
|
|
|
146
176
|
private prune;
|
|
147
177
|
}
|
|
148
178
|
|
|
149
|
-
export { type CollectionFrame, type CustomEvent, EventBuffer, type EventBufferOptions, type ExceptionStackTrace, type LogEvent, METRIC_CPU_USED_PCNT, METRIC_MEM_TOTAL, METRIC_MEM_USED, type MetricRecord, type NavigationEvent, type NetworkEvent, type ParsedConnectionString, type ReportRequest, type SessionRecordingPayload, type Span, type Trace, type TracewayEvent, type TracewayEventBase, type TracewayOptions, generateUUID, msToNanoseconds, nowISO, parseConnectionString };
|
|
179
|
+
export { type CollectionFrame, type CustomEvent, EventBuffer, type EventBufferOptions, type ExceptionStackTrace, type LogEvent, METRIC_CPU_USED_PCNT, METRIC_MEM_TOTAL, METRIC_MEM_USED, type MetricRecord, type NavigationEvent, type NetworkEvent, type ParsedConnectionString, type ReportRequest, type SessionPayload, type SessionRecordingPayload, type Span, type Trace, type TracewayEvent, type TracewayEventBase, type TracewayOptions, generateUUID, msToNanoseconds, nowISO, parseConnectionString };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,13 @@ interface ExceptionStackTrace {
|
|
|
6
6
|
attributes?: Record<string, string>;
|
|
7
7
|
isMessage: boolean;
|
|
8
8
|
sessionRecordingId?: string | null;
|
|
9
|
+
/**
|
|
10
|
+
* Persistent session UUID set by the SDK when `recordAllSessions: true`. Lets
|
|
11
|
+
* the backend link the exception to the parent `sessions` row and to all
|
|
12
|
+
* segments under that session — independent of the legacy
|
|
13
|
+
* `sessionRecordingId` (which is per-exception).
|
|
14
|
+
*/
|
|
15
|
+
sessionId?: string | null;
|
|
9
16
|
distributedTraceId?: string | null;
|
|
10
17
|
}
|
|
11
18
|
interface MetricRecord {
|
|
@@ -38,9 +45,32 @@ interface CollectionFrame {
|
|
|
38
45
|
metrics: MetricRecord[];
|
|
39
46
|
traces: Trace[];
|
|
40
47
|
sessionRecordings?: SessionRecordingPayload[];
|
|
48
|
+
/**
|
|
49
|
+
* Sessions started or ended in this frame. The backend upserts by id, so
|
|
50
|
+
* sending the same session twice (initial open with endedAt unset, final
|
|
51
|
+
* close with endedAt populated) is the intended pattern.
|
|
52
|
+
*/
|
|
53
|
+
sessions?: SessionPayload[];
|
|
54
|
+
}
|
|
55
|
+
interface SessionPayload {
|
|
56
|
+
/** SDK-generated session UUID; persistent for the page lifecycle. */
|
|
57
|
+
id: string;
|
|
58
|
+
startedAt: string;
|
|
59
|
+
endedAt?: string;
|
|
60
|
+
clientIP?: string;
|
|
61
|
+
attributes?: Record<string, string>;
|
|
62
|
+
distributedTraceId?: string;
|
|
41
63
|
}
|
|
42
64
|
interface SessionRecordingPayload {
|
|
43
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Per-exception ID. Empty/unset for always-on segments that are not tied
|
|
67
|
+
* to a specific exception.
|
|
68
|
+
*/
|
|
69
|
+
exceptionId?: string;
|
|
70
|
+
/** Parent session UUID — set when always-on session recording is active. */
|
|
71
|
+
sessionId?: string;
|
|
72
|
+
/** Monotonically increasing per-session segment counter starting at 0. */
|
|
73
|
+
segmentIndex?: number;
|
|
44
74
|
/** Replay frames (rrweb events on the web, MP4 chunks on native). */
|
|
45
75
|
events: unknown[];
|
|
46
76
|
/**
|
|
@@ -146,4 +176,4 @@ declare class EventBuffer<T extends TracewayEventBase> {
|
|
|
146
176
|
private prune;
|
|
147
177
|
}
|
|
148
178
|
|
|
149
|
-
export { type CollectionFrame, type CustomEvent, EventBuffer, type EventBufferOptions, type ExceptionStackTrace, type LogEvent, METRIC_CPU_USED_PCNT, METRIC_MEM_TOTAL, METRIC_MEM_USED, type MetricRecord, type NavigationEvent, type NetworkEvent, type ParsedConnectionString, type ReportRequest, type SessionRecordingPayload, type Span, type Trace, type TracewayEvent, type TracewayEventBase, type TracewayOptions, generateUUID, msToNanoseconds, nowISO, parseConnectionString };
|
|
179
|
+
export { type CollectionFrame, type CustomEvent, EventBuffer, type EventBufferOptions, type ExceptionStackTrace, type LogEvent, METRIC_CPU_USED_PCNT, METRIC_MEM_TOTAL, METRIC_MEM_USED, type MetricRecord, type NavigationEvent, type NetworkEvent, type ParsedConnectionString, type ReportRequest, type SessionPayload, type SessionRecordingPayload, type Span, type Trace, type TracewayEvent, type TracewayEventBase, type TracewayOptions, generateUUID, msToNanoseconds, nowISO, parseConnectionString };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/utils.ts","../src/constants.ts","../src/event-buffer.ts"],"sourcesContent":["export type {\n ExceptionStackTrace,\n MetricRecord,\n Span,\n Trace,\n CollectionFrame,\n SessionRecordingPayload,\n ReportRequest,\n TracewayOptions,\n TracewayEvent,\n TracewayEventBase,\n LogEvent,\n NetworkEvent,\n NavigationEvent,\n CustomEvent,\n} from \"./types.js\";\n\nexport {\n generateUUID,\n parseConnectionString,\n nowISO,\n msToNanoseconds,\n} from \"./utils.js\";\nexport type { ParsedConnectionString } from \"./utils.js\";\n\nexport {\n METRIC_MEM_USED,\n METRIC_MEM_TOTAL,\n METRIC_CPU_USED_PCNT,\n} from \"./constants.js\";\n\nexport { EventBuffer } from \"./event-buffer.js\";\nexport type { EventBufferOptions } from \"./event-buffer.js\";\n","export function generateUUID(): string {\n if (\n typeof crypto !== \"undefined\" &&\n typeof crypto.randomUUID === \"function\"\n ) {\n return crypto.randomUUID();\n }\n return \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\".replace(/[xy]/g, (c) => {\n const r = (Math.random() * 16) | 0;\n const v = c === \"x\" ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n}\n\nexport interface ParsedConnectionString {\n token: string;\n apiUrl: string;\n}\n\nexport function parseConnectionString(\n connectionString: string,\n): ParsedConnectionString {\n const atIndex = connectionString.indexOf(\"@\");\n if (atIndex === -1) {\n throw new Error(\n \"Invalid connection string: must be in format {token}@{apiUrl}\",\n );\n }\n const token = connectionString.slice(0, atIndex);\n const apiUrl = connectionString.slice(atIndex + 1);\n if (!token || !apiUrl) {\n throw new Error(\n \"Invalid connection string: token and apiUrl must not be empty\",\n );\n }\n return { token, apiUrl };\n}\n\nexport function nowISO(): string {\n return new Date().toISOString();\n}\n\nexport function msToNanoseconds(ms: number): number {\n return Math.round(ms * 1_000_000);\n}\n","export const METRIC_MEM_USED = \"mem.used\";\nexport const METRIC_MEM_TOTAL = \"mem.total\";\nexport const METRIC_CPU_USED_PCNT = \"cpu.used_pcnt\";\n","import type { TracewayEventBase } from \"./types.js\";\n\nexport interface EventBufferOptions {\n /** Window kept relative to `now`. Older entries are pruned. Default 10_000ms. */\n windowMs?: number;\n /** Hard cap on entries kept regardless of window. Default 200. */\n maxSize?: number;\n}\n\n/**\n * Time-windowed FIFO buffer with a hard size cap.\n *\n * Drops entries older than `windowMs` and keeps at most `maxSize` entries.\n * Pruning runs on every `add` and `snapshot` so the buffer is self-maintaining\n * without a background timer. Mirrors the Flutter SDK's EventBuffer.\n */\nexport class EventBuffer<T extends TracewayEventBase> {\n readonly windowMs: number;\n readonly maxSize: number;\n private q: T[] = [];\n\n constructor(options: EventBufferOptions = {}) {\n this.windowMs = options.windowMs ?? 10_000;\n this.maxSize = options.maxSize ?? 200;\n }\n\n add(event: T): void {\n this.q.push(event);\n this.prune();\n }\n\n /** Returns events ordered oldest -> newest. */\n snapshot(): T[] {\n this.prune();\n return this.q.slice();\n }\n\n clear(): void {\n this.q.length = 0;\n }\n\n get length(): number {\n return this.q.length;\n }\n\n private prune(): void {\n const cutoff = Date.now() - this.windowMs;\n while (this.q.length > 0 && Date.parse(this.q[0]!.timestamp) < cutoff) {\n this.q.shift();\n }\n while (this.q.length > this.maxSize) {\n this.q.shift();\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,SAAS,eAAuB;AACrC,MACE,OAAO,WAAW,eAClB,OAAO,OAAO,eAAe,YAC7B;AACA,WAAO,OAAO,WAAW;AAAA,EAC3B;AACA,SAAO,uCAAuC,QAAQ,SAAS,CAAC,MAAM;AACpE,UAAM,IAAK,KAAK,OAAO,IAAI,KAAM;AACjC,UAAM,IAAI,MAAM,MAAM,IAAK,IAAI,IAAO;AACtC,WAAO,EAAE,SAAS,EAAE;AAAA,EACtB,CAAC;AACH;AAOO,SAAS,sBACd,kBACwB;AACxB,QAAM,UAAU,iBAAiB,QAAQ,GAAG;AAC5C,MAAI,YAAY,IAAI;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,QAAM,QAAQ,iBAAiB,MAAM,GAAG,OAAO;AAC/C,QAAM,SAAS,iBAAiB,MAAM,UAAU,CAAC;AACjD,MAAI,CAAC,SAAS,CAAC,QAAQ;AACrB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO,EAAE,OAAO,OAAO;AACzB;AAEO,SAAS,SAAiB;AAC/B,UAAO,oBAAI,KAAK,GAAE,YAAY;AAChC;AAEO,SAAS,gBAAgB,IAAoB;AAClD,SAAO,KAAK,MAAM,KAAK,GAAS;AAClC;;;AC5CO,IAAM,kBAAkB;AACxB,IAAM,mBAAmB;AACzB,IAAM,uBAAuB;;;ACc7B,IAAM,cAAN,MAA+C;AAAA,EAC3C;AAAA,EACA;AAAA,EACD,IAAS,CAAC;AAAA,EAElB,YAAY,UAA8B,CAAC,GAAG;AAC5C,SAAK,WAAW,QAAQ,YAAY;AACpC,SAAK,UAAU,QAAQ,WAAW;AAAA,EACpC;AAAA,EAEA,IAAI,OAAgB;AAClB,SAAK,EAAE,KAAK,KAAK;AACjB,SAAK,MAAM;AAAA,EACb;AAAA;AAAA,EAGA,WAAgB;AACd,SAAK,MAAM;AACX,WAAO,KAAK,EAAE,MAAM;AAAA,EACtB;AAAA,EAEA,QAAc;AACZ,SAAK,EAAE,SAAS;AAAA,EAClB;AAAA,EAEA,IAAI,SAAiB;AACnB,WAAO,KAAK,EAAE;AAAA,EAChB;AAAA,EAEQ,QAAc;AACpB,UAAM,SAAS,KAAK,IAAI,IAAI,KAAK;AACjC,WAAO,KAAK,EAAE,SAAS,KAAK,KAAK,MAAM,KAAK,EAAE,CAAC,EAAG,SAAS,IAAI,QAAQ;AACrE,WAAK,EAAE,MAAM;AAAA,IACf;AACA,WAAO,KAAK,EAAE,SAAS,KAAK,SAAS;AACnC,WAAK,EAAE,MAAM;AAAA,IACf;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/utils.ts","../src/constants.ts","../src/event-buffer.ts"],"sourcesContent":["export type {\n ExceptionStackTrace,\n MetricRecord,\n Span,\n Trace,\n CollectionFrame,\n SessionPayload,\n SessionRecordingPayload,\n ReportRequest,\n TracewayOptions,\n TracewayEvent,\n TracewayEventBase,\n LogEvent,\n NetworkEvent,\n NavigationEvent,\n CustomEvent,\n} from \"./types.js\";\n\nexport {\n generateUUID,\n parseConnectionString,\n nowISO,\n msToNanoseconds,\n} from \"./utils.js\";\nexport type { ParsedConnectionString } from \"./utils.js\";\n\nexport {\n METRIC_MEM_USED,\n METRIC_MEM_TOTAL,\n METRIC_CPU_USED_PCNT,\n} from \"./constants.js\";\n\nexport { EventBuffer } from \"./event-buffer.js\";\nexport type { EventBufferOptions } from \"./event-buffer.js\";\n","export function generateUUID(): string {\n if (\n typeof crypto !== \"undefined\" &&\n typeof crypto.randomUUID === \"function\"\n ) {\n return crypto.randomUUID();\n }\n return \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\".replace(/[xy]/g, (c) => {\n const r = (Math.random() * 16) | 0;\n const v = c === \"x\" ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n}\n\nexport interface ParsedConnectionString {\n token: string;\n apiUrl: string;\n}\n\nexport function parseConnectionString(\n connectionString: string,\n): ParsedConnectionString {\n const atIndex = connectionString.indexOf(\"@\");\n if (atIndex === -1) {\n throw new Error(\n \"Invalid connection string: must be in format {token}@{apiUrl}\",\n );\n }\n const token = connectionString.slice(0, atIndex);\n const apiUrl = connectionString.slice(atIndex + 1);\n if (!token || !apiUrl) {\n throw new Error(\n \"Invalid connection string: token and apiUrl must not be empty\",\n );\n }\n return { token, apiUrl };\n}\n\nexport function nowISO(): string {\n return new Date().toISOString();\n}\n\nexport function msToNanoseconds(ms: number): number {\n return Math.round(ms * 1_000_000);\n}\n","export const METRIC_MEM_USED = \"mem.used\";\nexport const METRIC_MEM_TOTAL = \"mem.total\";\nexport const METRIC_CPU_USED_PCNT = \"cpu.used_pcnt\";\n","import type { TracewayEventBase } from \"./types.js\";\n\nexport interface EventBufferOptions {\n /** Window kept relative to `now`. Older entries are pruned. Default 10_000ms. */\n windowMs?: number;\n /** Hard cap on entries kept regardless of window. Default 200. */\n maxSize?: number;\n}\n\n/**\n * Time-windowed FIFO buffer with a hard size cap.\n *\n * Drops entries older than `windowMs` and keeps at most `maxSize` entries.\n * Pruning runs on every `add` and `snapshot` so the buffer is self-maintaining\n * without a background timer. Mirrors the Flutter SDK's EventBuffer.\n */\nexport class EventBuffer<T extends TracewayEventBase> {\n readonly windowMs: number;\n readonly maxSize: number;\n private q: T[] = [];\n\n constructor(options: EventBufferOptions = {}) {\n this.windowMs = options.windowMs ?? 10_000;\n this.maxSize = options.maxSize ?? 200;\n }\n\n add(event: T): void {\n this.q.push(event);\n this.prune();\n }\n\n /** Returns events ordered oldest -> newest. */\n snapshot(): T[] {\n this.prune();\n return this.q.slice();\n }\n\n clear(): void {\n this.q.length = 0;\n }\n\n get length(): number {\n return this.q.length;\n }\n\n private prune(): void {\n const cutoff = Date.now() - this.windowMs;\n while (this.q.length > 0 && Date.parse(this.q[0]!.timestamp) < cutoff) {\n this.q.shift();\n }\n while (this.q.length > this.maxSize) {\n this.q.shift();\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,SAAS,eAAuB;AACrC,MACE,OAAO,WAAW,eAClB,OAAO,OAAO,eAAe,YAC7B;AACA,WAAO,OAAO,WAAW;AAAA,EAC3B;AACA,SAAO,uCAAuC,QAAQ,SAAS,CAAC,MAAM;AACpE,UAAM,IAAK,KAAK,OAAO,IAAI,KAAM;AACjC,UAAM,IAAI,MAAM,MAAM,IAAK,IAAI,IAAO;AACtC,WAAO,EAAE,SAAS,EAAE;AAAA,EACtB,CAAC;AACH;AAOO,SAAS,sBACd,kBACwB;AACxB,QAAM,UAAU,iBAAiB,QAAQ,GAAG;AAC5C,MAAI,YAAY,IAAI;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,QAAM,QAAQ,iBAAiB,MAAM,GAAG,OAAO;AAC/C,QAAM,SAAS,iBAAiB,MAAM,UAAU,CAAC;AACjD,MAAI,CAAC,SAAS,CAAC,QAAQ;AACrB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO,EAAE,OAAO,OAAO;AACzB;AAEO,SAAS,SAAiB;AAC/B,UAAO,oBAAI,KAAK,GAAE,YAAY;AAChC;AAEO,SAAS,gBAAgB,IAAoB;AAClD,SAAO,KAAK,MAAM,KAAK,GAAS;AAClC;;;AC5CO,IAAM,kBAAkB;AACxB,IAAM,mBAAmB;AACzB,IAAM,uBAAuB;;;ACc7B,IAAM,cAAN,MAA+C;AAAA,EAC3C;AAAA,EACA;AAAA,EACD,IAAS,CAAC;AAAA,EAElB,YAAY,UAA8B,CAAC,GAAG;AAC5C,SAAK,WAAW,QAAQ,YAAY;AACpC,SAAK,UAAU,QAAQ,WAAW;AAAA,EACpC;AAAA,EAEA,IAAI,OAAgB;AAClB,SAAK,EAAE,KAAK,KAAK;AACjB,SAAK,MAAM;AAAA,EACb;AAAA;AAAA,EAGA,WAAgB;AACd,SAAK,MAAM;AACX,WAAO,KAAK,EAAE,MAAM;AAAA,EACtB;AAAA,EAEA,QAAc;AACZ,SAAK,EAAE,SAAS;AAAA,EAClB;AAAA,EAEA,IAAI,SAAiB;AACnB,WAAO,KAAK,EAAE;AAAA,EAChB;AAAA,EAEQ,QAAc;AACpB,UAAM,SAAS,KAAK,IAAI,IAAI,KAAK;AACjC,WAAO,KAAK,EAAE,SAAS,KAAK,KAAK,MAAM,KAAK,EAAE,CAAC,EAAG,SAAS,IAAI,QAAQ;AACrE,WAAK,EAAE,MAAM;AAAA,IACf;AACA,WAAO,KAAK,EAAE,SAAS,KAAK,SAAS;AACnC,WAAK,EAAE,MAAM;AAAA,IACf;AAAA,EACF;AACF;","names":[]}
|