@chrom-ar/collector 0.0.0-stage → 0.2.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 ADDED
@@ -0,0 +1,32 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 (unreleased)
4
+
5
+ - Source maps: `init()` uses the release injected by
6
+ `@chrom-ar/collector-cli/vite` (the `__COLLECTOR_RELEASE__` build constant)
7
+ when you don't pass `release`, so events match the uploaded maps.
8
+ - Firefox errors group with Chrome's and Safari's: its async-stack markers
9
+ (`EventListener.handleEvent*`, `setTimeout handler*`) are no longer frames.
10
+ - `throw null` and `throw undefined` are reported as `NonError`.
11
+ - Hash-router navigation (`#/orders/7`) shows up in breadcrumbs.
12
+ - webpack dev modules (`webpack-internal:///./src/…`) count as your code, and
13
+ only `vendor/` folders and `vendor…` bundles count as dependencies.
14
+ - A reused `XMLHttpRequest` no longer repeats old breadcrumbs.
15
+ - After Collector rejects the DSN (401/403), re-initializing (e.g. hot reload)
16
+ doesn't send again.
17
+ - Events dropped by `beforeSend` don't count toward the 30-per-10-seconds cap.
18
+
19
+ ## 0.1.0 (unreleased)
20
+
21
+ First release.
22
+
23
+ - Reports uncaught errors and unhandled promise rejections.
24
+ - `captureException`, `captureMessage`, `setUser`, `setTag`, `setTags`,
25
+ `addBreadcrumb`, `flush`, `close`.
26
+ - Breadcrumbs for clicks, navigation, fetch, XHR and console.
27
+ - Stack traces from Chrome, Firefox and Safari, with in-app detection and
28
+ hash-free module names for stable grouping across deploys.
29
+ - Drops duplicate events, caps a page at 30 events every 10 seconds, retries
30
+ on server errors, and honors `Retry-After`.
31
+ - Privacy defaults: query strings stripped from URLs, no cookies or headers,
32
+ `beforeSend` and `ignoreErrors`.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Chroma
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,206 @@
1
- # Temporary Holding Version
1
+ # @chrom-ar/collector
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Reports your browser app's errors to [Collector](https://app.clt.chrom.ar),
4
+ which groups them into issues, emails you when one is new or comes back,
5
+ and shows you what broke and why.
6
+
7
+ Works with any framework (React, Vue, Svelte, Angular, plain pages), has
8
+ no dependencies and weighs about 6 KB gzipped.
9
+
10
+ ## Installation
11
+
12
+ ```sh
13
+ npm install @chrom-ar/collector
14
+ ```
15
+
16
+ Then, as early as possible in your app's entry point (`main.ts`,
17
+ `index.js`, …), before the app renders:
18
+
19
+ ```ts
20
+ import * as Collector from "@chrom-ar/collector";
21
+
22
+ Collector.init({
23
+ dsn: "https://clt_…@app.clt.chrom.ar", // from your project's setup page
24
+ environment: "production",
25
+ release: "web@1.4.2",
26
+ });
27
+ ```
28
+
29
+ That's it. From now on, uncaught errors and unhandled promise rejections
30
+ are reported on their own, along with what happened right before them:
31
+ clicks, navigation, network requests and console messages.
32
+
33
+ The DSN is public: it can only send events, so it's fine in browser code.
34
+ Without a DSN nothing is captured or sent, so dev and tests stay quiet
35
+ when you leave it out:
36
+
37
+ ```ts
38
+ Collector.init({ dsn: import.meta.env.VITE_COLLECTOR_DSN });
39
+ ```
40
+
41
+ `environment` and `release` are optional. Issues are counted per
42
+ environment, and `release` tells you which deploy an error came from.
43
+
44
+ ### New domains
45
+
46
+ The first time events arrive from a new domain, Collector keeps them and
47
+ asks the project's admins whether that domain is yours. If an admin
48
+ blocks it, pages there stop sending, and you'll see this once in the
49
+ browser console:
50
+
51
+ > [collector] This site's domain (https://…) is blocked for this project in Collector (HTTP 403). Events won't be sent from this page.
52
+
53
+ ### Framework notes
54
+
55
+ - **Next.js, Nuxt, SvelteKit and other SSR frameworks:** importing the
56
+ package on the server is safe, and `init` does nothing there. Call it
57
+ from client-only code (e.g. a `"use client"` component's effect, or
58
+ `instrumentation-client.ts` in Next.js).
59
+ - **React:** errors caught by an error boundary aren't uncaught, so
60
+ report them yourself from `componentDidCatch`, or from `onCaughtError`
61
+ in React 19's `createRoot`:
62
+
63
+ ```ts
64
+ createRoot(el, { onCaughtError: (error) => Collector.captureException(error) });
65
+ ```
66
+
67
+ - **Vue:** add `app.config.errorHandler = (error) => Collector.captureException(error);`
68
+
69
+ ## Reporting things yourself
70
+
71
+ ```ts
72
+ try {
73
+ await checkout(cart);
74
+ } catch (error) {
75
+ Collector.captureException(error, { tags: { step: "payment" } });
76
+ showRetry();
77
+ }
78
+
79
+ Collector.captureMessage("Payment gateway slow", "warning");
80
+ ```
81
+
82
+ Both return the event's id, or `undefined` when nothing was sent.
83
+
84
+ ## Users and tags
85
+
86
+ Say who hit the error, by id (an id, not personal data), and add tags to
87
+ filter by:
88
+
89
+ ```ts
90
+ Collector.setUser({ id: currentUser.id });
91
+ Collector.setTag("plan", "pro");
92
+ ```
93
+
94
+ `setUser(null)` clears the user on logout.
95
+
96
+ ## Privacy
97
+
98
+ - Query strings and `#hashes` are removed from every URL sent (the page
99
+ URL and the breadcrumbs). Hash-router routes (`#/orders/7`) are kept in
100
+ navigation breadcrumbs, without their query. Turn it off with
101
+ `stripQuery: false`.
102
+ - Click breadcrumbs describe the element (`form.checkout > button#buy`),
103
+ never its text or input values.
104
+ - Cookies and request headers are never sent, only the user agent.
105
+ Usernames and passwords in URLs are removed.
106
+ - Console breadcrumbs keep a short summary of what was logged: strings
107
+ as they are, errors as `Type: message`, and only the first level of an
108
+ object's keys (`{id: 4812, email: "…"}`). If your app logs personal
109
+ data, turn them off with `breadcrumbs: { console: false }`.
110
+ - `beforeSend` sees every event last, and can edit it or drop it:
111
+
112
+ ```ts
113
+ Collector.init({
114
+ dsn: "…",
115
+ beforeSend(event) {
116
+ if (event.request) event.request.url = event.request.url.replace(/\/users\/\d+/, "/users/:id");
117
+ return event; // or null to drop it
118
+ },
119
+ });
120
+ ```
121
+
122
+ ## Options
123
+
124
+ | Option | Default | |
125
+ |---|---|---|
126
+ | `dsn` | none | Your project's DSN. Without it, nothing is sent |
127
+ | `environment` | none | e.g. `"production"`, `"staging"` |
128
+ | `release` | none | Your app's version or git sha |
129
+ | `debug` | `false` | Logs what the SDK does, prefixed `[collector]` |
130
+ | `enabled` | `true` | `false` turns everything off |
131
+ | `beforeSend` | none | `(event) => event \| null`, to edit or drop events |
132
+ | `ignoreErrors` | browser noise | Strings (matched anywhere in `"Type: message"`) or regexps. Added to the built-in list (`ResizeObserver loop…`, `Script error.`) |
133
+ | `inAppUrls` | same origin | Strings or regexps for script URLs that are your app's own code (see below) |
134
+ | `stripQuery` | `true` | Remove `?query` and `#hash` from URLs |
135
+ | `breadcrumbs` | all on | `{ console, dom, fetch, xhr, history }`, each `true`/`false` |
136
+ | `maxBreadcrumbs` | `50` | How many breadcrumbs to keep |
137
+ | `autoCapture` | both on | `{ onerror, onunhandledrejection }`, or `false` for neither |
138
+
139
+ Other functions: `setTags(tags)`, `addBreadcrumb({ message, category?, level? })`,
140
+ `flush(timeoutMs?)` (waits until queued events are sent) and `close()`
141
+ (removes everything the SDK installed).
142
+
143
+ ## How errors are grouped
144
+
145
+ Collector groups events into issues by the error type and the functions
146
+ in your app's own code that it passed through. The SDK marks a stack
147
+ frame as your code when its script is on the page's own origin (or is a
148
+ webpack dev module, `webpack-internal:///./src/…`) and
149
+ isn't a dependency bundle (`node_modules`, `.vite/deps`, `vendor` chunks,
150
+ Next.js framework chunks). Content hashes in file names are ignored, so
151
+ a new deploy doesn't open new issues. If your scripts come from a CDN,
152
+ say so:
153
+
154
+ ```ts
155
+ Collector.init({ dsn: "…", inAppUrls: ["https://cdn.example.com/app/"] });
156
+ ```
157
+
158
+ ## Source maps
159
+
160
+ Upload your build's source maps and Collector shows your original files,
161
+ lines and function names, and groups errors by them. With Vite, add the
162
+ plugin from [`@chrom-ar/collector-cli`](https://www.npmjs.com/package/@chrom-ar/collector-cli):
163
+
164
+ ```ts
165
+ // vite.config.ts
166
+ import collector from "@chrom-ar/collector-cli/vite";
167
+
168
+ export default defineConfig({ plugins: [collector()] });
169
+ ```
170
+
171
+ Set `COLLECTOR_UPLOAD_TOKEN` (from your project's settings) and
172
+ `COLLECTOR_DSN` in your CI. The plugin uploads the maps at the end of
173
+ `vite build`, removes them from the output, and injects the release, so you
174
+ don't need to pass `release` to `init()`.
175
+
176
+ With another bundler, upload with the CLI before you deploy, and make the
177
+ release match:
178
+
179
+ ```sh
180
+ npx @chrom-ar/collector-cli upload ./dist --release "$GIT_SHA"
181
+ ```
182
+
183
+ Pass the same value to `init({ release })`, or define the
184
+ `__COLLECTOR_RELEASE__` constant at build time (e.g. webpack's
185
+ `new DefinePlugin({ __COLLECTOR_RELEASE__: JSON.stringify(sha) })`).
186
+
187
+ ## What it won't do (yet)
188
+
189
+ - **Minified stack traces without source maps.** Upload them (see
190
+ [Source maps](#source-maps)); without them, frames show the built code
191
+ and the same error can open a new issue after a deploy.
192
+ - **Browsers name functions differently.** The SDK normalizes names
193
+ (`Cart.checkout` in Chrome and `checkout` in Firefox both become
194
+ `checkout`), but Safari sometimes leaves frames out, so the same error
195
+ can occasionally group separately per browser.
196
+ - **Browsers only.** For servers, use a server SDK
197
+ ([Elixir](https://hex.pm/packages/collector)).
198
+
199
+ It never throws into your app, never blocks it, and keeps quiet in the
200
+ console unless something's misconfigured (or you set `debug: true`).
201
+ When an error repeats in a loop, it sends it once; and it sends at most
202
+ 30 events every 10 seconds per page.
203
+
204
+ ## License
205
+
206
+ MIT