@sazabi/browser 0.2.0-dev.ga327325 → 0.2.0-dev.gc364c51

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.
Files changed (3) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +67 -38
  3. package/package.json +3 -3
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Sazabi
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,89 +1,109 @@
1
- # @sazabi/browser
1
+ # @sazabi/browser-sdk
2
2
 
3
- Capture what actually happens in your users' browsers: a session-scoped event stream of navigation, clicks, frustration signals, JavaScript errors, console output, and network calls correlated to your backend logs by `trace_id`, and streamed to [Sazabi](https://sazabi.com) as structured telemetry your agents can reason over.
3
+ Capture what happens in your users' browsers with `@sazabi/browser-sdk`, the official Sazabi browser SDK. It emits a session-scoped stream of navigation, interactions, console output, JavaScript errors, and network calls as OTLP log records, and injects W3C trace context into your API requests so a frontend symptom and its backend cause share a trace id.
4
4
 
5
- Zero runtime dependencies, ~8 KB gzipped, and designed to never break your app: every hook is wrapped, patches are reversible, and input values are never captured.
5
+ `@sazabi/browser-sdk` is a zero-dependency browser library you install in your own web app. It lets you:
6
+
7
+ - Follow a single visitor's session across tabs, from first page load to error
8
+ - Catch uncaught exceptions and unhandled promise rejections with stack traces
9
+ - See rage clicks and dead clicks — the interactions that signal frustration
10
+ - Join frontend network calls to backend logs on a shared `trace_id`
11
+ - Use AI to investigate a browser session end to end
12
+
13
+ ~8 KB gzipped, and designed to never break your app: every hook is wrapped, every patch is reversible, and input values are never captured.
6
14
 
7
15
  ## Install
8
16
 
9
17
  ```sh
10
- bun add @sazabi/browser
11
- # or: npm install @sazabi/browser
18
+ npm install @sazabi/browser-sdk
19
+ # or: bun add / pnpm add / yarn add
12
20
  ```
13
21
 
22
+ ## Get your intake URL
23
+
24
+ Sign in to Sazabi, go to **Settings > Log streams**, choose **Web**, and click **Add**. Sazabi mints a public key and shows your complete intake URL at the top of the setup screen.
25
+
26
+ The SDK needs both values: the intake URL as `intakeHost` (the SDK appends the `/v1/logs` signal path itself) and the full `sazabi_public_...` value as `publicKey`.
27
+
28
+ Unlike most credentials, this one is **meant** to ship in your browser bundle — a public key can only write telemetry into your project, never read from it.
29
+
14
30
  ## Quick start
15
31
 
16
32
  ```ts
17
- // First import in your app entry: installs instrumentation before any other
18
- // module can capture native fetch/XHR/history references.
19
- import "@sazabi/browser/register";
33
+ // Import first, because a module that runs earlier can capture the native
34
+ // fetch/XHR/history references before the SDK wraps them.
35
+ import "@sazabi/browser-sdk/register";
20
36
 
21
- import { init } from "@sazabi/browser";
37
+ import { init } from "@sazabi/browser-sdk";
22
38
 
23
39
  init({
24
- publicKey: "sazabi_public_...",
25
- intakeHost: "https://web.us-west-2.intake.sazabi.com",
40
+ intakeHost: "https://<public-key-hex>.<region>.intake.sazabi.com",
41
+ publicKey: "sazabi_public_<public-key-hex>",
26
42
  serviceName: "my-web-app",
43
+ serviceVersion: process.env.GIT_SHA,
44
+ environment: "production",
27
45
  });
28
46
  ```
29
47
 
30
- `publicKey` is a Sazabi public key it can only write telemetry, so it is safe to ship in your bundle. Replace the intake host region with your project's region.
48
+ `init()` is idempotent, never throws into your app, and no-ops during server-side rendering, so it is safe in a shared entry module.
31
49
 
32
- The register import is optional but recommended. `init()` alone also instruments, but only at call time — HTTP clients constructed at module scope may capture the native functions first. Requests that bypass instrumentation are still observed through a resource-timing fallback, and the SDK logs a once-per-origin `instrumentation_gap` diagnostic naming the escaped origin so the gap is visible instead of silent.
50
+ The register import is optional but recommended. `init()` alone also instruments, but only at call time — and every static import in your entry file evaluates before its first statement, so an HTTP client constructed at module scope wins that race. Requests that slip past instrumentation are still observed through a resource-timing fallback, and the SDK emits a once-per-origin `instrumentation_gap` diagnostic naming the escaped origin, so the gap is visible rather than silent.
33
51
 
