@chrom-ar/collector 0.0.0-stage → 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/CHANGELOG.md ADDED
@@ -0,0 +1,40 @@
1
+ # Changelog
2
+
3
+ ## 0.3.0 (unreleased)
4
+
5
+ - Heartbeats: once a day per release and environment, a few seconds after
6
+ `init()`, the SDK tells Collector the app is running, so a healthy app
7
+ shows as set up before its first error. It sends only the SDK name and
8
+ version, release and environment, and remembers the day in
9
+ `localStorage`. Turn it off with `heartbeat: false`.
10
+
11
+ ## 0.2.0 (2026-11-05)
12
+
13
+ - Source maps: `init()` uses the release injected by
14
+ `@chrom-ar/collector-cli/vite` (the `__COLLECTOR_RELEASE__` build constant)
15
+ when you don't pass `release`, so events match the uploaded maps.
16
+ - Firefox errors group with Chrome's and Safari's: its async-stack markers
17
+ (`EventListener.handleEvent*`, `setTimeout handler*`) are no longer frames.
18
+ - `throw null` and `throw undefined` are reported as `NonError`.
19
+ - Hash-router navigation (`#/orders/7`) shows up in breadcrumbs.
20
+ - webpack dev modules (`webpack-internal:///./src/…`) count as your code, and
21
+ only `vendor/` folders and `vendor…` bundles count as dependencies.
22
+ - A reused `XMLHttpRequest` no longer repeats old breadcrumbs.
23
+ - After Collector rejects the DSN (401/403), re-initializing (e.g. hot reload)
24
+ doesn't send again.
25
+ - Events dropped by `beforeSend` don't count toward the 30-per-10-seconds cap.
26
+
27
+ ## 0.1.0 (unreleased)
28
+
29
+ First release.
30
+
31
+ - Reports uncaught errors and unhandled promise rejections.
32
+ - `captureException`, `captureMessage`, `setUser`, `setTag`, `setTags`,
33
+ `addBreadcrumb`, `flush`, `close`.
34
+ - Breadcrumbs for clicks, navigation, fetch, XHR and console.
35
+ - Stack traces from Chrome, Firefox and Safari, with in-app detection and
36
+ hash-free module names for stable grouping across deploys.
37
+ - Drops duplicate events, caps a page at 30 events every 10 seconds, retries
38
+ on server errors, and honors `Retry-After`.
39
+ - Privacy defaults: query strings stripped from URLs, no cookies or headers,
40
+ `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,213 @@
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
+ - Once a day per release and environment, a few seconds after `init()`,
111
+ the SDK sends a heartbeat so Collector knows the app is running even
112
+ before its first error. It carries only the SDK's name and version, the
113
+ release and the environment: no user, URL, user agent or browser id. The
114
+ day it was sent is kept in `localStorage` (`collector:heartbeat:…`).
115
+ Turn it off with `heartbeat: false`.
116
+ - `beforeSend` sees every event last, and can edit it or drop it:
117
+
118
+ ```ts
119
+ Collector.init({
120
+ dsn: "…",
121
+ beforeSend(event) {
122
+ if (event.request) event.request.url = event.request.url.replace(/\/users\/\d+/, "/users/:id");
123
+ return event; // or null to drop it
124
+ },
125
+ });
126
+ ```
127
+
128
+ ## Options
129
+
130
+ | Option | Default | |
131
+ |---|---|---|
132
+ | `dsn` | none | Your project's DSN. Without it, nothing is sent |
133
+ | `environment` | none | e.g. `"production"`, `"staging"` |
134
+ | `release` | none | Your app's version or git sha |
135
+ | `debug` | `false` | Logs what the SDK does, prefixed `[collector]` |
136
+ | `enabled` | `true` | `false` turns everything off |
137
+ | `beforeSend` | none | `(event) => event \| null`, to edit or drop events |
138
+ | `ignoreErrors` | browser noise | Strings (matched anywhere in `"Type: message"`) or regexps. Added to the built-in list (`ResizeObserver loop…`, `Script error.`) |
139
+ | `inAppUrls` | same origin | Strings or regexps for script URLs that are your app's own code (see below) |
140
+ | `stripQuery` | `true` | Remove `?query` and `#hash` from URLs |
141
+ | `breadcrumbs` | all on | `{ console, dom, fetch, xhr, history }`, each `true`/`false` |
142
+ | `maxBreadcrumbs` | `50` | How many breadcrumbs to keep |
143
+ | `autoCapture` | both on | `{ onerror, onunhandledrejection }`, or `false` for neither |
144
+ | `heartbeat` | `true` | `false` stops the daily heartbeat (see [Privacy](#privacy)) |
145
+
146
+ Other functions: `setTags(tags)`, `addBreadcrumb({ message, category?, level? })`,
147
+ `flush(timeoutMs?)` (waits until queued events are sent) and `close()`
148
+ (removes everything the SDK installed).
149
+
150
+ ## How errors are grouped
151
+
152
+ Collector groups events into issues by the error type and the functions
153
+ in your app's own code that it passed through. The SDK marks a stack
154
+ frame as your code when its script is on the page's own origin (or is a
155
+ webpack dev module, `webpack-internal:///./src/…`) and
156
+ isn't a dependency bundle (`node_modules`, `.vite/deps`, `vendor` chunks,
157
+ Next.js framework chunks). Content hashes in file names are ignored, so
158
+ a new deploy doesn't open new issues. If your scripts come from a CDN,
159
+ say so:
160
+
161
+ ```ts
162
+ Collector.init({ dsn: "…", inAppUrls: ["https://cdn.example.com/app/"] });
163
+ ```
164
+
165
+ ## Source maps
166
+
167
+ Upload your build's source maps and Collector shows your original files,
168
+ lines and function names, and groups errors by them. With Vite, add the
169
+ plugin from [`@chrom-ar/collector-cli`](https://www.npmjs.com/package/@chrom-ar/collector-cli):
170
+
171
+ ```ts
172
+ // vite.config.ts
173
+ import collector from "@chrom-ar/collector-cli/vite";
174
+
175
+ export default defineConfig({ plugins: [collector()] });
176
+ ```
177
+
178
+ Set `COLLECTOR_UPLOAD_TOKEN` (from your project's settings) and
179
+ `COLLECTOR_DSN` in your CI. The plugin uploads the maps at the end of
180
+ `vite build`, removes them from the output, and injects the release, so you
181
+ don't need to pass `release` to `init()`.
182
+
183
+ With another bundler, upload with the CLI before you deploy, and make the
184
+ release match:
185
+
186
+ ```sh
187
+ npx @chrom-ar/collector-cli upload ./dist --release "$GIT_SHA"
188
+ ```
189
+
190
+ Pass the same value to `init({ release })`, or define the
191
+ `__COLLECTOR_RELEASE__` constant at build time (e.g. webpack's
192
+ `new DefinePlugin({ __COLLECTOR_RELEASE__: JSON.stringify(sha) })`).
193
+
194
+ ## What it won't do (yet)
195
+
196
+ - **Minified stack traces without source maps.** Upload them (see
197
+ [Source maps](#source-maps)); without them, frames show the built code
198
+ and the same error can open a new issue after a deploy.
199
+ - **Browsers name functions differently.** The SDK normalizes names
200
+ (`Cart.checkout` in Chrome and `checkout` in Firefox both become
201
+ `checkout`), but Safari sometimes leaves frames out, so the same error
202
+ can occasionally group separately per browser.
203
+ - **Browsers only.** For servers, use a server SDK
204
+ ([Elixir](https://hex.pm/packages/collector)).
205
+
206
+ It never throws into your app, never blocks it, and keeps quiet in the
207
+ console unless something's misconfigured (or you set `debug: true`).
208
+ When an error repeats in a loop, it sends it once; and it sends at most
209
+ 30 events every 10 seconds per page.
210
+
211
+ ## License
212
+
213
+ MIT