@nexussdk/tracker 0.0.3 → 0.0.4
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 +147 -8
- package/dist/dev-server/cli.mjs +1027 -0
- package/dist/index.cjs +2 -2
- package/dist/index.d.mts +227 -20
- package/dist/index.d.ts +227 -20
- package/dist/index.global.js +3 -3
- package/dist/index.mjs +2 -2
- package/package.json +30 -6
package/README.md
CHANGED
|
@@ -1,28 +1,167 @@
|
|
|
1
1
|
# @nexussdk/tracker
|
|
2
2
|
|
|
3
|
-
Ultra-resilient client crash ingestion and telemetry SDK with automated PII sanitization (<
|
|
3
|
+
> Ultra-resilient, production-grade client crash ingestion and telemetry SDK with automated PII sanitization, Core Web Vitals, and pluggable transports (< 5KB gzipped).
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@nexussdk/tracker)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://bundlephobia.com)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Key Features
|
|
12
|
+
|
|
13
|
+
- **Automated PII Scrubbing**: Recursive sanitization of emails, JWT tokens, credit card numbers, passwords, and authorization headers before transmission.
|
|
14
|
+
- **Deterministic Fingerprinting**: Parses stack traces across V8, SpiderMonkey, and JSCore to generate consistent, deterministic error group hashes without async crypto overhead.
|
|
15
|
+
- **Client-Side Deduplication & Sampling**: Sliding window deduplication prevents telemetry storms during rapid loops. Configurable sampling rate and session crash limits.
|
|
16
|
+
- **Pluggable Transports**: Supports `fetch` (with keepalive and `navigator.sendBeacon` fallback during page unloads), `console` logging, `localStorage` offline buffers, or custom callback functions.
|
|
17
|
+
- **Zero-Dependency Web Vitals**: Observes LCP, CLS, FID, TTFB, INP, FCP, and long tasks (>50ms) using the browser's native `PerformanceObserver` API.
|
|
18
|
+
- **Framework-Agnostic Error Boundary Core**: `NexusGuardCore` provides crash isolation and recovery logic for any JavaScript runtime.
|
|
19
|
+
- **Built-in Local Ingestion Server**: `nexus-dev` CLI offers an instant local HTTP ingestion server with real-time SSE Web GUI for offline development.
|
|
7
20
|
|
|
8
21
|
---
|
|
9
22
|
|
|
10
23
|
## Installation
|
|
11
24
|
|
|
12
25
|
```bash
|
|
13
|
-
npm install @nexussdk/tracker
|
|
14
|
-
# or
|
|
15
26
|
pnpm add @nexussdk/tracker
|
|
27
|
+
# or
|
|
28
|
+
npm install @nexussdk/tracker
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
*(If using React or Vue, install `@nexussdk/sdk` instead for built-in hooks and components).*
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Quickstart (Vanilla JS / TypeScript)
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { NexusTrackerClient, attachWebVitals, NexusGuardCore } from '@nexussdk/tracker';
|
|
39
|
+
|
|
40
|
+
// 1. Initialize client
|
|
41
|
+
const tracker = new NexusTrackerClient({
|
|
42
|
+
apiKey: 'pk_live_your_api_key',
|
|
43
|
+
environment: 'production',
|
|
44
|
+
sampling: {
|
|
45
|
+
rate: 1.0, // 100% sampling
|
|
46
|
+
dedupeWindow: 10000, // 10s deduplication window
|
|
47
|
+
maxPerSession: 50, // Crash-loop defense: cap at 50 errors per session
|
|
48
|
+
},
|
|
49
|
+
transport: 'fetch',
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// 2. Attach Web Vitals observer
|
|
53
|
+
const detachVitals = attachWebVitals(tracker, {
|
|
54
|
+
poorRatingOnly: true,
|
|
55
|
+
captureAsEvents: false, // captured as breadcrumbs
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// 3. Capture errors manually
|
|
59
|
+
try {
|
|
60
|
+
executePayment();
|
|
61
|
+
} catch (err) {
|
|
62
|
+
tracker.captureError(err, { orderId: 'ord_123' });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 4. Capture informational/warning messages
|
|
66
|
+
tracker.captureMessage('High memory usage detected', 'warning', { heapMb: 420 });
|
|
67
|
+
|
|
68
|
+
// 5. Add custom breadcrumbs
|
|
69
|
+
tracker.addBreadcrumb({
|
|
70
|
+
category: 'ui.click',
|
|
71
|
+
message: 'User clicked checkout button',
|
|
72
|
+
level: 'info',
|
|
73
|
+
});
|
|
16
74
|
```
|
|
17
75
|
|
|
18
76
|
---
|
|
19
77
|
|
|
20
|
-
##
|
|
78
|
+
## Configuration Options (`NexusTrackerOptions`)
|
|
79
|
+
|
|
80
|
+
| Option | Type | Default | Description |
|
|
81
|
+
| :--- | :--- | :--- | :--- |
|
|
82
|
+
| `apiKey` | `string` | Env | Public API key (`pk_live_...`) |
|
|
83
|
+
| `baseUrl` | `string` | Env | Ingestion endpoint URL (e.g. `https://telemetry.example.com`) |
|
|
84
|
+
| `environment` | `string` | `'production'` | Target environment name |
|
|
85
|
+
| `autoCapture` | `boolean` | `true` | Binds global `window.onerror` and `unhandledrejection` handlers |
|
|
86
|
+
| `tags` | `Record<string, string>` | `{}` | Global static tags attached to every captured event |
|
|
87
|
+
| `extra` | `Record<string, unknown>` | `{}` | Additional structured context attached to all events |
|
|
88
|
+
| `sampling` | `SamplingConfig` | Default | Rate limiting and deduplication parameters |
|
|
89
|
+
| `transport` | `TransportPlugin` | `'fetch'` | Delivery dispatcher: `'fetch'`, `'console'`, `'localStorage'`, or custom fn |
|
|
90
|
+
| `maxBreadcrumbs` | `number` | `50` | In-memory ring buffer capacity for breadcrumbs |
|
|
91
|
+
| `beforeSend` | `Function` | `undefined` | Hook to inspect, modify, or discard events prior to transmission |
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Sampling Configuration (`SamplingConfig`)
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
export interface SamplingConfig {
|
|
99
|
+
/** Sampling rate: 0.0 (0%) to 1.0 (100%). Default: 1.0 */
|
|
100
|
+
rate?: number;
|
|
101
|
+
/** Deduplication sliding window in milliseconds. Default: 10000 */
|
|
102
|
+
dedupeWindow?: number;
|
|
103
|
+
/** Max unique error fingerprints captured per browser session. Default: 100 */
|
|
104
|
+
maxPerSession?: number;
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Universal Error Boundary (`NexusGuardCore`)
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
const guard = new NexusGuardCore({
|
|
114
|
+
tracker,
|
|
115
|
+
onError: (error, info) => {
|
|
116
|
+
console.warn(`Protected crash [Ref: ${info.errorId}]:`, error);
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// Subscribe to state changes
|
|
121
|
+
const unsubscribe = guard.subscribe((info) => {
|
|
122
|
+
if (info) {
|
|
123
|
+
document.getElementById('root')!.innerHTML = `
|
|
124
|
+
<div class="alert">
|
|
125
|
+
<h2>App Crash Protected</h2>
|
|
126
|
+
<p>Reference: ${info.errorId}</p>
|
|
127
|
+
<button id="retry">Retry</button>
|
|
128
|
+
</div>
|
|
129
|
+
`;
|
|
130
|
+
document.getElementById('retry')?.addEventListener('click', () => guard.recover());
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Local Dev Server (`nexus-dev`)
|
|
138
|
+
|
|
139
|
+
The tracker package includes an offline telemetry receiver and dashboard CLI:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
# Start local ingestion server on port 4567
|
|
143
|
+
npx nexus-dev --port 4567
|
|
144
|
+
# or in monorepo
|
|
145
|
+
pnpm nexus-dev
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
- **Web Dashboard**: `http://localhost:4567/`
|
|
149
|
+
- **Ingestion Endpoint**: `http://localhost:4567/api/v1/telemetry/errors`
|
|
150
|
+
- **SSE Stream**: `http://localhost:4567/sse`
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Framework Compatibility Matrix
|
|
155
|
+
|
|
156
|
+
`@nexussdk/tracker` has zero runtime dependencies and runs on any modern browser or Node.js backend:
|
|
21
157
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
158
|
+
| Framework / Runtime | Supported Versions | Mechanism | Documentation |
|
|
159
|
+
| :--- | :--- | :--- | :--- |
|
|
160
|
+
| **React / Next.js** | React 16.8 – 19 / Next.js 13 – 16 | `<NexusGuard>`, `useNexus`, Error Boundary | [React Error Boundary Guide](https://nexus.dev/sdk-tracker/react-error-boundary/) |
|
|
161
|
+
| **Vue / Nuxt** | Vue 2.7 & 3.x / Nuxt 3 & 4 | `app.config.errorHandler`, `error.vue` | [Vue Error Tracking Guide](https://nexus.dev/sdk-tracker/frameworks/vue/) |
|
|
162
|
+
| **Angular** | Angular 14 – 19+ / AngularJS | `ErrorHandler` provider, HTTP interceptors | [Angular Error Tracking Guide](https://nexus.dev/sdk-tracker/frameworks/angular/) |
|
|
163
|
+
| **Svelte / SvelteKit** | Svelte 3 – 5 / SvelteKit 1 & 2 | `handleError` hooks, `+error.svelte` | [Svelte Error Tracking Guide](https://nexus.dev/sdk-tracker/frameworks/svelte/) |
|
|
164
|
+
| **Node.js Backend** | Node.js 18, 20, 22 LTS | Express / Fastify error middleware | [Node.js Backend Guide](https://nexus.dev/sdk-tracker/frameworks/vanilla/) |
|
|
26
165
|
|
|
27
166
|
---
|
|
28
167
|
|