34
52
  ## What gets captured
35
53
 
36
- | Event type | Contents |
37
- |------------|----------|
38
- | `navigation` | Page loads and SPA route changes — History API, hash, back/forward, and Navigation API (`navigation.navigate()`) |
39
- | `click` | Capture-phase clicks with a privacy-safe selector and the element's label ("Save changes") — never input values |
40
- | `rage_click` / `dead_click` | Frustration signals: rapid repeat clicks, clicks with no visible response |
41
- | `input` | One event per field engagement which field (by its label), for how long, how many edits, whether pasted. Never keystrokes, values, or value lengths |
42
- | `error` | Uncaught exceptions and unhandled promise rejections with stack traces |
43
- | `network` | fetch/XHR calls with method, status, duration and a trace id when propagated |
44
- | `log` | Mirrored `console.error`/`console.warn` output, plus anything you send with `log()` |
54
+ Every event carries a cross-tab `session.id`, a per-tab `session.window_id`, `session.distinct_id`, and the page URL, so one user's activity reads as a single ordered timeline. The `web.event_type` attribute names the kind:
55
+
56
+ | `web.event_type` | Contents |
57
+ |------------------|----------|
58
+ | `navigation` | Page loads and SPA route changes — History API, hash, back/forward, and the Navigation API |
59
+ | `click` | Capture-phase clicks with a privacy-safe selector and the element's label ("Save changes") |
60
+ | `rage_click` / `dead_click` | Frustration signals: rapid repeat clicks, and clicks with no visible response |
61
+ | `input` | One event per field engagement — which field, for how long, how many edits, whether pasted. Never keystrokes, values, or value lengths |
62
+ | `error` | Uncaught exceptions and unhandled rejections with `exception.type`, `exception.message`, and `exception.stacktrace` |
63
+ | `network` | fetch and XHR calls with method, status, and duration — plus the trace context injected into them |
64
+ | `log` | Mirrored `console.error` / `console.warn` output, plus anything you send with `log()` |
45
65
  | `custom` | Marks you add with `addEvent()` |
46
66
 
47
- Every event carries a cross-tab `session.id`, a per-tab `session.window_id`, and the page URL, so a user's activity reads as one ordered timeline.
48
-
49
67
  ## Correlate with your backend
50
68
 
51
- The SDK injects a W3C `traceparent` header into same-origin requests by default. To propagate to an API on another origin, allowlist it — and make sure the API's CORS `Access-Control-Allow-Headers` includes `traceparent`:
69
+ The SDK injects a W3C `traceparent` header into same-origin requests by default. To reach an API on another origin, allowlist it — and make sure that API's CORS configuration includes `traceparent` in `Access-Control-Allow-Headers`, or the browser preflight fails and those requests break:
52
70
 
53
71
  ```ts
54
72
  init({
55
- // ...
73
+ //
56
74
  network: {
57
75
  allowlist: ["https://api.example.com"],
58
76
  },
59
77
  });
60
78
  ```
61
79
 
62
- Backend log lines that run inside the extracted trace context then share a `trace_id` with the originating browser request. If your backend runs OpenTelemetry, extraction already happens by default; set `network: { sampledFlag: true }` if you also want your backend tracer to record those traces (the logs-side join works either way).
80
+ Backend log lines that run inside the extracted trace context then share a `trace_id` with the originating browser request. If your backend runs OpenTelemetry, that extraction already happens by default. Set `network: { sampledFlag: true }` if you also want your backend tracer to *record* those traces the logs-side join works either way.
63
81
 
64
- The SDK also records platform request ids echoed on responses (`x-request-id`, `cf-ray`, `x-vercel-id`, and similar) as `web.network.request_id`, giving you an exact join key against CDN and platform logs with no backend changes.
82
+ The SDK also records platform request ids echoed on responses (`x-request-id`, `cf-ray`, `x-vercel-id`, and similar) as `web.network.request_id`, giving you an exact join key against CDN and platform logs with no backend changes. Reading these cross-origin requires the header in `Access-Control-Expose-Headers`.
65
83
 
66
84
  ## Identify users
67
85
 
68
86
  ```ts
69
- import { identify, reset } from "@sazabi/browser";
87
+ import { identify, reset } from "@sazabi/browser-sdk";
70
88
 
71
- identify("user_123", { plan: "pro" }); // on login or app boot — use your internal id, not an email
72
- reset(); // on logout — clears identity and starts a fresh session
89
+ identify("user_123", { plan: "pro" }); // on sign-in — use your internal id, not an email
90
+ reset(); // on sign-out
73
91
  ```
