@pmate/log-sdk 0.2.0 → 0.2.2

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
@@ -53,3 +53,26 @@ Use authenticatedProfile from server authentication, never a client body/header.
53
53
 
54
54
  ## Counting
55
55
  The envelope `id` is the event deduplication key. PV counts pv events; sessions deduplicate `(appId, accessId)`; Profile UV deduplicates `(appId, profileId)` in a defined time window/topic. Missing identifiers are reported separately. Never count HTTP requests or vitals as page views, or infer first-ever visits from a limited retention window.
56
+
57
+ ## Error and crash diagnostics
58
+
59
+ Caught exceptions need explicit reporting; a global rejection listener cannot see
60
+ an exception already handled by application code. Use `log.captureError(error,
61
+ { operation: 'chat.send' })` on browser, React and Node loggers. Error records use
62
+ the `error` topic and include bounded message/stack diagnostics with URL queries
63
+ removed. Applications must redact domain-specific sensitive strings before
64
+ calling this method.
65
+
66
+ Inside `LogProvider`, wrap the application in `LogErrorBoundary` with a `fallback`
67
+ React node. It reports descendant render/lifecycle failures with component stacks.
68
+ Event handlers, asynchronous operations and errors above the boundary require
69
+ separate reporting. Explicitly allowlisted `log.fetch` requests report non-2xx and
70
+ network failures without bodies or request URLs.
71
+
72
+ Node exports `installCrashReporter({ directory, send })`. Install it before
73
+ starting the service. It monitors fatal exceptions without suppressing Node's
74
+ fatal exit, persists up to 20 records, and exposes `replay()` for startup recovery.
75
+ The `send(entry)` callback must resolve only after server acknowledgement, retain
76
+ entry ID/time, and route records to the service's `crash` topic. Failed uploads
77
+ remain on disk. Use a service-specific private persistent directory. It cannot
78
+ capture SIGKILL, OOM kills, native faults, or failures before installation.
package/dist/browser.js CHANGED
@@ -97,7 +97,15 @@ export function createLogger(options) {
97
97
  if (!validId(headers.get(REQUEST_HEADER)))
98
98
  headers.set(REQUEST_HEADER, crypto.randomUUID());
99
99
  // Refuse redirects so correlation headers cannot leak to another origin.
100
- return fetch(input, { ...init, headers, redirect: "error" });
100
+ return fetch(input, { ...init, headers, redirect: "error" }).then(response => {
101
+ if (!response.ok)
102
+ transport.append("error", { data: { event: "http.client.failed", origin: url.origin, status: response.status, clientRequestId: headers.get(REQUEST_HEADER), serverRequestId: response.headers.get(REQUEST_HEADER) } });
103
+ return response;
104
+ }, error => {
105
+ const failure = errorInput(error, { operation: "http.fetch" });
106
+ transport.append("error", { data: { ...failure.data, origin: url.origin, clientRequestId: headers.get(REQUEST_HEADER) } });
107
+ throw error;
108
+ });
101
109
  }
102
110
  return fetch(input, init);
103
111
  },
package/dist/node.d.ts CHANGED
@@ -33,3 +33,4 @@ export declare function createLogger(options: NodeLoggerOptions): {
33
33
  close(): Promise<void>;
34
34
  };
35
35
  export { installCrashReporter } from "./crash.js";
36
+ export { errorInput } from "./errors.js";
package/dist/node.js CHANGED
@@ -131,3 +131,4 @@ export function createLogger(options) {
131
131
  };
132
132
  }
133
133
  export { installCrashReporter } from "./crash.js";
134
+ export { errorInput } from "./errors.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/log-sdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "PMate browser, React and Node logs with access and profile context",
5
5
  "type": "module",
6
6
  "sideEffects": false,