@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
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Customer-facing telemetry contract shared by the published JavaScript SDKs.
|
|
3
|
+
* This module intentionally contains only the documented ingestion shapes.
|
|
4
|
+
*/
|
|
5
|
+
export type JsonPrimitive = boolean | null | number | string;
|
|
6
|
+
export interface JsonObject {
|
|
7
|
+
[key: string]: JsonValue;
|
|
8
|
+
}
|
|
9
|
+
export type JsonValue = JsonPrimitive | JsonValue[] | JsonObject;
|
|
10
|
+
export type Level = "fatal" | "error" | "warning" | "info" | "debug";
|
|
11
|
+
export interface StackFrame {
|
|
12
|
+
filename?: string;
|
|
13
|
+
function?: string;
|
|
14
|
+
lineno?: number;
|
|
15
|
+
colno?: number;
|
|
16
|
+
in_app?: boolean;
|
|
17
|
+
context_line?: string;
|
|
18
|
+
pre_context?: string[];
|
|
19
|
+
post_context?: string[];
|
|
20
|
+
}
|
|
21
|
+
export interface UserContext {
|
|
22
|
+
id?: string;
|
|
23
|
+
email?: string;
|
|
24
|
+
username?: string;
|
|
25
|
+
ip_address?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface RequestContext {
|
|
28
|
+
url?: string;
|
|
29
|
+
method?: string;
|
|
30
|
+
headers?: Record<string, string>;
|
|
31
|
+
}
|
|
32
|
+
export interface Breadcrumb {
|
|
33
|
+
timestamp?: string;
|
|
34
|
+
category?: string;
|
|
35
|
+
message?: string;
|
|
36
|
+
level?: string;
|
|
37
|
+
data?: JsonObject;
|
|
38
|
+
}
|
|
39
|
+
/** Event payload accepted by the documented ingestion endpoint. */
|
|
40
|
+
export interface IngestEvent {
|
|
41
|
+
message: string;
|
|
42
|
+
type?: string;
|
|
43
|
+
stack?: string;
|
|
44
|
+
frames?: StackFrame[];
|
|
45
|
+
level?: Level;
|
|
46
|
+
tags?: Record<string, string>;
|
|
47
|
+
user?: UserContext;
|
|
48
|
+
request?: RequestContext;
|
|
49
|
+
sdk?: {
|
|
50
|
+
name: string;
|
|
51
|
+
version: string;
|
|
52
|
+
};
|
|
53
|
+
timestamp?: string;
|
|
54
|
+
release?: string;
|
|
55
|
+
environment?: string;
|
|
56
|
+
breadcrumbs?: Breadcrumb[];
|
|
57
|
+
extra?: Record<string, JsonValue>;
|
|
58
|
+
session_id?: string;
|
|
59
|
+
kind?: TelemetryKind;
|
|
60
|
+
event_name?: string;
|
|
61
|
+
distinct_id?: string;
|
|
62
|
+
visitor?: VisitorContext;
|
|
63
|
+
analytics?: AnalyticsContext;
|
|
64
|
+
page?: PageContext;
|
|
65
|
+
session?: SessionContext;
|
|
66
|
+
trace?: TraceContext;
|
|
67
|
+
tool_call?: ToolCallContext;
|
|
68
|
+
llm?: LlmContext;
|
|
69
|
+
attributes?: JsonObject;
|
|
70
|
+
measurements?: TelemetryMeasurement[];
|
|
71
|
+
resource_attributes?: Record<string, string>;
|
|
72
|
+
}
|
|
73
|
+
export interface IngestBatchPayload {
|
|
74
|
+
events: IngestEvent[];
|
|
75
|
+
}
|
|
76
|
+
export type IngestEventBatch = [IngestEvent, ...IngestEvent[]];
|
|
77
|
+
export interface IngestBatchEnvelope {
|
|
78
|
+
events: IngestEventBatch;
|
|
79
|
+
}
|
|
80
|
+
export type IngestJsonBatchPayload = IngestEventBatch | IngestBatchEnvelope;
|
|
81
|
+
export type IngestJsonPayload = IngestEvent | IngestJsonBatchPayload;
|
|
82
|
+
/** An encoded newline-delimited JSON request body. */
|
|
83
|
+
export type IngestNdjsonPayload = string;
|
|
84
|
+
export type IngestRequestPayload = IngestJsonPayload | IngestNdjsonPayload;
|
|
85
|
+
export type TelemetryKind = "error" | "log" | "analytics" | "identify" | "page" | "screen" | "visitor" | "agent_session" | "agent_span" | "tool_call" | "llm_generation" | "agent_score";
|
|
86
|
+
export interface VisitorContext {
|
|
87
|
+
visitor_id?: string;
|
|
88
|
+
anonymous_id?: string;
|
|
89
|
+
account_id?: string;
|
|
90
|
+
}
|
|
91
|
+
export interface AnalyticsContext {
|
|
92
|
+
event?: string;
|
|
93
|
+
category?: string;
|
|
94
|
+
funnel?: string;
|
|
95
|
+
step?: string;
|
|
96
|
+
properties?: JsonObject;
|
|
97
|
+
}
|
|
98
|
+
export interface PageContext {
|
|
99
|
+
name?: string;
|
|
100
|
+
path?: string;
|
|
101
|
+
title?: string;
|
|
102
|
+
referrer?: string;
|
|
103
|
+
search?: string;
|
|
104
|
+
screen_class?: string;
|
|
105
|
+
}
|
|
106
|
+
export interface SessionContext {
|
|
107
|
+
session_type?: string;
|
|
108
|
+
agent_id?: string;
|
|
109
|
+
run_id?: string;
|
|
110
|
+
workflow_id?: string;
|
|
111
|
+
step_id?: string;
|
|
112
|
+
status?: string;
|
|
113
|
+
duration_ms?: number;
|
|
114
|
+
}
|
|
115
|
+
export interface TraceContext {
|
|
116
|
+
trace_id?: string;
|
|
117
|
+
span_id?: string;
|
|
118
|
+
parent_span_id?: string;
|
|
119
|
+
span_name?: string;
|
|
120
|
+
span_kind?: string;
|
|
121
|
+
status?: string;
|
|
122
|
+
duration_ms?: number;
|
|
123
|
+
}
|
|
124
|
+
export interface ToolCallContext {
|
|
125
|
+
name?: string;
|
|
126
|
+
input?: JsonObject;
|
|
127
|
+
output?: JsonObject;
|
|
128
|
+
status?: string;
|
|
129
|
+
duration_ms?: number;
|
|
130
|
+
}
|
|
131
|
+
export interface LlmContext {
|
|
132
|
+
provider?: string;
|
|
133
|
+
model?: string;
|
|
134
|
+
prompt_tokens?: number;
|
|
135
|
+
completion_tokens?: number;
|
|
136
|
+
total_tokens?: number;
|
|
137
|
+
cached_input_tokens?: number;
|
|
138
|
+
cost_usd?: number;
|
|
139
|
+
latency_ms?: number;
|
|
140
|
+
status?: string;
|
|
141
|
+
input?: JsonObject;
|
|
142
|
+
output?: JsonObject;
|
|
143
|
+
}
|
|
144
|
+
export interface TelemetryMeasurement {
|
|
145
|
+
name: string;
|
|
146
|
+
value: number;
|
|
147
|
+
unit?: string;
|
|
148
|
+
}
|
|
149
|
+
/** Outcome-aware SDK sampling. Errors and slow operations are kept by default. */
|
|
150
|
+
export interface TelemetrySamplingConfig {
|
|
151
|
+
successRate?: number;
|
|
152
|
+
errorRate?: number;
|
|
153
|
+
slowRate?: number;
|
|
154
|
+
slowThresholdMs?: number;
|
|
155
|
+
alwaysSampleUserIds?: string[];
|
|
156
|
+
alwaysSampleReleases?: string[];
|
|
157
|
+
}
|
|
158
|
+
export interface IngestResponse {
|
|
159
|
+
id: string;
|
|
160
|
+
status: string;
|
|
161
|
+
accepted?: number;
|
|
162
|
+
}
|
|
163
|
+
export interface SdkConfig {
|
|
164
|
+
apiKey: string;
|
|
165
|
+
projectId: string;
|
|
166
|
+
endpoint?: string;
|
|
167
|
+
environment?: string;
|
|
168
|
+
release?: string;
|
|
169
|
+
debug?: boolean;
|
|
170
|
+
sampling?: TelemetrySamplingConfig;
|
|
171
|
+
beforeSend?: (event: IngestEvent) => IngestEvent | null;
|
|
172
|
+
maxBreadcrumbs?: number;
|
|
173
|
+
resourceAttributes?: Record<string, string>;
|
|
174
|
+
autoFlushIntervalMs?: number;
|
|
175
|
+
}
|
package/dist/autocapture.d.ts
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Auto-capture breadcrumbs
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Categories:
|
|
9
|
-
* - "navigation" — route changes (pushState, replaceState, popstate)
|
|
10
|
-
* - "ui.click" — user clicks on elements
|
|
11
|
-
* - "fetch" — failed fetch requests (4xx/5xx)
|
|
12
|
-
* - "console" — console.error / console.warn calls
|
|
2
|
+
* Auto-capture breadcrumbs. Categories emitted:
|
|
3
|
+
* - "navigation" — pushState/replaceState/popstate
|
|
4
|
+
* - "ui.click" — clicks on elements
|
|
5
|
+
* - "fetch" — 4xx/5xx fetch responses
|
|
6
|
+
* - "console" — console.error / console.warn calls
|
|
13
7
|
*/
|
|
14
|
-
import type
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
8
|
+
import { type BreadcrumbCallback } from "./console-capture.js";
|
|
9
|
+
import type { BrowserErrorEvent } from "./types.js";
|
|
10
|
+
export type { BreadcrumbCallback } from "./console-capture.js";
|
|
11
|
+
export interface AutocaptureOptions {
|
|
12
|
+
captureBreadcrumbs?: boolean;
|
|
13
|
+
onConsoleError?: (event: BrowserErrorEvent) => void;
|
|
14
|
+
}
|
|
15
|
+
/** Installs all hooks. Returned function removes them and restores originals. */
|
|
16
|
+
export declare function installAutocapture(onBreadcrumb: BreadcrumbCallback, options?: AutocaptureOptions): () => void;
|
package/dist/autocapture.js
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Auto-capture breadcrumbs
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Categories:
|
|
9
|
-
* - "navigation" — route changes (pushState, replaceState, popstate)
|
|
10
|
-
* - "ui.click" — user clicks on elements
|
|
11
|
-
* - "fetch" — failed fetch requests (4xx/5xx)
|
|
12
|
-
* - "console" — console.error / console.warn calls
|
|
2
|
+
* Auto-capture breadcrumbs. Categories emitted:
|
|
3
|
+
* - "navigation" — pushState/replaceState/popstate
|
|
4
|
+
* - "ui.click" — clicks on elements
|
|
5
|
+
* - "fetch" — 4xx/5xx fetch responses
|
|
6
|
+
* - "console" — console.error / console.warn calls
|
|
13
7
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*/
|
|
18
|
-
export function installAutocapture(onBreadcrumb) {
|
|
8
|
+
import { attemptAsync } from "./_vendor/result-runtime/attempt.js";
|
|
9
|
+
import { readRuntimeProperty, readRuntimeString } from "./_vendor/sdk-runtime/runtime/public-sdk-runtime.js";
|
|
10
|
+
import { captureConsole } from "./console-capture.js";
|
|
11
|
+
/** Installs all hooks. Returned function removes them and restores originals. */
|
|
12
|
+
export function installAutocapture(onBreadcrumb, options = {}) {
|
|
19
13
|
const cleanups = [];
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
const captureBreadcrumbs = options.captureBreadcrumbs ?? true;
|
|
15
|
+
if (captureBreadcrumbs) {
|
|
16
|
+
cleanups.push(captureNavigation(onBreadcrumb));
|
|
17
|
+
cleanups.push(captureClicks(onBreadcrumb));
|
|
18
|
+
cleanups.push(captureFetch(onBreadcrumb));
|
|
19
|
+
}
|
|
20
|
+
if (captureBreadcrumbs || options.onConsoleError) {
|
|
21
|
+
cleanups.push(captureConsole(onBreadcrumb, {
|
|
22
|
+
captureBreadcrumbs,
|
|
23
|
+
onConsoleError: options.onConsoleError,
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
24
26
|
return () => {
|
|
25
27
|
for (const cleanup of cleanups) {
|
|
26
28
|
cleanup();
|
|
@@ -43,13 +45,13 @@ function captureNavigation(onBreadcrumb) {
|
|
|
43
45
|
};
|
|
44
46
|
// Patch history.pushState
|
|
45
47
|
const origPushState = history.pushState.bind(history);
|
|
46
|
-
history.pushState =
|
|
48
|
+
history.pushState = (...args) => {
|
|
47
49
|
origPushState(...args);
|
|
48
50
|
emitNavCrumb();
|
|
49
51
|
};
|
|
50
52
|
// Patch history.replaceState
|
|
51
53
|
const origReplaceState = history.replaceState.bind(history);
|
|
52
|
-
history.replaceState =
|
|
54
|
+
history.replaceState = (...args) => {
|
|
53
55
|
origReplaceState(...args);
|
|
54
56
|
emitNavCrumb();
|
|
55
57
|
};
|
|
@@ -65,20 +67,21 @@ function captureNavigation(onBreadcrumb) {
|
|
|
65
67
|
// ─── Clicks ─────────────────────────────────────────────────────────────
|
|
66
68
|
function captureClicks(onBreadcrumb) {
|
|
67
69
|
const handler = (event) => {
|
|
68
|
-
const target = event.target;
|
|
70
|
+
const target = readClickTarget(event.target);
|
|
69
71
|
if (!target)
|
|
70
72
|
return;
|
|
71
73
|
const descriptor = describeElement(target);
|
|
72
74
|
if (!descriptor)
|
|
73
75
|
return;
|
|
76
|
+
const data = { tag: target.tagName.toLowerCase() };
|
|
77
|
+
if (target.id)
|
|
78
|
+
data.id = target.id;
|
|
79
|
+
if (target.className)
|
|
80
|
+
data.className = target.className;
|
|
74
81
|
onBreadcrumb({
|
|
75
82
|
category: "ui.click",
|
|
76
83
|
message: descriptor,
|
|
77
|
-
data
|
|
78
|
-
tag: target.tagName?.toLowerCase(),
|
|
79
|
-
id: target.id || undefined,
|
|
80
|
-
className: target.className || undefined,
|
|
81
|
-
},
|
|
84
|
+
data,
|
|
82
85
|
});
|
|
83
86
|
};
|
|
84
87
|
// Use capture phase to catch clicks even if stopPropagation is called
|
|
@@ -87,27 +90,35 @@ function captureClicks(onBreadcrumb) {
|
|
|
87
90
|
document.removeEventListener("click", handler, true);
|
|
88
91
|
};
|
|
89
92
|
}
|
|
93
|
+
function readClickTarget(target) {
|
|
94
|
+
const tagName = readRuntimeString(readRuntimeProperty(target, "tagName"));
|
|
95
|
+
if (!tagName)
|
|
96
|
+
return null;
|
|
97
|
+
return {
|
|
98
|
+
className: readRuntimeString(readRuntimeProperty(target, "className")) ?? "",
|
|
99
|
+
id: readRuntimeString(readRuntimeProperty(target, "id")) ?? "",
|
|
100
|
+
tagName,
|
|
101
|
+
textContent: readRuntimeString(readRuntimeProperty(target, "textContent")) ?? "",
|
|
102
|
+
};
|
|
103
|
+
}
|
|
90
104
|
/**
|
|
91
105
|
* Build a human-readable descriptor for a DOM element.
|
|
92
106
|
* e.g. "button#submit-btn.primary" or "a.nav-link"
|
|
93
107
|
*/
|
|
94
108
|
function describeElement(el) {
|
|
95
|
-
const tag = el.tagName
|
|
96
|
-
if (!tag)
|
|
97
|
-
return null;
|
|
109
|
+
const tag = el.tagName.toLowerCase();
|
|
98
110
|
let desc = tag;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
desc += `#${htmlEl.id}`;
|
|
111
|
+
if (el.id) {
|
|
112
|
+
desc += `#${el.id}`;
|
|
102
113
|
}
|
|
103
|
-
if (
|
|
104
|
-
const classes =
|
|
114
|
+
if (el.className) {
|
|
115
|
+
const classes = el.className.trim().split(/\s+/).slice(0, 2).join(".");
|
|
105
116
|
if (classes) {
|
|
106
117
|
desc += `.${classes}`;
|
|
107
118
|
}
|
|
108
119
|
}
|
|
109
120
|
// Add text content for buttons/links (truncated)
|
|
110
|
-
const textContent =
|
|
121
|
+
const textContent = el.textContent?.trim();
|
|
111
122
|
if (textContent && (tag === "button" || tag === "a")) {
|
|
112
123
|
const truncated = textContent.length > 30 ? `${textContent.slice(0, 30)}...` : textContent;
|
|
113
124
|
desc += `[${truncated}]`;
|
|
@@ -116,76 +127,47 @@ function describeElement(el) {
|
|
|
116
127
|
}
|
|
117
128
|
// ─── Fetch ──────────────────────────────────────────────────────────────
|
|
118
129
|
function captureFetch(onBreadcrumb) {
|
|
119
|
-
if (
|
|
130
|
+
if (!globalThis.window?.fetch)
|
|
120
131
|
return () => { };
|
|
121
132
|
const origFetch = window.fetch.bind(window);
|
|
122
|
-
window.fetch = async
|
|
133
|
+
window.fetch = async (input, init) => {
|
|
123
134
|
const method = init?.method?.toUpperCase() || "GET";
|
|
124
|
-
const url =
|
|
125
|
-
|
|
126
|
-
:
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
const url = input instanceof URL ? input.href : input instanceof Request ? input.url : String(input);
|
|
136
|
+
return attemptAsync({
|
|
137
|
+
try: async () => {
|
|
138
|
+
const response = await origFetch(input, init);
|
|
139
|
+
// Only breadcrumb on error responses (4xx/5xx)
|
|
140
|
+
if (response.status >= 400) {
|
|
141
|
+
onBreadcrumb({
|
|
142
|
+
category: "fetch",
|
|
143
|
+
message: `${method} ${url} [${response.status}]`,
|
|
144
|
+
level: response.status >= 500 ? "error" : "warning",
|
|
145
|
+
data: {
|
|
146
|
+
method,
|
|
147
|
+
url,
|
|
148
|
+
status: response.status,
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return response;
|
|
153
|
+
},
|
|
154
|
+
catch: ({ cause, error }) => {
|
|
155
|
+
// Network error
|
|
135
156
|
onBreadcrumb({
|
|
136
157
|
category: "fetch",
|
|
137
|
-
message: `${method} ${url} [
|
|
138
|
-
level:
|
|
158
|
+
message: `${method} ${url} [network error]`,
|
|
159
|
+
level: "error",
|
|
139
160
|
data: {
|
|
140
161
|
method,
|
|
141
162
|
url,
|
|
142
|
-
|
|
163
|
+
error: error.message,
|
|
143
164
|
},
|
|
144
165
|
});
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
catch (error) {
|
|
149
|
-
// Network error
|
|
150
|
-
onBreadcrumb({
|
|
151
|
-
category: "fetch",
|
|
152
|
-
message: `${method} ${url} [network error]`,
|
|
153
|
-
level: "error",
|
|
154
|
-
data: {
|
|
155
|
-
method,
|
|
156
|
-
url,
|
|
157
|
-
error: error instanceof Error ? error.message : String(error),
|
|
158
|
-
},
|
|
159
|
-
});
|
|
160
|
-
throw error;
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
return () => {
|
|
164
|
-
window.fetch = origFetch;
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
// ─── Console ────────────────────────────────────────────────────────────
|
|
168
|
-
function captureConsole(onBreadcrumb) {
|
|
169
|
-
const origError = console.error.bind(console);
|
|
170
|
-
const origWarn = console.warn.bind(console);
|
|
171
|
-
console.error = (...args) => {
|
|
172
|
-
onBreadcrumb({
|
|
173
|
-
category: "console",
|
|
174
|
-
message: args.map(String).join(" ").slice(0, 200),
|
|
175
|
-
level: "error",
|
|
176
|
-
});
|
|
177
|
-
origError(...args);
|
|
178
|
-
};
|
|
179
|
-
console.warn = (...args) => {
|
|
180
|
-
onBreadcrumb({
|
|
181
|
-
category: "console",
|
|
182
|
-
message: args.map(String).join(" ").slice(0, 200),
|
|
183
|
-
level: "warning",
|
|
166
|
+
throw cause;
|
|
167
|
+
},
|
|
184
168
|
});
|
|
185
|
-
origWarn(...args);
|
|
186
169
|
};
|
|
187
170
|
return () => {
|
|
188
|
-
|
|
189
|
-
console.warn = origWarn;
|
|
171
|
+
window.fetch = origFetch;
|
|
190
172
|
};
|
|
191
173
|
}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Manages:
|
|
5
|
-
* - Configuration with sensible defaults
|
|
6
|
-
* - User context, tags, and breadcrumbs
|
|
7
|
-
* - Web Vitals collection (via vitals.ts)
|
|
8
|
-
* - Global error capture (via errors.ts)
|
|
9
|
-
* - Auto-capture breadcrumbs (via autocapture.ts)
|
|
10
|
-
* - Transport (via transport.ts)
|
|
11
|
-
*/
|
|
12
|
-
import type { Breadcrumb, BrowserConfig, BrowserErrorEvent, JsonObject, Level, UserContext } from "./types";
|
|
1
|
+
import { type BrowserClientRuntime } from "./runtime/client.js";
|
|
2
|
+
import type { Breadcrumb, BrowserConfig, BrowserErrorEvent, JsonObject, Level, UserContext } from "./types.js";
|
|
3
|
+
import { type ExternalVitalInput } from "./vitals.js";
|
|
13
4
|
export declare class BrowserClient {
|
|
14
5
|
private config;
|
|
15
6
|
private transport;
|
|
@@ -19,12 +10,13 @@ export declare class BrowserClient {
|
|
|
19
10
|
private disabled;
|
|
20
11
|
private cleanups;
|
|
21
12
|
private replayRecorder;
|
|
22
|
-
|
|
13
|
+
private vitalsHandle;
|
|
14
|
+
constructor(config: BrowserConfig, runtime?: BrowserClientRuntime);
|
|
23
15
|
setUser(user: UserContext | undefined): void;
|
|
24
16
|
setTag(key: string, value: string): void;
|
|
25
17
|
setTags(tags: Record<string, string>): void;
|
|
26
18
|
addBreadcrumb(crumb: Omit<Breadcrumb, "timestamp">): void;
|
|
27
|
-
captureError(error: Error, extra?:
|
|
19
|
+
captureError(error: Error, extra?: JsonObject): void;
|
|
28
20
|
captureMessage(message: string, level?: Level): void;
|
|
29
21
|
captureTelemetry(event: BrowserErrorEvent): void;
|
|
30
22
|
track(eventName: string, properties?: JsonObject, context?: Partial<BrowserErrorEvent>): void;
|
|
@@ -34,13 +26,13 @@ export declare class BrowserClient {
|
|
|
34
26
|
captureSpan(name: string, context?: Partial<BrowserErrorEvent>): void;
|
|
35
27
|
captureToolCall(name: string, context?: Partial<BrowserErrorEvent>): void;
|
|
36
28
|
captureGeneration(message: string, context?: Partial<BrowserErrorEvent>): void;
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
/** Record a web vital from an external collector (e.g. Next.js `useReportWebVitals`). */
|
|
30
|
+
recordWebVital(metric: ExternalVitalInput, route?: string): void;
|
|
31
|
+
/** Stop the SDK's native `web-vitals` collector to avoid double-counting. */
|
|
32
|
+
suppressNativeVitalsCollection(): void;
|
|
33
|
+
private vitalsConfig;
|
|
34
|
+
/** Flush vitals and stop timers. Call before unmounting a SPA. */
|
|
41
35
|
close(): void;
|
|
42
|
-
private shouldSample;
|
|
43
36
|
/** Enrich an error event with current context and send it. */
|
|
44
37
|
private sendErrorEvent;
|
|
45
38
|
}
|
|
46
|
-
//# sourceMappingURL=client.d.ts.map
|