@tracewayapp/core 1.0.5 → 1.0.7
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/README.md +85 -11
- 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/README.md
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/tracewayapp/traceway/main/Traceway%20Logo%20White.png" />
|
|
4
|
+
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/tracewayapp/traceway/main/Traceway%20Logo.png" />
|
|
5
|
+
<img src="https://raw.githubusercontent.com/tracewayapp/traceway/main/Traceway%20Logo.png" alt="Traceway" width="200" />
|
|
6
|
+
</picture>
|
|
7
|
+
</p>
|
|
2
8
|
|
|
3
|
-
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.com/package/@tracewayapp/core"><img src="https://img.shields.io/npm/v/@tracewayapp/core.svg" alt="npm"></a>
|
|
11
|
+
<a href="https://github.com/tracewayapp/traceway-js/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License"></a>
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
# Traceway JS Core
|
|
15
|
+
|
|
16
|
+
Shared types and utilities consumed by every Traceway JavaScript SDK. Zero runtime dependencies, framework-agnostic, safe to import anywhere — browser, Node, React Native, Hermes, Cloudflare Workers.
|
|
17
|
+
|
|
18
|
+
[Traceway](https://tracewayapp.com) is a completely open-source error tracking platform. You can [self-host](https://docs.tracewayapp.com/server) it or use [Traceway Cloud](https://tracewayapp.com).
|
|
19
|
+
|
|
20
|
+
> **You probably don't need to install this directly.** It's a transitive dependency of `@tracewayapp/frontend`, `@tracewayapp/react-native`, and the framework wrappers. Install one of those instead. Reach for `@tracewayapp/core` directly only if you're building your own SDK or rendering Traceway's wire types in a dashboard.
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
- Type definitions for the full Traceway wire format — exceptions, metrics, traces, spans, session recordings
|
|
25
|
+
- Discriminated union for the timeline event types (logs, network, navigation, custom breadcrumbs)
|
|
26
|
+
- A bounded rolling `EventBuffer<T>` keyed by time window + max size, used by every higher-level SDK to capture the last ~10 seconds of activity
|
|
27
|
+
- Connection-string parser, UUID v4 generator, ISO-8601 timestamp helper
|
|
28
|
+
- Constants for built-in metric names (`mem.used`, `cpu.used_pcnt`, etc.)
|
|
29
|
+
- Pure ESM + CJS dual output, full TypeScript declarations
|
|
4
30
|
|
|
5
31
|
## Installation
|
|
6
32
|
|
|
@@ -8,30 +34,57 @@ Shared types and utilities for all Traceway JavaScript SDKs. Zero runtime depend
|
|
|
8
34
|
npm install @tracewayapp/core
|
|
9
35
|
```
|
|
10
36
|
|
|
11
|
-
##
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import {
|
|
41
|
+
parseConnectionString,
|
|
42
|
+
generateUUID,
|
|
43
|
+
nowISO,
|
|
44
|
+
EventBuffer,
|
|
45
|
+
type LogEvent,
|
|
46
|
+
type ReportRequest,
|
|
47
|
+
} from "@tracewayapp/core";
|
|
48
|
+
|
|
49
|
+
const { token, apiUrl } = parseConnectionString(
|
|
50
|
+
"your-token@https://traceway.example.com/api/report",
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
// Rolling buffer that drops entries older than 10s OR beyond 200 entries:
|
|
54
|
+
const logs = new EventBuffer<LogEvent>({ windowMs: 10_000, maxSize: 200 });
|
|
55
|
+
logs.add({
|
|
56
|
+
type: "log",
|
|
57
|
+
timestamp: nowISO(),
|
|
58
|
+
level: "info",
|
|
59
|
+
message: "user reached checkout",
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const recent: LogEvent[] = logs.snapshot();
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Wire Types
|
|
12
66
|
|
|
13
67
|
### Reporting
|
|
14
68
|
|
|
15
69
|
| Type | Description |
|
|
16
70
|
|------|-------------|
|
|
17
|
-
| `ExceptionStackTrace` |
|
|
71
|
+
| `ExceptionStackTrace` | Single exception/message record |
|
|
18
72
|
| `MetricRecord` | Metric data point (`name`, `value`, `recordedAt`, optional `tags`) |
|
|
19
73
|
| `Span` | Sub-operation span within a trace |
|
|
20
74
|
| `Trace` | Endpoint or task trace |
|
|
21
75
|
| `CollectionFrame` | Batch of stack traces, metrics, traces, and session recordings |
|
|
22
76
|
| `ReportRequest` | Top-level request payload sent to `/api/report` |
|
|
23
|
-
| `TracewayOptions` | Configuration options for SDK initialization |
|
|
24
77
|
|
|
25
|
-
###
|
|
78
|
+
### Timeline (logs, actions, recordings)
|
|
26
79
|
|
|
27
|
-
The
|
|
80
|
+
The browser, RN, and framework SDKs ship a rolling timeline of logs and action breadcrumbs alongside each captured exception. The wire types are defined here so dashboards and custom SDKs can share them.
|
|
28
81
|
|
|
29
82
|
| Type | Description |
|
|
30
83
|
|------|-------------|
|
|
31
84
|
| `TracewayEventBase` | Discriminator (`type`) + `timestamp` shared by all timeline events |
|
|
32
|
-
| `LogEvent` | Console log
|
|
85
|
+
| `LogEvent` | Console log: `level` (`debug` / `info` / `warn` / `error`) + `message` |
|
|
33
86
|
| `NetworkEvent` | `fetch` / `XHR` request: `method`, `url`, `durationMs`, optional `statusCode`, byte counts, `error` |
|
|
34
|
-
| `NavigationEvent` | History API transition: `action` (`push` / `replace` / `pop`), `from`, `to` |
|
|
87
|
+
| `NavigationEvent` | History API or manual navigation transition: `action` (`push` / `replace` / `pop`), `from`, `to` |
|
|
35
88
|
| `CustomEvent` | User-defined breadcrumb from `recordAction(category, name, data?)` |
|
|
36
89
|
| `TracewayEvent` | Discriminated union of the four event types above |
|
|
37
90
|
| `SessionRecordingPayload` | Replay frames + buffered `logs` + `actions` + `startedAt` / `endedAt` anchors, attached to an exception via `exceptionId` |
|
|
@@ -40,11 +93,11 @@ The frontend SDK ships a rolling timeline of logs and action breadcrumbs alongsi
|
|
|
40
93
|
|
|
41
94
|
| Function | Description |
|
|
42
95
|
|----------|-------------|
|
|
96
|
+
| `parseConnectionString(str)` | Split `{token}@{apiUrl}` into `{ token, apiUrl }`; throws on malformed input |
|
|
43
97
|
| `generateUUID()` | Generate a UUID v4 string |
|
|
44
|
-
| `parseConnectionString(str)` | Split `{token}@{apiUrl}` into `{ token, apiUrl }` |
|
|
45
98
|
| `nowISO()` | Current time as ISO 8601 string |
|
|
46
99
|
| `msToNanoseconds(ms)` | Convert milliseconds to nanoseconds (integer) |
|
|
47
|
-
| `EventBuffer<T>` | Bounded rolling buffer (`windowMs`, `maxSize`) used by the
|
|
100
|
+
| `EventBuffer<T>` | Bounded rolling buffer (`windowMs`, `maxSize`) used by the higher-level SDKs to keep the most recent logs and actions |
|
|
48
101
|
|
|
49
102
|
## Constants
|
|
50
103
|
|
|
@@ -53,3 +106,24 @@ The frontend SDK ships a rolling timeline of logs and action breadcrumbs alongsi
|
|
|
53
106
|
| `METRIC_MEM_USED` | `"mem.used"` |
|
|
54
107
|
| `METRIC_MEM_TOTAL` | `"mem.total"` |
|
|
55
108
|
| `METRIC_CPU_USED_PCNT` | `"cpu.used_pcnt"` |
|
|
109
|
+
|
|
110
|
+
## Platform Support
|
|
111
|
+
|
|
112
|
+
| Environment | Status |
|
|
113
|
+
|---|---|
|
|
114
|
+
| Browser (any modern engine) | Yes |
|
|
115
|
+
| Node.js ≥ 18 | Yes |
|
|
116
|
+
| React Native (Hermes / JSC) | Yes |
|
|
117
|
+
| Cloudflare Workers / Deno / Bun | Yes |
|
|
118
|
+
|
|
119
|
+
## Links
|
|
120
|
+
|
|
121
|
+
- [Traceway Website](https://tracewayapp.com)
|
|
122
|
+
- [Traceway GitHub](https://github.com/tracewayapp/traceway)
|
|
123
|
+
- [Documentation](https://docs.tracewayapp.com)
|
|
124
|
+
- [Browser SDK](https://www.npmjs.com/package/@tracewayapp/frontend)
|
|
125
|
+
- [React Native SDK](https://www.npmjs.com/package/@tracewayapp/react-native)
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
MIT
|
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":[]}
|