@chrom-ar/collector 0.3.0 → 0.4.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/CHANGELOG.md +19 -1
- package/README.md +65 -0
- package/dist/chunk-YN5N3X7X.js +56 -0
- package/dist/index.cjs +177 -15
- package/dist/index.d.cts +16 -111
- package/dist/index.d.ts +16 -111
- package/dist/index.js +168 -61
- package/dist/rum.cjs +615 -0
- package/dist/rum.d.cts +57 -0
- package/dist/rum.d.ts +57 -0
- package/dist/rum.js +591 -0
- package/dist/types-CTnanJxh.d.cts +178 -0
- package/dist/types-CTnanJxh.d.ts +178 -0
- package/package.json +11 -1
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
interface Logger {
|
|
2
|
+
debug: (...args: unknown[]) => void;
|
|
3
|
+
/** For misconfigurations the developer must see, even without `debug`. Once per message. */
|
|
4
|
+
warnOnce: (message: string) => void;
|
|
5
|
+
/** Always shown, for answers to something the developer asked for (like `test()`). */
|
|
6
|
+
info: (message: string) => void;
|
|
7
|
+
warn: (message: string) => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** How bad an event is. Collector accepts exactly these four. */
|
|
11
|
+
type Level = "fatal" | "error" | "warning" | "info";
|
|
12
|
+
/** One stack frame, innermost first, as the protocol defines it. */
|
|
13
|
+
interface Frame {
|
|
14
|
+
/** Script path with content hashes removed, e.g. `/assets/index.js`. Used for grouping. */
|
|
15
|
+
module: string;
|
|
16
|
+
/** Function name, or `"?"` for anonymous functions. */
|
|
17
|
+
function: string;
|
|
18
|
+
/** Script path as loaded, e.g. `/assets/index-a1b2c3d4.js`. Shown, not grouped on. */
|
|
19
|
+
file: string;
|
|
20
|
+
line?: number;
|
|
21
|
+
column?: number;
|
|
22
|
+
/** True for the app's own code; this decides how errors group into issues. */
|
|
23
|
+
in_app: boolean;
|
|
24
|
+
}
|
|
25
|
+
/** Something that happened before an error: a click, a request, a log line. */
|
|
26
|
+
interface Breadcrumb {
|
|
27
|
+
/** ISO 8601; set to now when missing. */
|
|
28
|
+
timestamp?: string;
|
|
29
|
+
level?: Level;
|
|
30
|
+
/** e.g. `ui.click`, `fetch`, `xhr`, `navigation`, `console`. */
|
|
31
|
+
category?: string;
|
|
32
|
+
message: string;
|
|
33
|
+
}
|
|
34
|
+
/** One fetch or XHR call, as the RUM plugin sees it. Times are `performance.now()` ms. */
|
|
35
|
+
interface RequestTiming {
|
|
36
|
+
method: string;
|
|
37
|
+
/** Absolute, without credentials, query or fragment. */
|
|
38
|
+
url: string;
|
|
39
|
+
/** `0` when there was no answer. */
|
|
40
|
+
status: number;
|
|
41
|
+
start: number;
|
|
42
|
+
end: number;
|
|
43
|
+
}
|
|
44
|
+
/** What the core hands the RUM plugin when it starts. */
|
|
45
|
+
interface RumContext {
|
|
46
|
+
win: Window;
|
|
47
|
+
/** `POST` URL for page views, key included. */
|
|
48
|
+
url: string;
|
|
49
|
+
/** The unwrapped `fetch`, so RUM's own requests are never measured. */
|
|
50
|
+
fetch: typeof fetch;
|
|
51
|
+
logger: Logger;
|
|
52
|
+
options: CollectorOptions;
|
|
53
|
+
sdk: {
|
|
54
|
+
name: string;
|
|
55
|
+
version: string;
|
|
56
|
+
};
|
|
57
|
+
environment: string | undefined;
|
|
58
|
+
release: string | undefined;
|
|
59
|
+
}
|
|
60
|
+
/** A running RUM plugin, as the core drives it. */
|
|
61
|
+
interface RumHandle {
|
|
62
|
+
/** The tab's session id, only when RUM sampled this tab. Events carry it. */
|
|
63
|
+
readonly session: string | undefined;
|
|
64
|
+
/** A request started. What it returns comes back with its `request()` when it ends. */
|
|
65
|
+
requestStart: () => unknown;
|
|
66
|
+
request: (timing: RequestTiming, token?: unknown) => void;
|
|
67
|
+
/** The URL may have changed (pushState, replaceState, popstate). */
|
|
68
|
+
navigate: () => void;
|
|
69
|
+
setRoute: (name: string | undefined) => void;
|
|
70
|
+
close: () => void;
|
|
71
|
+
}
|
|
72
|
+
/** What `rum()` from `@chrom-ar/collector/rum` returns, for `init({ rum })`. */
|
|
73
|
+
interface RumPlugin {
|
|
74
|
+
start: (ctx: RumContext) => RumHandle;
|
|
75
|
+
}
|
|
76
|
+
/** An event as sent to Collector (protocol v1). */
|
|
77
|
+
interface CollectorEvent {
|
|
78
|
+
v: 1;
|
|
79
|
+
uuid: string;
|
|
80
|
+
timestamp: string;
|
|
81
|
+
platform: "javascript";
|
|
82
|
+
level: Level;
|
|
83
|
+
environment?: string;
|
|
84
|
+
release?: string;
|
|
85
|
+
exception?: {
|
|
86
|
+
type: string;
|
|
87
|
+
message?: string;
|
|
88
|
+
frames?: Frame[];
|
|
89
|
+
};
|
|
90
|
+
message?: string;
|
|
91
|
+
fingerprint?: string[];
|
|
92
|
+
request?: {
|
|
93
|
+
url: string;
|
|
94
|
+
headers: Record<string, string>;
|
|
95
|
+
};
|
|
96
|
+
user?: {
|
|
97
|
+
id: string;
|
|
98
|
+
};
|
|
99
|
+
tags?: Record<string, string>;
|
|
100
|
+
breadcrumbs?: Breadcrumb[];
|
|
101
|
+
sdk: {
|
|
102
|
+
name: string;
|
|
103
|
+
version: string;
|
|
104
|
+
};
|
|
105
|
+
/** The tab's RUM session, so the error links to its visit. Only from tabs RUM sampled. */
|
|
106
|
+
session?: string;
|
|
107
|
+
}
|
|
108
|
+
/** Extra details for one captured event. They merge over what `setUser`/`setTag` set. */
|
|
109
|
+
interface CaptureContext {
|
|
110
|
+
level?: Level;
|
|
111
|
+
tags?: Record<string, string>;
|
|
112
|
+
/** Overrides how Collector groups this event into an issue. */
|
|
113
|
+
fingerprint?: string[];
|
|
114
|
+
user?: {
|
|
115
|
+
id: string | number;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/** What `test()` resolves to: the event's id, or why it wasn't accepted. */
|
|
119
|
+
type TestResult = {
|
|
120
|
+
ok: true;
|
|
121
|
+
id: string;
|
|
122
|
+
} | {
|
|
123
|
+
ok: false;
|
|
124
|
+
reason: string;
|
|
125
|
+
};
|
|
126
|
+
type BreadcrumbKind = "console" | "dom" | "fetch" | "xhr" | "history";
|
|
127
|
+
interface CollectorOptions {
|
|
128
|
+
/** Your project's DSN, from its setup page in Collector. Without it, nothing is sent. */
|
|
129
|
+
dsn?: string;
|
|
130
|
+
/** e.g. `"production"`, `"staging"`. Issues are counted per environment. */
|
|
131
|
+
environment?: string;
|
|
132
|
+
/** Your app's version or git sha, e.g. `"web@1.4.2"`. */
|
|
133
|
+
release?: string;
|
|
134
|
+
/** Logs what the SDK does to the console, prefixed `[collector]`. Default `false`. */
|
|
135
|
+
debug?: boolean;
|
|
136
|
+
/** Set to `false` to turn the SDK off entirely. Default `true`. */
|
|
137
|
+
enabled?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Last chance to edit or drop an event before it's sent. Return the event
|
|
140
|
+
* (changed or not) to send it, or `null` to drop it.
|
|
141
|
+
*/
|
|
142
|
+
beforeSend?: (event: CollectorEvent) => CollectorEvent | null;
|
|
143
|
+
/**
|
|
144
|
+
* Errors to ignore: strings match anywhere in `"Type: message"`, regexps are
|
|
145
|
+
* tested against it. Added to the built-in list of well-known browser noise.
|
|
146
|
+
*/
|
|
147
|
+
ignoreErrors?: (string | RegExp)[];
|
|
148
|
+
/**
|
|
149
|
+
* Which script URLs are your app's own code. When set, a frame is in-app only
|
|
150
|
+
* if its URL matches. Default: same origin as the page, except vendor chunks.
|
|
151
|
+
*/
|
|
152
|
+
inAppUrls?: (string | RegExp)[];
|
|
153
|
+
/** Remove `?query` and `#hash` from URLs sent to Collector. Default `true`. */
|
|
154
|
+
stripQuery?: boolean;
|
|
155
|
+
/** Which breadcrumbs to record automatically. All on by default. */
|
|
156
|
+
breadcrumbs?: Partial<Record<BreadcrumbKind, boolean>>;
|
|
157
|
+
/** How many breadcrumbs to keep. Default `50`. */
|
|
158
|
+
maxBreadcrumbs?: number;
|
|
159
|
+
/**
|
|
160
|
+
* Tell Collector once a day that the app is running (its release and
|
|
161
|
+
* environment, nothing about the user), so it shows as set up before any
|
|
162
|
+
* error. Default `true`.
|
|
163
|
+
*/
|
|
164
|
+
heartbeat?: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Real User Monitoring, off by default. Import it separately so apps
|
|
167
|
+
* without it don't ship it: `import { rum } from "@chrom-ar/collector/rum"`,
|
|
168
|
+
* then `init({ rum: rum({ sampleRate: 0.1 }) })`.
|
|
169
|
+
*/
|
|
170
|
+
rum?: RumPlugin;
|
|
171
|
+
/** Report uncaught errors and unhandled promise rejections. Default: both on. */
|
|
172
|
+
autoCapture?: false | {
|
|
173
|
+
onerror?: boolean;
|
|
174
|
+
onunhandledrejection?: boolean;
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export type { Breadcrumb as B, CaptureContext as C, Frame as F, Level as L, RequestTiming as R, TestResult as T, CollectorOptions as a, BreadcrumbKind as b, CollectorEvent as c, RumContext as d, RumHandle as e, RumPlugin as f };
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
interface Logger {
|
|
2
|
+
debug: (...args: unknown[]) => void;
|
|
3
|
+
/** For misconfigurations the developer must see, even without `debug`. Once per message. */
|
|
4
|
+
warnOnce: (message: string) => void;
|
|
5
|
+
/** Always shown, for answers to something the developer asked for (like `test()`). */
|
|
6
|
+
info: (message: string) => void;
|
|
7
|
+
warn: (message: string) => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** How bad an event is. Collector accepts exactly these four. */
|
|
11
|
+
type Level = "fatal" | "error" | "warning" | "info";
|
|
12
|
+
/** One stack frame, innermost first, as the protocol defines it. */
|
|
13
|
+
interface Frame {
|
|
14
|
+
/** Script path with content hashes removed, e.g. `/assets/index.js`. Used for grouping. */
|
|
15
|
+
module: string;
|
|
16
|
+
/** Function name, or `"?"` for anonymous functions. */
|
|
17
|
+
function: string;
|
|
18
|
+
/** Script path as loaded, e.g. `/assets/index-a1b2c3d4.js`. Shown, not grouped on. */
|
|
19
|
+
file: string;
|
|
20
|
+
line?: number;
|
|
21
|
+
column?: number;
|
|
22
|
+
/** True for the app's own code; this decides how errors group into issues. */
|
|
23
|
+
in_app: boolean;
|
|
24
|
+
}
|
|
25
|
+
/** Something that happened before an error: a click, a request, a log line. */
|
|
26
|
+
interface Breadcrumb {
|
|
27
|
+
/** ISO 8601; set to now when missing. */
|
|
28
|
+
timestamp?: string;
|
|
29
|
+
level?: Level;
|
|
30
|
+
/** e.g. `ui.click`, `fetch`, `xhr`, `navigation`, `console`. */
|
|
31
|
+
category?: string;
|
|
32
|
+
message: string;
|
|
33
|
+
}
|
|
34
|
+
/** One fetch or XHR call, as the RUM plugin sees it. Times are `performance.now()` ms. */
|
|
35
|
+
interface RequestTiming {
|
|
36
|
+
method: string;
|
|
37
|
+
/** Absolute, without credentials, query or fragment. */
|
|
38
|
+
url: string;
|
|
39
|
+
/** `0` when there was no answer. */
|
|
40
|
+
status: number;
|
|
41
|
+
start: number;
|
|
42
|
+
end: number;
|
|
43
|
+
}
|
|
44
|
+
/** What the core hands the RUM plugin when it starts. */
|
|
45
|
+
interface RumContext {
|
|
46
|
+
win: Window;
|
|
47
|
+
/** `POST` URL for page views, key included. */
|
|
48
|
+
url: string;
|
|
49
|
+
/** The unwrapped `fetch`, so RUM's own requests are never measured. */
|
|
50
|
+
fetch: typeof fetch;
|
|
51
|
+
logger: Logger;
|
|
52
|
+
options: CollectorOptions;
|
|
53
|
+
sdk: {
|
|
54
|
+
name: string;
|
|
55
|
+
version: string;
|
|
56
|
+
};
|
|
57
|
+
environment: string | undefined;
|
|
58
|
+
release: string | undefined;
|
|
59
|
+
}
|
|
60
|
+
/** A running RUM plugin, as the core drives it. */
|
|
61
|
+
interface RumHandle {
|
|
62
|
+
/** The tab's session id, only when RUM sampled this tab. Events carry it. */
|
|
63
|
+
readonly session: string | undefined;
|
|
64
|
+
/** A request started. What it returns comes back with its `request()` when it ends. */
|
|
65
|
+
requestStart: () => unknown;
|
|
66
|
+
request: (timing: RequestTiming, token?: unknown) => void;
|
|
67
|
+
/** The URL may have changed (pushState, replaceState, popstate). */
|
|
68
|
+
navigate: () => void;
|
|
69
|
+
setRoute: (name: string | undefined) => void;
|
|
70
|
+
close: () => void;
|
|
71
|
+
}
|
|
72
|
+
/** What `rum()` from `@chrom-ar/collector/rum` returns, for `init({ rum })`. */
|
|
73
|
+
interface RumPlugin {
|
|
74
|
+
start: (ctx: RumContext) => RumHandle;
|
|
75
|
+
}
|
|
76
|
+
/** An event as sent to Collector (protocol v1). */
|
|
77
|
+
interface CollectorEvent {
|
|
78
|
+
v: 1;
|
|
79
|
+
uuid: string;
|
|
80
|
+
timestamp: string;
|
|
81
|
+
platform: "javascript";
|
|
82
|
+
level: Level;
|
|
83
|
+
environment?: string;
|
|
84
|
+
release?: string;
|
|
85
|
+
exception?: {
|
|
86
|
+
type: string;
|
|
87
|
+
message?: string;
|
|
88
|
+
frames?: Frame[];
|
|
89
|
+
};
|
|
90
|
+
message?: string;
|
|
91
|
+
fingerprint?: string[];
|
|
92
|
+
request?: {
|
|
93
|
+
url: string;
|
|
94
|
+
headers: Record<string, string>;
|
|
95
|
+
};
|
|
96
|
+
user?: {
|
|
97
|
+
id: string;
|
|
98
|
+
};
|
|
99
|
+
tags?: Record<string, string>;
|
|
100
|
+
breadcrumbs?: Breadcrumb[];
|
|
101
|
+
sdk: {
|
|
102
|
+
name: string;
|
|
103
|
+
version: string;
|
|
104
|
+
};
|
|
105
|
+
/** The tab's RUM session, so the error links to its visit. Only from tabs RUM sampled. */
|
|
106
|
+
session?: string;
|
|
107
|
+
}
|
|
108
|
+
/** Extra details for one captured event. They merge over what `setUser`/`setTag` set. */
|
|
109
|
+
interface CaptureContext {
|
|
110
|
+
level?: Level;
|
|
111
|
+
tags?: Record<string, string>;
|
|
112
|
+
/** Overrides how Collector groups this event into an issue. */
|
|
113
|
+
fingerprint?: string[];
|
|
114
|
+
user?: {
|
|
115
|
+
id: string | number;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/** What `test()` resolves to: the event's id, or why it wasn't accepted. */
|
|
119
|
+
type TestResult = {
|
|
120
|
+
ok: true;
|
|
121
|
+
id: string;
|
|
122
|
+
} | {
|
|
123
|
+
ok: false;
|
|
124
|
+
reason: string;
|
|
125
|
+
};
|
|
126
|
+
type BreadcrumbKind = "console" | "dom" | "fetch" | "xhr" | "history";
|
|
127
|
+
interface CollectorOptions {
|
|
128
|
+
/** Your project's DSN, from its setup page in Collector. Without it, nothing is sent. */
|
|
129
|
+
dsn?: string;
|
|
130
|
+
/** e.g. `"production"`, `"staging"`. Issues are counted per environment. */
|
|
131
|
+
environment?: string;
|
|
132
|
+
/** Your app's version or git sha, e.g. `"web@1.4.2"`. */
|
|
133
|
+
release?: string;
|
|
134
|
+
/** Logs what the SDK does to the console, prefixed `[collector]`. Default `false`. */
|
|
135
|
+
debug?: boolean;
|
|
136
|
+
/** Set to `false` to turn the SDK off entirely. Default `true`. */
|
|
137
|
+
enabled?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Last chance to edit or drop an event before it's sent. Return the event
|
|
140
|
+
* (changed or not) to send it, or `null` to drop it.
|
|
141
|
+
*/
|
|
142
|
+
beforeSend?: (event: CollectorEvent) => CollectorEvent | null;
|
|
143
|
+
/**
|
|
144
|
+
* Errors to ignore: strings match anywhere in `"Type: message"`, regexps are
|
|
145
|
+
* tested against it. Added to the built-in list of well-known browser noise.
|
|
146
|
+
*/
|
|
147
|
+
ignoreErrors?: (string | RegExp)[];
|
|
148
|
+
/**
|
|
149
|
+
* Which script URLs are your app's own code. When set, a frame is in-app only
|
|
150
|
+
* if its URL matches. Default: same origin as the page, except vendor chunks.
|
|
151
|
+
*/
|
|
152
|
+
inAppUrls?: (string | RegExp)[];
|
|
153
|
+
/** Remove `?query` and `#hash` from URLs sent to Collector. Default `true`. */
|
|
154
|
+
stripQuery?: boolean;
|
|
155
|
+
/** Which breadcrumbs to record automatically. All on by default. */
|
|
156
|
+
breadcrumbs?: Partial<Record<BreadcrumbKind, boolean>>;
|
|
157
|
+
/** How many breadcrumbs to keep. Default `50`. */
|
|
158
|
+
maxBreadcrumbs?: number;
|
|
159
|
+
/**
|
|
160
|
+
* Tell Collector once a day that the app is running (its release and
|
|
161
|
+
* environment, nothing about the user), so it shows as set up before any
|
|
162
|
+
* error. Default `true`.
|
|
163
|
+
*/
|
|
164
|
+
heartbeat?: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Real User Monitoring, off by default. Import it separately so apps
|
|
167
|
+
* without it don't ship it: `import { rum } from "@chrom-ar/collector/rum"`,
|
|
168
|
+
* then `init({ rum: rum({ sampleRate: 0.1 }) })`.
|
|
169
|
+
*/
|
|
170
|
+
rum?: RumPlugin;
|
|
171
|
+
/** Report uncaught errors and unhandled promise rejections. Default: both on. */
|
|
172
|
+
autoCapture?: false | {
|
|
173
|
+
onerror?: boolean;
|
|
174
|
+
onunhandledrejection?: boolean;
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export type { Breadcrumb as B, CaptureContext as C, Frame as F, Level as L, RequestTiming as R, TestResult as T, CollectorOptions as a, BreadcrumbKind as b, CollectorEvent as c, RumContext as d, RumHandle as e, RumPlugin as f };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chrom-ar/collector",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Reports your browser app's errors to Collector.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"error-tracking",
|
|
@@ -32,6 +32,16 @@
|
|
|
32
32
|
"default": "./dist/index.cjs"
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
|
+
"./rum": {
|
|
36
|
+
"import": {
|
|
37
|
+
"types": "./dist/rum.d.ts",
|
|
38
|
+
"default": "./dist/rum.js"
|
|
39
|
+
},
|
|
40
|
+
"require": {
|
|
41
|
+
"types": "./dist/rum.d.cts",
|
|
42
|
+
"default": "./dist/rum.cjs"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
35
45
|
"./package.json": "./package.json"
|
|
36
46
|
},
|
|
37
47
|
"files": [
|