catchfn 0.1.2 → 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/README.md CHANGED
@@ -43,21 +43,21 @@ errors.stop();
43
43
  sockets.stop();
44
44
  ```
45
45
 
46
- ## Evidence events v1
46
+ ## Evidence event formats
47
47
 
48
- Every event has `schemaVersion: 1`, a `kind` (`"console"`, `"network"`,
48
+ Every event has a `schemaVersion`, a `kind` (`"console"`, `"network"`,
49
49
  `"breadcrumb"`, `"error"` or `"websocket"`), a `seq` capture-order number and a `timestamp` in epoch
50
50
  milliseconds, plus the fields of its kind. The format is closed: extra fields
51
51
  are invalid. Check an event with `validateEvidenceEvent(event)` (returns a list
52
52
  of problems, empty when valid) or with any JSON Schema 2020-12 validator and
53
53
  the exported `evidenceEventSchema`. Integer fields (`seq`, `timestamp`,
54
- `status`, `lineno`, `colno`, `size`, `code`) are safe integers in both, and nested records (`data`, header
55
- records, objects in `args`) must be plain or null-prototype objects without a
54
+ `argumentCount`, `status`, `lineno`, `colno`, `size`, `code`) are safe integers in both, and nested records (`data`, header
55
+ records, and objects in legacy `args`) must be plain or null-prototype objects without a
56
56
  callable `toJSON`.
57
57
 
58
58
  | kind | fields |
59
59
  | --- | --- |
60
- | `console` | `level` (`log`, `info`, `warn`, `error`, `debug`), `args` |
60
+ | `console` | `level` (`log`, `info`, `warn`, `error`, `debug`), `argumentCount`, `source` (`console`), optional `lineno` and `colno` |
61
61
  | `network` | `transport` (`fetch`, `xhr`), `method`, `url`, optional `status`, `statusText`, `duration`, `requestHeaders`, `responseHeaders` |
62
62
  | `breadcrumb` | `type` (`navigation`, `console`, `network`, `user`, `custom`), optional `message`, `data`, `category`, `level` (`debug`, `info`, `warning`, `error`) |
63
63
  | `error` | `source` (`error`, `unhandledrejection`), `message`, optional `name`, `stack`, `filename`, `lineno`, `colno`, `value` |
@@ -65,6 +65,16 @@ callable `toJSON`.
65
65
 
66
66
  Captured events are frozen.
67
67
 
68
+ Starting with 0.2.0, console collectors record metadata with `schemaVersion: 2`.
69
+ The other collectors continue to emit version 1. Use `argumentCount`
70
+ to show how many arguments were passed. The original console call receives
71
+ the arguments unchanged, and the collector never inspects their contents.
72
+ Wrapped calls omit coordinates and never request a stack. If your instrumentation
73
+ already knows the numeric call site, use `collector.record(level, argumentCount,
74
+ lineno, colno)` to record it directly. This method can be used without starting
75
+ the console wrappers. The current validators accept saved v1 events with `args`
76
+ from earlier releases. Update validators before consuming the new console events.
77
+
68
78
  ## Time-window queries
69
79
 
70
80
  Each collector keeps its events in a fixed-size ring buffer (the constructor's
@@ -176,17 +186,23 @@ uncaught error while it runs.
176
186
 
177
187
  - An uncaught error is read from a platform `ErrorEvent` through the getters
178
188
  captured at load: `message` is the browser's text (`"Uncaught Error: boom"`)
179
- when it has one, `filename` goes through `redactUrl`, and `lineno` and
180
- `colno` are kept. An `error` event that is not an `ErrorEvent` (one the page
189
+ when it has one. The collector omits `data:` filenames because they contain
190
+ inline source. Other filenames go through `redactUrl`. The numeric `lineno`
191
+ and `colno` are kept. An `error` event that is not an `ErrorEvent` (one the page
181
192
  dispatches itself) is ignored.
182
193
  - An unhandled rejection's reason is read through the captured
183
194
  `PromiseRejectionEvent` getter, and an `unhandledrejection` event that is
184
195
  not a `PromiseRejectionEvent` is ignored. Only on a runtime without that
185
196
  class is the reason read from the event's own `reason` data property.
186
197
  - A thrown value or reason that is an `Error` gives `name`, `message` and
187
- `stack`, serialized as one entry; reading them can run the error's own
188
- getters, as for a console argument. Each URL in the stack goes through
189
- `redactUrl`, keeping its `:line:column` suffix. Any other value is serialized into
198
+ `stack`, serialized as one entry; reading diagnostics can run the error's own
199
+ getters. A linear scan replaces absolute and `data:` stack URLs with
200
+ `[REDACTED_URL]` without expanding the retained input prefix. A URL token's
201
+ numeric suffix can belong to the URL, so the scan masks it too. The browser's
202
+ numeric error-event fields described above still carry locations. A `data:`
203
+ token masks the rest of its line because inline source can include spaces
204
+ and frame-like text. That rule can also hide a function label that contains
205
+ `data:`. Any other value is serialized into
190
206
  `value`, and `message` holds it as text (a string as is, anything else as
191
207
  its JSON). An uncaught error whose `ErrorEvent.error` is `null` or
192
208
  `undefined` has no `value`: a cross-origin `"Script error."` and an
@@ -273,7 +289,7 @@ constructs through the page's own class and is not observed.
273
289
  or adding a listener) is a no-op, and a `stop()` during that install leaves
274
290
  the session at once: a socket constructed meanwhile is never observed, also
275
291
  after a restart. Each collector holds at most one subscription.
276
- - Timestamps of the error and WebSocket collectors come from the `Date.now`
292
+ - Timestamps of the console, error and WebSocket collectors come from the `Date.now`
277
293
  captured at load. An observation whose clock gives anything but a
278
294
  nonnegative safe integer is dropped; the event or send itself is unchanged.
279
295
  Loading never throws: with no `Date.now` to capture then (a throwing
@@ -307,8 +323,7 @@ Captured values are snapshotted under a closed set of forms:
307
323
  One entry is at most 10 KB of UTF-8 JSON; strings are cut and containers stop
308
324
  early with a `"[Truncated]"` marker (the last array item, or a record key
309
325
  whose value counts the omitted keys; `"[Truncated 2]"`, ... when the record
310
- already holds that key). A console event's argument list is one
311
- entry, and each argument counts its depth from 1. A breadcrumb's `data` and
326
+ already holds that key). A breadcrumb's `data` and
312
327
  `message`, a network event's `url` and each header record, an error event's
313
328
  `message`, `filename` and thrown value (an `Error`'s name, message and stack
314
329
  together, or `value`), and a websocket event's `url`, are entries.