@newtalaria/browser 0.1.16 → 0.1.18

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/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Browser SDK for [Talaria](https://github.com/) — error capture and **session replay** (rrweb event streams, not video).
4
4
 
5
+ Network calls (`fetch` / XHR) are instrumented as replay breadcrumbs; **only first-party (same-origin) or allowlisted origins** promote failed requests to error events — see [Failed HTTP / network requests](#failed-http--network-requests--events).
6
+
5
7
  ## Install
6
8
 
7
9
  ```bash
@@ -187,27 +189,68 @@ Set `inlineStylesheet: true` so same-origin stylesheet rules are embedded while
187
189
 
188
190
  ### Failed HTTP / network requests → events
189
191
 
190
- By default, completed `fetch` / XHR responses with status **500–599** are sent as Talaria events (message like `HTTP 500: GET /api/...`).
192
+ All instrumented `fetch` / XHR calls are recorded as replay breadcrumbs (`talaria-network`). **Error events are promoted only for first-party (same-origin) or explicitly allowlisted origins.**
193
+
194
+ | Request | HTTP 5xx | Transport failure / timeout | Abort |
195
+ | --- | --- | --- | --- |
196
+ | Same-origin | Error event | Error event | Breadcrumb only |
197
+ | Allowlisted third-party (`networkErrorOrigins`) | Error event | Error event | Breadcrumb only |
198
+ | Other third-party (analytics, ads, widgets, …) | Breadcrumb only | Breadcrumb only | Breadcrumb only |
199
+
200
+ This avoids Issue spam from Google Analytics, ad pixels, privacy blockers, and similar third-party noise—without a hardcoded domain denylist. Add origins you intentionally depend on (payments, CMS APIs, widgets):
201
+
202
+ ```ts
203
+ networkErrorOrigins: ['https://api.stripe.com', 'https://widget.yonder.example'],
204
+ // Escape hatch (not recommended): networkErrorOrigins: ['*']
205
+ ```
206
+
207
+ **URL privacy:** network telemetry stores `origin + pathname` only (plus `hostname` / `pathname`). Query strings and fragments are stripped by default. Set `captureRequestQueryParameters: true` to keep query params after redaction of secrets **and** common tracking keys (`token`, `api_key`, `gclid`, `fbclid`, `_ga`, `cid`, `sid`, …). Bodies and auth headers are never captured.
208
+
209
+ Both **`fetch`** and **`XMLHttpRequest`** are instrumented (`network.transport`: `fetch` | `xhr`). Failure kinds are only claimed when detectable:
191
210
 
192
- Transport failures (CORS, offline, DNS — browser `TypeError: Failed to fetch`) are also promoted by default as:
211
+ | `failure.kind` | Meaning |
212
+ | --- | --- |
213
+ | `http` | Completed response with a real status (e.g. 500) |
214
+ | `network` | No usable HTTP response (status 0 / Failed to fetch) — CORS, block, DNS, offline, etc. |
215
+ | `timeout` | `TimeoutError` or XHR `timeout` event |
216
+ | `abort` | `AbortError` / XHR abort — recorded in breadcrumbs, **not** promoted as events |
217
+
218
+ We **do not** classify status 0 as `cors` — browsers do not expose that reliably. Tags include `network.party` (`first_party` \| `third_party`).
193
219
 
194
- `Network error: POST https://www.google-analytics.com/g/collect TypeError: Failed to fetch`
220
+ Promoted events use structured `extra` (server groups on method + host + path + kind + status):
195
221
 
196
- **URL privacy:** network telemetry stores `origin + pathname` only (plus `hostname` / `pathname` fields). Query strings and fragments are stripped by default — analytics/ads URLs often carry `cid`, `sid`, `dl`, etc. Set `includeNetworkUrlQuery: true` to keep query params after sensitive-key redaction (`token`, `api_key`, …).
222
+ ```json
223
+ {
224
+ "http": {
225
+ "method": "POST",
226
+ "url": "https://app.example.com/api/orders",
227
+ "origin": "https://app.example.com",
228
+ "hostname": "app.example.com",
229
+ "pathname": "/api/orders",
230
+ "transport": "fetch"
231
+ },
232
+ "failure": { "kind": "network", "name": "TypeError", "message": "Failed to fetch" },
233
+ "network": { "party": "first_party", "durationMs": 842, "aborted": false, "ok": false },
234
+ "exception_class": "NetworkError",
235
+ "status_code": null
236
+ }
237
+ ```
197
238
 
198
- Replay `talaria-network` breadcrumbs include method, sanitized URL, status (when an HTTP response exists), duration, and on failures `errorName` / `errorMessage` / `aborted` / `failureKind`. Request/response bodies and auth headers are never captured.
239
+ Crawler UAs are tagged (`bot=true`, `bot.name=Baiduspider`) without inventing a browser name.
199
240
 
200
241
  ```ts
201
242
  Talaria.init({
202
243
  dsn: 'https://api.example.com',
203
244
  apiKey: 'tal_live_…',
204
245
  environment: 'production',
205
- // Default true — HTTP status promotion
246
+ // Default true — HTTP status promotion (first-party / allowlisted only)
206
247
  captureFailedRequests: true,
207
- // Default true — CORS/offline/DNS fetch failures
248
+ // Default true — transport failures (first-party / allowlisted only)
208
249
  captureNetworkErrors: true,
250
+ // Extra origins to treat like first-party for promotion
251
+ networkErrorOrigins: ['https://api.stripe.com'],
209
252
  // Default false — do not store ?query on network URLs
210
- includeNetworkUrlQuery: false,
253
+ captureRequestQueryParameters: false,
211
254
  // Default [[500, 599]]. CMS admin often wants 4xx too:
212
255
  failedRequestStatusCodes: [[400, 599]],
213
256
  // Extra URL substrings to skip (Talaria /events and /replays are always skipped)
@@ -215,7 +258,24 @@ Talaria.init({
215
258
  });
216
259
  ```
217
260
 
218
- `AbortError` is never promoted and is ignored by the global `unhandledrejection` handler. If a fetch failure is left unhandled after network-error promotion, the duplicate bare `TypeError` event is suppressed; if promotion is off, the exception is kept and correlated with the recent request URL/method/duration.
261
+ `AbortError` is never promoted and is ignored by the global `unhandledrejection` handler. Bare `TypeError: Failed to fetch` / `TimeoutError` rejections are correlated with recent network breadcrumbs: promoted failures and third-party noise are suppressed; first-party failures with promotion off keep the exception and merge request context.
262
+
263
+ #### Network event tags (low cardinality)
264
+
265
+ | Tag | Values | Notes |
266
+ | --- | --- | --- |
267
+ | `http.method` | `GET`, `POST`, … | |
268
+ | `http.status_code` | e.g. `500` | Present on HTTP promotions only |
269
+ | `network.failure_kind` | `http` \| `network` \| `timeout` | |
270
+ | `network.transport` | `fetch` \| `xhr` | |
271
+ | `network.party` | `first_party` \| `third_party` | Same-origin vs cross-origin (allowlist does not change this tag) |
272
+ | `network.error_name` | e.g. `TypeError`, `TimeoutError` | When available |
273
+
274
+ Hostname, pathname, full sanitized URL, and duration live in `extra` — not tags — to avoid high-cardinality facets.
275
+
276
+ #### Issue grouping (server)
277
+
278
+ Promoted network events set `extra.exception_class` (`HttpError` \| `NetworkError` \| `TimeoutError`) and `extra.status_code`. The server fingerprints them on **method + hostname + pathname + failure kind + status** (not the human message), so query strings and volatile error text do not fragment Issues. See [`planning/fingerprints.md`](../../../planning/fingerprints.md) §6.4.
219
279
 
220
280
  ### Event timestamps
221
281
 
@@ -226,11 +286,35 @@ Talaria.init({
226
286
 
227
287
  If replay upload runs before event ingest, `extra.sdk.queuedMs` records how long capture waited (ms). A large `createdAt - timestamp` gap is usually flush/queue delay or clock skew — not a wrong failure classification.
228
288
 
289
+ ## Init options reference
290
+
291
+ | Option | Default | Description |
292
+ | --- | --- | --- |
293
+ | `dsn` / `baseUrl` | *(required)* | Serverpod host, e.g. `https://api.example.com` |
294
+ | `apiKey` | *(required)* | Project API key (`tal_live_…`) |
295
+ | `environment` | *(required)* | `production` \| `staging` \| `development` (aliases accepted) |
296
+ | `release` | — | Optional release string on every event |
297
+ | `userId` | — | Optional app user id |
298
+ | `tags` | — | Tags merged into every event |
299
+ | `replaysSessionSampleRate` | `0` | Fraction of sessions that upload continuously |
300
+ | `replaysOnErrorSampleRate` | `1` | Fraction of errors that promote the ring buffer |
301
+ | `replaysErrorAfterMs` | `15000` | Post-error upload window; `0` = continue to 5 min cap |
302
+ | `maskAllInputs` | `true` | rrweb input masking |
303
+ | `inlineStylesheet` | `false` | Embed same-origin CSS (CMS/admin) |
304
+ | `blockSelector` | — | Extra CSS selectors blocked from the DOM snapshot |
305
+ | `disableDefaultIntegrations` | `false` | Skip `window.onerror` / `unhandledrejection` |
306
+ | `captureFailedRequests` | `true` | Promote HTTP status failures (**first-party / allowlisted only**) |
307
+ | `captureNetworkErrors` | `true` | Promote transport/timeout failures (**first-party / allowlisted only**) |
308
+ | `networkErrorOrigins` | `[]` | Extra origins eligible for promotion; same-origin always eligible; `['*']` = all (not recommended) |
309
+ | `failedRequestStatusCodes` | `[[500, 599]]` | Status codes/ranges to promote when origin is eligible |
310
+ | `failedRequestIgnoreUrls` | `[]` | URL substrings never promoted (Talaria `/events` + `/replays` always ignored) |
311
+ | `captureRequestQueryParameters` | `false` | Keep `?query` on network URLs after redaction (`includeNetworkUrlQuery` alias) |
312
+
229
313
  ## Public API
230
314
 
231
315
  | API | Description |
232
316
  | --- | --- |
233
- | `Talaria.init(options)` | Configure + start recording |
317
+ | `Talaria.init(options)` | Configure + start recording + install network/console hooks |
234
318
  | `Talaria.captureException(error)` | Ingest error (+ replay link when sampled) |
235
319
  | `Talaria.captureMessage(message, level?)` | Ingest message |
236
320
  | `Talaria.getReplayId()` | Active upload replay id, or `null` |
package/dist/client.d.ts CHANGED
@@ -107,7 +107,7 @@ export declare class TalariaClient {
107
107
  private pruneRecentNetworkFailures;
108
108
  private rememberNetworkFailure;
109
109
  /**
110
- * Find a recent transport failure for a bare fetch TypeError.
110
+ * Find a recent transport failure for a bare fetch TypeError / TimeoutError.
111
111
  * Consumes the entry so a later duplicate path cannot reuse it.
112
112
  */
113
113
  private consumeCorrelatedNetworkFailure;
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,aAAa,EACb,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAgEpB,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,EACnB,0BAA0B,EAC1B,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,uBAAuB,EACvB,+BAA+B,EAC/B,+BAA+B,EAC/B,4BAA4B,GAC7B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EACzB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,6BAA6B,CAAC;AACrC,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,6BAA6B,CAAC;AA0IrC,qBAAa,aAAa;IACxB,OAAO,CAAC,OAAO,CAAgC;IAC/C,OAAO,CAAC,SAAS,CAAmC;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