@squasher-ai/browser 0.1.1 → 0.3.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/LICENSE +21 -21
- package/README.md +3 -42
- package/dist/_vendor/result-runtime/attempt.d.ts +17 -0
- package/dist/_vendor/result-runtime/attempt.js +62 -0
- package/dist/_vendor/sdk-runtime/batching/index.d.ts +42 -0
- package/dist/_vendor/sdk-runtime/batching/index.js +48 -0
- package/dist/_vendor/sdk-runtime/errors/headers.d.ts +6 -0
- package/dist/_vendor/sdk-runtime/errors/headers.js +44 -0
- package/dist/_vendor/sdk-runtime/errors/index.d.ts +95 -0
- package/dist/_vendor/sdk-runtime/errors/index.js +157 -0
- package/dist/_vendor/sdk-runtime/headers.d.ts +48 -0
- package/dist/_vendor/sdk-runtime/headers.js +67 -0
- package/dist/_vendor/sdk-runtime/platform.d.ts +33 -0
- package/dist/_vendor/sdk-runtime/platform.js +173 -0
- package/dist/_vendor/sdk-runtime/retry.d.ts +50 -0
- package/dist/_vendor/sdk-runtime/retry.js +104 -0
- package/dist/_vendor/sdk-runtime/runtime/actionable-error.d.ts +37 -0
- package/dist/_vendor/sdk-runtime/runtime/actionable-error.js +123 -0
- package/dist/_vendor/sdk-runtime/runtime/environment.d.ts +18 -0
- package/dist/_vendor/sdk-runtime/runtime/environment.js +81 -0
- package/dist/_vendor/sdk-runtime/runtime/public-sdk-runtime.d.ts +12 -0
- package/dist/_vendor/sdk-runtime/runtime/public-sdk-runtime.js +38 -0
- package/dist/_vendor/sdk-runtime/runtime/redaction.d.ts +14 -0
- package/dist/_vendor/sdk-runtime/runtime/redaction.js +120 -0
- package/dist/_vendor/sdk-runtime/runtime/release.d.ts +35 -0
- package/dist/_vendor/sdk-runtime/runtime/release.js +120 -0
- package/dist/_vendor/sdk-runtime/sampling/index.d.ts +43 -0
- package/dist/_vendor/sdk-runtime/sampling/index.js +70 -0
- package/dist/_vendor/telemetry-contract/sdk/public-contract.d.ts +175 -0
- package/dist/_vendor/telemetry-contract/sdk/public-contract.js +5 -0
- package/dist/autocapture.d.ts +14 -19
- package/dist/autocapture.js +77 -95
- package/dist/client.d.ts +12 -20
- package/dist/client.js +56 -72
- package/dist/config.d.ts +24 -0
- package/dist/config.js +26 -0
- package/dist/console-capture.d.ts +7 -0
- package/dist/console-capture.js +79 -0
- package/dist/errors.d.ts +2 -3
- package/dist/errors.js +8 -5
- package/dist/index.d.ts +5 -39
- package/dist/index.js +4 -82
- package/dist/next.d.ts +39 -0
- package/dist/next.js +67 -0
- package/dist/react.d.ts +0 -1
- package/dist/react.js +12 -10
- package/dist/replay-network.d.ts +20 -0
- package/dist/replay-network.js +193 -0
- package/dist/replay-privacy.d.ts +2 -3
- package/dist/replay-privacy.js +47 -17
- package/dist/replay-retry.d.ts +40 -0
- package/dist/replay-retry.js +193 -0
- package/dist/replay.d.ts +18 -6
- package/dist/replay.js +131 -71
- package/dist/runtime/client-singleton.d.ts +24 -0
- package/dist/runtime/client-singleton.js +66 -0
- package/dist/runtime/client.d.ts +21 -0
- package/dist/runtime/client.js +12 -0
- package/dist/runtime/replay.d.ts +12 -0
- package/dist/runtime/replay.js +15 -0
- package/dist/session.d.ts +0 -11
- package/dist/session.js +20 -21
- package/dist/telemetry.d.ts +1 -2
- package/dist/telemetry.js +13 -10
- package/dist/trace-context.d.ts +8 -0
- package/dist/trace-context.js +13 -0
- package/dist/transport.d.ts +11 -20
- package/dist/transport.js +86 -66
- package/dist/types.d.ts +38 -139
- package/dist/types.js +0 -7
- package/dist/vitals.d.ts +55 -3
- package/dist/vitals.js +115 -16
- package/package.json +11 -3
- package/dist/__tests__/client.test.d.ts +0 -2
- package/dist/__tests__/client.test.d.ts.map +0 -1
- package/dist/__tests__/client.test.js +0 -103
- package/dist/__tests__/errors.test.d.ts +0 -2
- package/dist/__tests__/errors.test.d.ts.map +0 -1
- package/dist/__tests__/errors.test.js +0 -80
- package/dist/__tests__/replay-privacy.test.d.ts +0 -2
- package/dist/__tests__/replay-privacy.test.d.ts.map +0 -1
- package/dist/__tests__/replay-privacy.test.js +0 -124
- package/dist/__tests__/replay-startup.test.d.ts +0 -2
- package/dist/__tests__/replay-startup.test.d.ts.map +0 -1
- package/dist/__tests__/replay-startup.test.js +0 -99
- package/dist/__tests__/replay.test.d.ts +0 -2
- package/dist/__tests__/replay.test.d.ts.map +0 -1
- package/dist/__tests__/replay.test.js +0 -217
- package/dist/__tests__/session.test.d.ts +0 -2
- package/dist/__tests__/session.test.d.ts.map +0 -1
- package/dist/__tests__/session.test.js +0 -46
- package/dist/__tests__/transport.test.d.ts +0 -2
- package/dist/__tests__/transport.test.d.ts.map +0 -1
- package/dist/__tests__/transport.test.js +0 -101
- package/dist/__tests__/types.test.d.ts +0 -2
- package/dist/__tests__/types.test.d.ts.map +0 -1
- package/dist/__tests__/types.test.js +0 -139
- package/dist/autocapture.d.ts.map +0 -1
- package/dist/client.d.ts.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/react.d.ts.map +0 -1
- package/dist/replay-privacy.d.ts.map +0 -1
- package/dist/replay.d.ts.map +0 -1
- package/dist/session.d.ts.map +0 -1
- package/dist/telemetry.d.ts.map +0 -1
- package/dist/transport.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/vitals.d.ts.map +0 -1
package/dist/client.js
CHANGED
|
@@ -1,43 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* - Global error capture (via errors.ts)
|
|
9
|
-
* - Auto-capture breadcrumbs (via autocapture.ts)
|
|
10
|
-
* - Transport (via transport.ts)
|
|
11
|
-
*/
|
|
12
|
-
import { installAutocapture } from "./autocapture";
|
|
13
|
-
import { buildErrorEvent, buildMessageEvent, installGlobalErrorHandlers } from "./errors";
|
|
14
|
-
import { ReplayRecorder } from "./replay";
|
|
15
|
-
import { buildGenerationEvent, buildIdentifyEvent, buildPageEvent, buildScreenEvent, buildSpanEvent, buildToolCallEvent, buildTrackEvent, mergeIdentifiedUser, prepareBrowserEvent, } from "./telemetry";
|
|
16
|
-
import { Transport } from "./transport";
|
|
17
|
-
import { startVitalsCollection } from "./vitals";
|
|
18
|
-
const DEFAULT_ENDPOINT = "https://ingest.squasher.ai";
|
|
19
|
-
function resolveConfig(config) {
|
|
20
|
-
return {
|
|
21
|
-
apiKey: config.apiKey,
|
|
22
|
-
projectId: config.projectId,
|
|
23
|
-
endpoint: config.endpoint ?? DEFAULT_ENDPOINT,
|
|
24
|
-
environment: config.environment,
|
|
25
|
-
release: config.release,
|
|
26
|
-
debug: config.debug ?? false,
|
|
27
|
-
sampleRate: config.sampleRate ?? 1,
|
|
28
|
-
vitalsSampleRate: config.vitalsSampleRate ?? 1,
|
|
29
|
-
enableVitals: config.enableVitals ?? true,
|
|
30
|
-
enableErrorCapture: config.enableErrorCapture ?? true,
|
|
31
|
-
enableAutoBreadcrumbs: config.enableAutoBreadcrumbs ?? true,
|
|
32
|
-
beforeSend: config.beforeSend,
|
|
33
|
-
maxBreadcrumbs: config.maxBreadcrumbs ?? 30,
|
|
34
|
-
vitalsBufferSize: config.vitalsBufferSize ?? 10,
|
|
35
|
-
vitalsFlushIntervalMs: config.vitalsFlushIntervalMs ?? 10_000,
|
|
36
|
-
replayEnabled: config.replay?.enabled ?? false,
|
|
37
|
-
replaySampleRate: config.replay?.sampleRate ?? 1,
|
|
38
|
-
replayPrivacy: config.replay?.privacy,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
1
|
+
import { shouldSampleTelemetry } from "./_vendor/sdk-runtime/runtime/public-sdk-runtime.js";
|
|
2
|
+
import { resolveConfig } from "./config.js";
|
|
3
|
+
import { buildErrorEvent, buildMessageEvent } from "./errors.js";
|
|
4
|
+
import { defaultBrowserClientRuntime, } from "./runtime/client.js";
|
|
5
|
+
import { getSessionId } from "./session.js";
|
|
6
|
+
import { buildGenerationEvent, buildIdentifyEvent, buildPageEvent, buildScreenEvent, buildSpanEvent, buildToolCallEvent, buildTrackEvent, mergeIdentifiedUser, prepareBrowserEvent, } from "./telemetry.js";
|
|
7
|
+
import { mapExternalVital } from "./vitals.js";
|
|
41
8
|
export class BrowserClient {
|
|
42
9
|
config;
|
|
43
10
|
transport;
|
|
@@ -47,7 +14,8 @@ export class BrowserClient {
|
|
|
47
14
|
disabled;
|
|
48
15
|
cleanups = [];
|
|
49
16
|
replayRecorder = null;
|
|
50
|
-
|
|
17
|
+
vitalsHandle = null;
|
|
18
|
+
constructor(config, runtime = defaultBrowserClientRuntime) {
|
|
51
19
|
if (!config.apiKey)
|
|
52
20
|
throw new Error("Squasher: apiKey is required");
|
|
53
21
|
if (!config.projectId)
|
|
@@ -58,8 +26,7 @@ export class BrowserClient {
|
|
|
58
26
|
if (this.config.debug) {
|
|
59
27
|
console.warn("[squasher] SDK initialized in disabled mode");
|
|
60
28
|
}
|
|
61
|
-
|
|
62
|
-
this.transport = new Transport({
|
|
29
|
+
this.transport = runtime.createTransport({
|
|
63
30
|
endpoint: this.config.endpoint,
|
|
64
31
|
projectId: this.config.projectId,
|
|
65
32
|
apiKey: this.config.apiKey,
|
|
@@ -69,8 +36,7 @@ export class BrowserClient {
|
|
|
69
36
|
});
|
|
70
37
|
return;
|
|
71
38
|
}
|
|
72
|
-
|
|
73
|
-
this.transport = new Transport({
|
|
39
|
+
this.transport = runtime.createTransport({
|
|
74
40
|
endpoint: this.config.endpoint,
|
|
75
41
|
projectId: this.config.projectId,
|
|
76
42
|
apiKey: this.config.apiKey,
|
|
@@ -78,36 +44,45 @@ export class BrowserClient {
|
|
|
78
44
|
vitalsBufferSize: this.config.vitalsBufferSize,
|
|
79
45
|
vitalsFlushIntervalMs: this.config.vitalsFlushIntervalMs,
|
|
80
46
|
});
|
|
81
|
-
// Start Web Vitals collection
|
|
82
47
|
if (this.config.enableVitals) {
|
|
83
|
-
startVitalsCollection(this.transport, {
|
|
48
|
+
this.vitalsHandle = runtime.startVitalsCollection(this.transport, {
|
|
84
49
|
sampleRate: this.config.vitalsSampleRate,
|
|
85
50
|
environment: this.config.environment,
|
|
86
51
|
release: this.config.release,
|
|
87
52
|
debug: this.config.debug,
|
|
88
53
|
});
|
|
89
54
|
}
|
|
90
|
-
// Install global error handlers
|
|
91
55
|
if (this.config.enableErrorCapture) {
|
|
92
|
-
const cleanup = installGlobalErrorHandlers((event) => {
|
|
56
|
+
const cleanup = runtime.installGlobalErrorHandlers((event) => {
|
|
93
57
|
this.sendErrorEvent(event);
|
|
94
58
|
});
|
|
95
59
|
this.cleanups.push(cleanup);
|
|
96
60
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const cleanup = installAutocapture((crumb) => {
|
|
61
|
+
if (this.config.enableAutoBreadcrumbs || this.config.captureConsoleErrors) {
|
|
62
|
+
const cleanup = runtime.installAutocapture((crumb) => {
|
|
100
63
|
this.addBreadcrumb(crumb);
|
|
64
|
+
}, {
|
|
65
|
+
captureBreadcrumbs: this.config.enableAutoBreadcrumbs,
|
|
66
|
+
onConsoleError: this.config.captureConsoleErrors
|
|
67
|
+
? (event) => {
|
|
68
|
+
this.sendErrorEvent(event);
|
|
69
|
+
}
|
|
70
|
+
: undefined,
|
|
101
71
|
});
|
|
102
72
|
this.cleanups.push(cleanup);
|
|
103
73
|
}
|
|
104
74
|
if (this.config.replayEnabled) {
|
|
105
|
-
this.replayRecorder =
|
|
75
|
+
this.replayRecorder = runtime.createReplayRecorder({
|
|
106
76
|
endpoint: this.config.endpoint,
|
|
107
77
|
projectId: this.config.projectId,
|
|
108
78
|
apiKey: this.config.apiKey,
|
|
109
79
|
debug: this.config.debug,
|
|
110
80
|
sampleRate: this.config.replaySampleRate,
|
|
81
|
+
environment: this.config.environment,
|
|
82
|
+
release: this.config.release,
|
|
83
|
+
getDistinctId: () => this.user?.id,
|
|
84
|
+
getUserId: () => this.user?.id,
|
|
85
|
+
getVisitorId: () => getSessionId(),
|
|
111
86
|
privacy: this.config.replayPrivacy,
|
|
112
87
|
});
|
|
113
88
|
}
|
|
@@ -117,11 +92,11 @@ export class BrowserClient {
|
|
|
117
92
|
vitals: this.config.enableVitals,
|
|
118
93
|
errorCapture: this.config.enableErrorCapture,
|
|
119
94
|
autoBreadcrumbs: this.config.enableAutoBreadcrumbs,
|
|
95
|
+
consoleErrors: this.config.captureConsoleErrors,
|
|
120
96
|
replay: this.config.replayEnabled,
|
|
121
97
|
});
|
|
122
98
|
}
|
|
123
99
|
}
|
|
124
|
-
// ─── Context ──────────────────────────────────────────────────────────
|
|
125
100
|
setUser(user) {
|
|
126
101
|
this.user = user;
|
|
127
102
|
}
|
|
@@ -140,7 +115,6 @@ export class BrowserClient {
|
|
|
140
115
|
this.breadcrumbs = this.breadcrumbs.slice(-this.config.maxBreadcrumbs);
|
|
141
116
|
}
|
|
142
117
|
}
|
|
143
|
-
// ─── Capture ──────────────────────────────────────────────────────────
|
|
144
118
|
captureError(error, extra) {
|
|
145
119
|
this.captureTelemetry(buildErrorEvent(error, extra));
|
|
146
120
|
}
|
|
@@ -150,8 +124,6 @@ export class BrowserClient {
|
|
|
150
124
|
captureTelemetry(event) {
|
|
151
125
|
if (this.disabled)
|
|
152
126
|
return;
|
|
153
|
-
if (!this.shouldSample())
|
|
154
|
-
return;
|
|
155
127
|
this.sendErrorEvent(event);
|
|
156
128
|
}
|
|
157
129
|
track(eventName, properties, context = {}) {
|
|
@@ -176,11 +148,22 @@ export class BrowserClient {
|
|
|
176
148
|
captureGeneration(message, context = {}) {
|
|
177
149
|
this.captureTelemetry(buildGenerationEvent(message, context));
|
|
178
150
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
151
|
+
/** Record a web vital from an external collector (e.g. Next.js `useReportWebVitals`). */
|
|
152
|
+
recordWebVital(metric, route) {
|
|
153
|
+
if (this.disabled)
|
|
154
|
+
return;
|
|
155
|
+
const event = mapExternalVital(metric, this.vitalsConfig(), route);
|
|
156
|
+
this.transport.enqueueVital(event);
|
|
157
|
+
}
|
|
158
|
+
/** Stop the SDK's native `web-vitals` collector to avoid double-counting. */
|
|
159
|
+
suppressNativeVitalsCollection() {
|
|
160
|
+
this.vitalsHandle?.suppress();
|
|
161
|
+
}
|
|
162
|
+
vitalsConfig() {
|
|
163
|
+
const { vitalsSampleRate: sampleRate, environment, release, debug } = this.config;
|
|
164
|
+
return { sampleRate, environment, release, debug };
|
|
165
|
+
}
|
|
166
|
+
/** Flush vitals and stop timers. Call before unmounting a SPA. */
|
|
184
167
|
close() {
|
|
185
168
|
this.replayRecorder?.dispose();
|
|
186
169
|
this.replayRecorder = null;
|
|
@@ -190,14 +173,6 @@ export class BrowserClient {
|
|
|
190
173
|
this.cleanups = [];
|
|
191
174
|
this.transport.dispose();
|
|
192
175
|
}
|
|
193
|
-
// ─── Private ──────────────────────────────────────────────────────────
|
|
194
|
-
shouldSample() {
|
|
195
|
-
if (this.config.sampleRate >= 1)
|
|
196
|
-
return true;
|
|
197
|
-
if (this.config.sampleRate <= 0)
|
|
198
|
-
return false;
|
|
199
|
-
return Math.random() < this.config.sampleRate;
|
|
200
|
-
}
|
|
201
176
|
/** Enrich an error event with current context and send it. */
|
|
202
177
|
sendErrorEvent(event) {
|
|
203
178
|
const prepared = prepareBrowserEvent(event, {
|
|
@@ -208,8 +183,17 @@ export class BrowserClient {
|
|
|
208
183
|
tags: this.tags,
|
|
209
184
|
user: this.user,
|
|
210
185
|
});
|
|
211
|
-
if (prepared)
|
|
212
|
-
|
|
186
|
+
if (!prepared)
|
|
187
|
+
return;
|
|
188
|
+
if (!this.config.debug && !shouldSampleTelemetry(prepared, this.config.sampling)) {
|
|
189
|
+
if (!prepared.measurements?.length)
|
|
190
|
+
return;
|
|
191
|
+
this.transport.sendEvent({
|
|
192
|
+
...prepared,
|
|
193
|
+
attributes: { ...prepared.attributes, "squasher.sampled": false },
|
|
194
|
+
});
|
|
195
|
+
return;
|
|
213
196
|
}
|
|
197
|
+
this.transport.sendEvent(prepared);
|
|
214
198
|
}
|
|
215
199
|
}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ResolvedTelemetrySampling } from "./_vendor/sdk-runtime/runtime/public-sdk-runtime.js";
|
|
2
|
+
import type { BrowserConfig, BrowserErrorEvent, ReplayPrivacyConfig } from "./types.js";
|
|
3
|
+
export interface ResolvedConfig {
|
|
4
|
+
apiKey: string;
|
|
5
|
+
projectId: string;
|
|
6
|
+
endpoint: string;
|
|
7
|
+
environment?: string;
|
|
8
|
+
release?: string;
|
|
9
|
+
debug: boolean;
|
|
10
|
+
sampling: ResolvedTelemetrySampling;
|
|
11
|
+
vitalsSampleRate: number;
|
|
12
|
+
enableVitals: boolean;
|
|
13
|
+
enableErrorCapture: boolean;
|
|
14
|
+
enableAutoBreadcrumbs: boolean;
|
|
15
|
+
captureConsoleErrors: boolean;
|
|
16
|
+
beforeSend?: (event: BrowserErrorEvent) => BrowserErrorEvent | null;
|
|
17
|
+
maxBreadcrumbs: number;
|
|
18
|
+
vitalsBufferSize: number;
|
|
19
|
+
vitalsFlushIntervalMs: number;
|
|
20
|
+
replayEnabled: boolean;
|
|
21
|
+
replaySampleRate: number;
|
|
22
|
+
replayPrivacy?: ReplayPrivacyConfig;
|
|
23
|
+
}
|
|
24
|
+
export declare function resolveConfig(config: BrowserConfig): ResolvedConfig;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DEFAULT_INGEST_ENDPOINT, detectRelease, resolveDebugFlag, resolveTelemetrySampling, } from "./_vendor/sdk-runtime/runtime/public-sdk-runtime.js";
|
|
2
|
+
export function resolveConfig(config) {
|
|
3
|
+
return {
|
|
4
|
+
apiKey: config.apiKey,
|
|
5
|
+
projectId: config.projectId,
|
|
6
|
+
endpoint: config.endpoint ?? DEFAULT_INGEST_ENDPOINT,
|
|
7
|
+
environment: config.environment,
|
|
8
|
+
// In the browser, detectRelease only picks up build-time-injected vars
|
|
9
|
+
// (Next.js inlines `process.env.NEXT_PUBLIC_*` etc).
|
|
10
|
+
release: config.release ?? detectRelease() ?? undefined,
|
|
11
|
+
debug: resolveDebugFlag(config.debug),
|
|
12
|
+
sampling: resolveTelemetrySampling(config.sampling),
|
|
13
|
+
vitalsSampleRate: config.vitalsSampleRate ?? 1,
|
|
14
|
+
enableVitals: config.enableVitals ?? true,
|
|
15
|
+
enableErrorCapture: config.enableErrorCapture ?? true,
|
|
16
|
+
enableAutoBreadcrumbs: config.enableAutoBreadcrumbs ?? true,
|
|
17
|
+
captureConsoleErrors: config.captureConsoleErrors ?? false,
|
|
18
|
+
beforeSend: config.beforeSend,
|
|
19
|
+
maxBreadcrumbs: config.maxBreadcrumbs ?? 30,
|
|
20
|
+
vitalsBufferSize: config.vitalsBufferSize ?? 10,
|
|
21
|
+
vitalsFlushIntervalMs: config.vitalsFlushIntervalMs ?? 10_000,
|
|
22
|
+
replayEnabled: config.replay?.enabled ?? true,
|
|
23
|
+
replaySampleRate: config.replay?.sampleRate ?? 1,
|
|
24
|
+
replayPrivacy: config.replay?.privacy,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Breadcrumb, BrowserErrorEvent } from "./types.js";
|
|
2
|
+
export type BreadcrumbCallback = (crumb: Omit<Breadcrumb, "timestamp">) => void;
|
|
3
|
+
export interface ConsoleCaptureOptions {
|
|
4
|
+
captureBreadcrumbs: boolean;
|
|
5
|
+
onConsoleError?: (event: BrowserErrorEvent) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function captureConsole(onBreadcrumb: BreadcrumbCallback, options: ConsoleCaptureOptions): () => void;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { buildErrorEvent, buildMessageEvent } from "./errors.js";
|
|
2
|
+
export function captureConsole(onBreadcrumb, options) {
|
|
3
|
+
const origError = console.error.bind(console);
|
|
4
|
+
const origWarn = console.warn.bind(console);
|
|
5
|
+
console.error = (...args) => {
|
|
6
|
+
if (!isInternalSquasherConsole(args)) {
|
|
7
|
+
const message = formatConsoleArgs(args);
|
|
8
|
+
if (options.captureBreadcrumbs) {
|
|
9
|
+
onBreadcrumb({
|
|
10
|
+
category: "console",
|
|
11
|
+
message: message.slice(0, 200),
|
|
12
|
+
level: "error",
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
options.onConsoleError?.(buildConsoleErrorEvent(args, message));
|
|
16
|
+
}
|
|
17
|
+
origError(...args);
|
|
18
|
+
};
|
|
19
|
+
console.warn = (...args) => {
|
|
20
|
+
if (options.captureBreadcrumbs && !isInternalSquasherConsole(args)) {
|
|
21
|
+
onBreadcrumb({
|
|
22
|
+
category: "console",
|
|
23
|
+
message: formatConsoleArgs(args).slice(0, 200),
|
|
24
|
+
level: "warning",
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
origWarn(...args);
|
|
28
|
+
};
|
|
29
|
+
return () => {
|
|
30
|
+
console.error = origError;
|
|
31
|
+
console.warn = origWarn;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function buildConsoleErrorEvent(args, message) {
|
|
35
|
+
const error = args.find((arg) => arg instanceof Error);
|
|
36
|
+
if (error instanceof Error) {
|
|
37
|
+
const event = buildErrorEvent(error, {
|
|
38
|
+
argument_count: args.length,
|
|
39
|
+
source: "console",
|
|
40
|
+
});
|
|
41
|
+
event.message = message || event.message;
|
|
42
|
+
event.type = event.type === "Error" ? "ConsoleError" : `ConsoleError(${event.type})`;
|
|
43
|
+
return event;
|
|
44
|
+
}
|
|
45
|
+
const event = buildMessageEvent(message || "console.error", "error");
|
|
46
|
+
event.type = "ConsoleError";
|
|
47
|
+
event.extra = {
|
|
48
|
+
argument_count: args.length,
|
|
49
|
+
source: "console",
|
|
50
|
+
};
|
|
51
|
+
return event;
|
|
52
|
+
}
|
|
53
|
+
function isInternalSquasherConsole(args) {
|
|
54
|
+
const first = args[0];
|
|
55
|
+
return (Object.prototype.toString.call(first) === "[object String]" &&
|
|
56
|
+
String(first).startsWith("[squasher]"));
|
|
57
|
+
}
|
|
58
|
+
function formatConsoleArgs(args) {
|
|
59
|
+
return args.map(formatConsoleArg).join(" ").slice(0, 1_000);
|
|
60
|
+
}
|
|
61
|
+
function formatConsoleArg(arg) {
|
|
62
|
+
if (arg instanceof Error) {
|
|
63
|
+
return `${arg.name}: ${arg.message}`;
|
|
64
|
+
}
|
|
65
|
+
if (arg === null) {
|
|
66
|
+
return "null";
|
|
67
|
+
}
|
|
68
|
+
if (arg === undefined) {
|
|
69
|
+
return "undefined";
|
|
70
|
+
}
|
|
71
|
+
const tag = Object.prototype.toString.call(arg);
|
|
72
|
+
if (tag === "[object String]" ||
|
|
73
|
+
tag === "[object Number]" ||
|
|
74
|
+
tag === "[object Boolean]" ||
|
|
75
|
+
tag === "[object BigInt]") {
|
|
76
|
+
return String(arg);
|
|
77
|
+
}
|
|
78
|
+
return Object.prototype.toString.call(arg);
|
|
79
|
+
}
|
package/dist/errors.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* Parses Error.stack into StackFrame[] using the same regex pattern as
|
|
9
9
|
* @squasher-ai/node. In-app heuristic: node_modules = not in_app.
|
|
10
10
|
*/
|
|
11
|
-
import type { BrowserErrorEvent, StackFrame } from "./types";
|
|
11
|
+
import type { BrowserErrorEvent, JsonObject, StackFrame } from "./types.js";
|
|
12
12
|
/**
|
|
13
13
|
* Parse an Error.stack string into structured StackFrame[].
|
|
14
14
|
*/
|
|
@@ -16,7 +16,7 @@ export declare function parseStack(stack?: string): StackFrame[] | undefined;
|
|
|
16
16
|
/**
|
|
17
17
|
* Build a BrowserErrorEvent from an Error object.
|
|
18
18
|
*/
|
|
19
|
-
export declare function buildErrorEvent(error: Error, extra?:
|
|
19
|
+
export declare function buildErrorEvent(error: Error, extra?: JsonObject): BrowserErrorEvent;
|
|
20
20
|
/**
|
|
21
21
|
* Build a BrowserErrorEvent from a string message.
|
|
22
22
|
*/
|
|
@@ -26,4 +26,3 @@ export declare function buildMessageEvent(message: string, level?: BrowserErrorE
|
|
|
26
26
|
* Returns a cleanup function to remove the handlers.
|
|
27
27
|
*/
|
|
28
28
|
export declare function installGlobalErrorHandlers(onError: (event: BrowserErrorEvent) => void): () => void;
|
|
29
|
-
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @squasher-ai/node. In-app heuristic: node_modules = not in_app.
|
|
10
10
|
*/
|
|
11
11
|
const SDK_NAME = "@squasher-ai/browser";
|
|
12
|
-
const SDK_VERSION = "0.
|
|
12
|
+
const SDK_VERSION = "0.3.0";
|
|
13
13
|
/** Stack trace line regex — works for V8 (Chrome, Node) and SpiderMonkey (Firefox). */
|
|
14
14
|
const STACK_LINE_RE = /^\s*at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?/;
|
|
15
15
|
/** Firefox stack format: "functionName@filename:line:col" */
|
|
@@ -33,10 +33,7 @@ export function parseStack(stack) {
|
|
|
33
33
|
if (!match)
|
|
34
34
|
continue;
|
|
35
35
|
const [, fn, filename, lineno, colno] = match;
|
|
36
|
-
const isExternal = filename
|
|
37
|
-
filename?.includes("extensions/") ||
|
|
38
|
-
filename?.startsWith("chrome-extension://") ||
|
|
39
|
-
false;
|
|
36
|
+
const isExternal = isExternalFilename(filename);
|
|
40
37
|
frames.push({
|
|
41
38
|
function: fn || "<anonymous>",
|
|
42
39
|
filename,
|
|
@@ -47,6 +44,12 @@ export function parseStack(stack) {
|
|
|
47
44
|
}
|
|
48
45
|
return frames.length > 0 ? frames : undefined;
|
|
49
46
|
}
|
|
47
|
+
function isExternalFilename(filename) {
|
|
48
|
+
return (filename?.includes("node_modules") ||
|
|
49
|
+
filename?.includes("extensions/") ||
|
|
50
|
+
filename?.startsWith("chrome-extension://") ||
|
|
51
|
+
false);
|
|
52
|
+
}
|
|
50
53
|
/**
|
|
51
54
|
* Build a BrowserErrorEvent from an Error object.
|
|
52
55
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* - Core Web Vitals (LCP, CLS, INP, FCP, TTFB)
|
|
6
6
|
* - JavaScript errors (window.onerror, unhandledrejection)
|
|
7
7
|
* - Navigation breadcrumbs, click breadcrumbs, fetch error breadcrumbs
|
|
8
|
+
* - Optional console.error events
|
|
8
9
|
* - Session context for error ↔ vitals correlation
|
|
9
10
|
*
|
|
10
11
|
* Usage:
|
|
@@ -21,42 +22,7 @@
|
|
|
21
22
|
* // Manual capture:
|
|
22
23
|
* captureError(new Error('Something went wrong'));
|
|
23
24
|
*/
|
|
24
|
-
export { BrowserClient } from "./client";
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
/** Initialize the global Squasher browser client. Throws if called twice. */
|
|
29
|
-
export declare function init(config: BrowserConfig): BrowserClient;
|
|
30
|
-
/** Get the global client (throws if not initialized). */
|
|
31
|
-
export declare function getClient(): BrowserClient;
|
|
32
|
-
/** Capture an error using the global client. */
|
|
33
|
-
export declare function captureError(error: Error, extra?: Record<string, unknown>): void;
|
|
34
|
-
/** Capture a message using the global client. */
|
|
35
|
-
export declare function captureMessage(message: string, level?: Level): void;
|
|
36
|
-
/** Capture a generalized telemetry event using the global client. */
|
|
37
|
-
export declare function captureTelemetry(event: BrowserErrorEvent): void;
|
|
38
|
-
/** Track a product analytics event using the global client. */
|
|
39
|
-
export declare function track(eventName: string, properties?: JsonObject, context?: Partial<BrowserErrorEvent>): void;
|
|
40
|
-
/** Identify a distinct user or visitor using the global client. */
|
|
41
|
-
export declare function identify(distinctId: string, traits?: JsonObject, context?: Partial<BrowserErrorEvent>): void;
|
|
42
|
-
/** Capture a page navigation event using the global client. */
|
|
43
|
-
export declare function page(name: string, properties?: JsonObject, context?: Partial<BrowserErrorEvent>): void;
|
|
44
|
-
/** Capture a screen event using the global client. */
|
|
45
|
-
export declare function screen(name: string, properties?: JsonObject, context?: Partial<BrowserErrorEvent>): void;
|
|
46
|
-
/** Capture an agent span using the global client. */
|
|
47
|
-
export declare function captureSpan(name: string, context?: Partial<BrowserErrorEvent>): void;
|
|
48
|
-
/** Capture a tool call using the global client. */
|
|
49
|
-
export declare function captureToolCall(name: string, context?: Partial<BrowserErrorEvent>): void;
|
|
50
|
-
/** Capture an LLM generation event using the global client. */
|
|
51
|
-
export declare function captureGeneration(message: string, context?: Partial<BrowserErrorEvent>): void;
|
|
52
|
-
/** Set user context on the global client. */
|
|
53
|
-
export declare function setUser(user: UserContext | undefined): void;
|
|
54
|
-
/** Set a single tag on the global client. */
|
|
55
|
-
export declare function setTag(key: string, value: string): void;
|
|
56
|
-
/** Set multiple tags on the global client. */
|
|
57
|
-
export declare function setTags(tags: Record<string, string>): void;
|
|
58
|
-
/** Add a breadcrumb on the global client. */
|
|
59
|
-
export declare function addBreadcrumb(crumb: Omit<Breadcrumb, "timestamp">): void;
|
|
60
|
-
/** Close the global client (stop timers, flush vitals, remove handlers). */
|
|
61
|
-
export declare function close(): void;
|
|
62
|
-
//# sourceMappingURL=index.d.ts.map
|
|
25
|
+
export { BrowserClient } from "./client.js";
|
|
26
|
+
export { addBreadcrumb, captureError, captureGeneration, captureMessage, captureSpan, captureTelemetry, captureToolCall, close, getClient, identify, init, page, screen, setTag, setTags, setUser, track, } from "./runtime/client-singleton.js";
|
|
27
|
+
export { createSpanId, createTraceContext, createTraceId } from "./trace-context.js";
|
|
28
|
+
export type { AnalyticsContext, Breadcrumb, BrowserConfig, BrowserErrorEvent, DeviceType, IngestBatchPayload, IngestResponse, JsonObject, Level, LlmContext, PageContext, ReplayConfig, ReplayPrivacyConfig, SessionContext, StackFrame, TelemetryKind, TelemetryMeasurement, ToolCallContext, TraceContext, UserContext, VisitorContext, VitalEvent, VitalMetricName, VitalRating, VitalsPayload, } from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* - Core Web Vitals (LCP, CLS, INP, FCP, TTFB)
|
|
6
6
|
* - JavaScript errors (window.onerror, unhandledrejection)
|
|
7
7
|
* - Navigation breadcrumbs, click breadcrumbs, fetch error breadcrumbs
|
|
8
|
+
* - Optional console.error events
|
|
8
9
|
* - Session context for error ↔ vitals correlation
|
|
9
10
|
*
|
|
10
11
|
* Usage:
|
|
@@ -21,85 +22,6 @@
|
|
|
21
22
|
* // Manual capture:
|
|
22
23
|
* captureError(new Error('Something went wrong'));
|
|
23
24
|
*/
|
|
24
|
-
export { BrowserClient } from "./client";
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
let _client = null;
|
|
28
|
-
/** Initialize the global Squasher browser client. Throws if called twice. */
|
|
29
|
-
export function init(config) {
|
|
30
|
-
if (_client) {
|
|
31
|
-
throw new Error("squasher.init() called more than once. Call close() first if re-initializing.");
|
|
32
|
-
}
|
|
33
|
-
_client = new BrowserClient(config);
|
|
34
|
-
return _client;
|
|
35
|
-
}
|
|
36
|
-
/** Get the global client (throws if not initialized). */
|
|
37
|
-
export function getClient() {
|
|
38
|
-
if (!_client) {
|
|
39
|
-
throw new Error("Squasher not initialized. Call init() first.");
|
|
40
|
-
}
|
|
41
|
-
return _client;
|
|
42
|
-
}
|
|
43
|
-
/** Capture an error using the global client. */
|
|
44
|
-
export function captureError(error, extra) {
|
|
45
|
-
getClient().captureError(error, extra);
|
|
46
|
-
}
|
|
47
|
-
/** Capture a message using the global client. */
|
|
48
|
-
export function captureMessage(message, level) {
|
|
49
|
-
getClient().captureMessage(message, level);
|
|
50
|
-
}
|
|
51
|
-
/** Capture a generalized telemetry event using the global client. */
|
|
52
|
-
export function captureTelemetry(event) {
|
|
53
|
-
getClient().captureTelemetry(event);
|
|
54
|
-
}
|
|
55
|
-
/** Track a product analytics event using the global client. */
|
|
56
|
-
export function track(eventName, properties, context) {
|
|
57
|
-
getClient().track(eventName, properties, context);
|
|
58
|
-
}
|
|
59
|
-
/** Identify a distinct user or visitor using the global client. */
|
|
60
|
-
export function identify(distinctId, traits, context) {
|
|
61
|
-
getClient().identify(distinctId, traits, context);
|
|
62
|
-
}
|
|
63
|
-
/** Capture a page navigation event using the global client. */
|
|
64
|
-
export function page(name, properties, context) {
|
|
65
|
-
getClient().page(name, properties, context);
|
|
66
|
-
}
|
|
67
|
-
/** Capture a screen event using the global client. */
|
|
68
|
-
export function screen(name, properties, context) {
|
|
69
|
-
getClient().screen(name, properties, context);
|
|
70
|
-
}
|
|
71
|
-
/** Capture an agent span using the global client. */
|
|
72
|
-
export function captureSpan(name, context) {
|
|
73
|
-
getClient().captureSpan(name, context);
|
|
74
|
-
}
|
|
75
|
-
/** Capture a tool call using the global client. */
|
|
76
|
-
export function captureToolCall(name, context) {
|
|
77
|
-
getClient().captureToolCall(name, context);
|
|
78
|
-
}
|
|
79
|
-
/** Capture an LLM generation event using the global client. */
|
|
80
|
-
export function captureGeneration(message, context) {
|
|
81
|
-
getClient().captureGeneration(message, context);
|
|
82
|
-
}
|
|
83
|
-
/** Set user context on the global client. */
|
|
84
|
-
export function setUser(user) {
|
|
85
|
-
getClient().setUser(user);
|
|
86
|
-
}
|
|
87
|
-
/** Set a single tag on the global client. */
|
|
88
|
-
export function setTag(key, value) {
|
|
89
|
-
getClient().setTag(key, value);
|
|
90
|
-
}
|
|
91
|
-
/** Set multiple tags on the global client. */
|
|
92
|
-
export function setTags(tags) {
|
|
93
|
-
getClient().setTags(tags);
|
|
94
|
-
}
|
|
95
|
-
/** Add a breadcrumb on the global client. */
|
|
96
|
-
export function addBreadcrumb(crumb) {
|
|
97
|
-
getClient().addBreadcrumb(crumb);
|
|
98
|
-
}
|
|
99
|
-
/** Close the global client (stop timers, flush vitals, remove handlers). */
|
|
100
|
-
export function close() {
|
|
101
|
-
if (_client) {
|
|
102
|
-
_client.close();
|
|
103
|
-
_client = null;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
25
|
+
export { BrowserClient } from "./client.js";
|
|
26
|
+
export { addBreadcrumb, captureError, captureGeneration, captureMessage, captureSpan, captureTelemetry, captureToolCall, close, getClient, identify, init, page, screen, setTag, setTags, setUser, track, } from "./runtime/client-singleton.js";
|
|
27
|
+
export { createSpanId, createTraceContext, createTraceId } from "./trace-context.js";
|
package/dist/next.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js Web Vitals bridge for @squasher-ai/browser.
|
|
3
|
+
*
|
|
4
|
+
* Drop `<SquasherNextWebVitals />` into your root layout to capture both
|
|
5
|
+
* Core Web Vitals (LCP, CLS, INP, FCP, TTFB) and Next.js framework metrics
|
|
6
|
+
* (`Next.js-hydration`, `Next.js-route-change-to-render`, `Next.js-render`).
|
|
7
|
+
*
|
|
8
|
+
* The component hard-imports `next/web-vitals` and `next/navigation` so it
|
|
9
|
+
* is **only** valid in a Next.js app. Non-Next consumers should rely on the
|
|
10
|
+
* auto-collector that runs from `init()` and not import this module.
|
|
11
|
+
*
|
|
12
|
+
* Internally it bridges Next's `useReportWebVitals` hook into the existing
|
|
13
|
+
* browser client transport, suppressing the SDK's native `web-vitals`
|
|
14
|
+
* collector on mount so Core metrics aren't reported twice.
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* import { SquasherNextWebVitals } from '@squasher-ai/browser/next';
|
|
18
|
+
*
|
|
19
|
+
* export default function RootLayout({ children }) {
|
|
20
|
+
* return (
|
|
21
|
+
* <html>
|
|
22
|
+
* <body>
|
|
23
|
+
* <SquasherNextWebVitals />
|
|
24
|
+
* {children}
|
|
25
|
+
* </body>
|
|
26
|
+
* </html>
|
|
27
|
+
* );
|
|
28
|
+
* }
|
|
29
|
+
*/
|
|
30
|
+
interface SquasherNextWebVitalsProps {
|
|
31
|
+
/**
|
|
32
|
+
* Override the route tag attached to every metric. Defaults to the
|
|
33
|
+
* current `usePathname()` value, with the pathname re-evaluated lazily
|
|
34
|
+
* so a single hook subscription doesn't re-fire on every navigation.
|
|
35
|
+
*/
|
|
36
|
+
path?: string;
|
|
37
|
+
}
|
|
38
|
+
export declare function SquasherNextWebVitals({ path }?: SquasherNextWebVitalsProps): null;
|
|
39
|
+
export {};
|