74
92
 
75
- `identify()` stamps `session.distinct_id` on subsequent events and records the traits on the identify event. `reset()` clears the identity and rotates the session so activity on a shared device never threads into the previous user's timeline; switching identities without a `reset()` rotates automatically. Identity is client-asserted — treat it as a claim, not authentication.
93
+ `identify()` stamps `session.distinct_id` on subsequent events and records the traits on the identify event. `reset()` clears the identity and rotates the session and window ids, so activity on a shared device never threads into the previous user's timeline; switching identities without a `reset()` rotates automatically.
94
+
95
+ Identity is client-asserted — treat it as a claim, not as authentication.
76
96
 
77
97
  ## Logs, custom events, and console output
78
98
 
79
99
  ```ts
80
- import { addEvent, log } from "@sazabi/browser";
100
+ import { addEvent, log } from "@sazabi/browser-sdk";
81
101
 
82
102
  addEvent("checkout_started", { cartValue: 42 });
83
103
  log("WARN", "cache lookup failed", { requestId: "req_9" });
84
104
  ```
85
105
 
86
- `console.error` and `console.warn` are mirrored into the event stream by default (the original console behavior is untouched). Configure with `console: { levels: [...] }` or disable with `console: { capture: false }`.
106
+ `console.error` and `console.warn` are mirrored into the event stream by default, and the original console behavior is untouched. Configure with `console: { levels: [...] }` or turn it off with `console: { capture: false }`.
87
107
 
88
108
  ## Consent
89
109
 
@@ -91,11 +111,13 @@ If your users must opt in before capture, pass a consent gate — nothing is ins
91
111
 
92
112
  ```ts
93
113
  init({
94
- // ...
114
+ //
95
115
  consent: () => cookieBanner.accepted(),
96
116
  });
97
117
  ```
98
118
 
119
+ `identify()` calls made while consent is pending are buffered and applied when capture starts.
120
+
99
121
  ## Configuration
100
122
 
101
123
  | Option | Default | Purpose |
@@ -113,7 +135,14 @@ init({
113
135
 
114
136
  ## Privacy and safety
115
137
 
116
- - Input values, keystrokes, request bodies, and response bodies are never captured — not even value lengths.
117
- - Element names come from developer-authored sources only (`aria-label`, `<label>`, `placeholder`, button captions), and only for interactive elements clicks on plain containers, where user content lives, record selectors only. Add `data-sazabi-mask` to any element to suppress text capture for its whole subtree, or `data-sazabi-name` to set the reported name explicitly.
118
- - Every patch is transparent, idempotent, and reversible; SDK failures are invisible to your app, and `shutdown()` restores the original functions.
138
+ - **Input values, keystrokes, request bodies, and response bodies are never captured** — not even value lengths.
139
+ - Element names come from developer-authored sources only (`aria-label`, `<label>`, `placeholder`, button captions), and only for interactive elements. Clicks on plain containers, where user content lives, record selectors only.
140
+ - Add `data-sazabi-mask` to any element to suppress text capture for its whole subtree, or `data-sazabi-name` to set an element's reported name explicitly.
141
+ - Every patch is transparent, idempotent, and reversible. SDK failures are invisible to your app, and `shutdown()` restores the original functions.
119
142
  - Events are delivered as OTLP/HTTP log records with batching, and flushed with `keepalive` when the tab closes.
143
+
144
+ ## Verifying it works
145
+
146
+ Load your app and click through a few pages. The SDK flushes every 5 seconds and again when the tab is hidden or closed, so the first events land within about 10 seconds. In your browser's network tab, filter for `intake` — POSTs to `/v1/logs` should return 200.
147
+
148
+ Full setup guide and troubleshooting: [docs.sazabi.com/data/log-sources/endpoint/web](https://docs.sazabi.com/data/log-sources/endpoint/web).
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sazabi/browser",
3
- "description": "Sazabi browser observability SDK \u2014 semantic event stream capture with W3C trace context propagation",
4
- "version": "0.2.0-dev.ga327325",
3
+ "description": "Sazabi browser observability SDK semantic event stream capture with W3C trace context propagation",
4
+ "version": "0.2.0-dev.gc364c51",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -32,4 +32,4 @@
32
32
  "access": "public",
33
33
  "registry": "https://registry.npmjs.org"
34
34
  }
35
- }
35
+ }