@hanzo/event 0.3.48 → 0.3.49
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 +11 -50
- package/dist/core.d.ts +6 -36
- package/dist/core.d.ts.map +1 -1
- package/dist/index.cjs +206 -409
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -4
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +208 -406
- package/dist/index.mjs.map +1 -1
- package/dist/org.d.ts.map +1 -1
- package/dist/react.cjs +118 -404
- package/dist/react.cjs.map +1 -1
- package/dist/react.mjs +119 -405
- package/dist/react.mjs.map +1 -1
- package/dist/throwable.d.ts +15 -0
- package/dist/throwable.d.ts.map +1 -0
- package/dist/types.d.ts +19 -74
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/core.test.ts +28 -300
- package/src/core.ts +36 -185
- package/src/exception.ts +1 -1
- package/src/index.ts +1 -5
- package/src/org.ts +4 -0
- package/src/stream.test.ts +0 -7
- package/src/throwable.test.ts +72 -0
- package/src/throwable.ts +126 -0
- package/src/types.ts +15 -75
- package/src/uid.test.ts +1 -1
- package/dist/dsn.d.ts +0 -43
- package/dist/dsn.d.ts.map +0 -1
- package/dist/sentry.d.ts +0 -62
- package/dist/sentry.d.ts.map +0 -1
- package/src/dsn.test.ts +0 -75
- package/src/dsn.ts +0 -56
- package/src/sentry.test.ts +0 -312
- package/src/sentry.ts +0 -311
package/README.md
CHANGED
|
@@ -4,28 +4,9 @@ The ONE telemetry client for Hanzo surfaces. Emits every kind of event —
|
|
|
4
4
|
`pageview` / `event` / `identify` / `group` **and errors** — to **Hanzo Cloud**,
|
|
5
5
|
never to a third-party.
|
|
6
6
|
|
|
7
|
-
ONE
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
```
|
|
11
|
-
1. event stream POST {host}/v1/event body: { batch: [Event, …] } -> { accepted, dropped }
|
|
12
|
-
2. error plane POST {dsn}/v1/sentry/{projectId}/envelope/?sentry_key=… (a real Sentry envelope)
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
> ### Errors need a DSN. Without one, nothing reaches Sentry.
|
|
16
|
-
>
|
|
17
|
-
> **There is no server-side fan-out from `/v1/event` into Sentry.** Versions
|
|
18
|
-
> ≤ 0.3.1 of this README claimed there was — that "Cloud fans the one stream out
|
|
19
|
-
> into three lenses". It does not. `/v1/event` writes a `type:'error'` row to the
|
|
20
|
-
> cloud event warehouse (readable via `GET /v1/errors`) and stops there. Because
|
|
21
|
-
> every Hanzo property believed that claim, nobody set a DSN, and the entire
|
|
22
|
-
> fleet reported **zero** errors to Sentry until 0.3.2 added the envelope.
|
|
23
|
-
>
|
|
24
|
-
> Set `dsn` (or `NEXT_PUBLIC_HANZO_EVENT_DSN`). Mint one per property with
|
|
25
|
-
> `POST /v1/sentry/projects`. The key is publishable and write-only — safe in a
|
|
26
|
-
> browser bundle, same trust class as a `pk_` ingest key. No DSN means the error
|
|
27
|
-
> plane is **inert**: nothing is sent, nothing throws, analytics is unaffected.
|
|
28
|
-
> Assert `client.errorPlaneEnabled` if you want to know which you have.
|
|
7
|
+
ONE endpoint, `POST {host}/v1/event`, body `{ batch: [Event, …] }`. Pageviews,
|
|
8
|
+
events, identifies, groups and errors all ride it; there is no second endpoint,
|
|
9
|
+
DSN or envelope.
|
|
29
10
|
|
|
30
11
|
### No bundler? Use the hosted tag
|
|
31
12
|
|
|
@@ -78,9 +59,8 @@ refusals. A React app does not need this file — mount `<Hanzo analytics>` from
|
|
|
78
59
|
- **Batched** with a size + interval flush, and **beacon-on-unload**
|
|
79
60
|
(`sendBeacon` for cookie/publishable-key apps, `fetch(keepalive)` for token apps).
|
|
80
61
|
- **Auto error capture** (subsumes `@sentry`): `window.onerror`,
|
|
81
|
-
`unhandledrejection`, and a React `ErrorBoundary` are reported
|
|
82
|
-
|
|
83
|
-
stream. Opt out with `captureErrors: false`.
|
|
62
|
+
`unhandledrejection`, and a React `ErrorBoundary` are reported as one
|
|
63
|
+
`type:'error'` event each. Opt out with `captureErrors: false`.
|
|
84
64
|
- **Scrubbed at the source**: secrets are always redacted and PII is masked
|
|
85
65
|
client-side before an error leaves the device.
|
|
86
66
|
- **First-touch attribution**: UTM + referrer + `refCode` are parsed once and
|
|
@@ -140,12 +120,10 @@ Unhandled errors and promise rejections are captured automatically. React render
|
|
|
140
120
|
errors never reach `window.onerror`, so wrap your tree in the `ErrorBoundary` to
|
|
141
121
|
catch those too. Report caught errors yourself with `captureError`.
|
|
142
122
|
|
|
143
|
-
**Pass a `dsn` or none of this reaches Sentry.**
|
|
144
|
-
|
|
145
123
|
```tsx
|
|
146
124
|
import { ErrorBoundary } from '@hanzo/event/react'
|
|
147
125
|
|
|
148
|
-
<AnalyticsProvider config={{ product: 'console'
|
|
126
|
+
<AnalyticsProvider config={{ product: 'console' }}>
|
|
149
127
|
<ErrorBoundary fallback={(err, reset) => <Crash error={err} onReset={reset} />}>
|
|
150
128
|
<App />
|
|
151
129
|
</ErrorBoundary>
|
|
@@ -156,20 +134,13 @@ import { ErrorBoundary } from '@hanzo/event/react'
|
|
|
156
134
|
try { risky() } catch (err) { analytics.captureError(err, { properties: { where: 'checkout' } }) }
|
|
157
135
|
```
|
|
158
136
|
|
|
159
|
-
Each report
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
thing that creates an issue in the error dashboard, with grouping and stack
|
|
163
|
-
frames. Sent one envelope per error, immediately; batching a crash report is
|
|
164
|
-
how you lose it.
|
|
165
|
-
- **the event stream** — a `type:'error'` event; Cloud folds the exception into
|
|
166
|
-
`properties.$exception` and stamps `event_type='error'`, so the error stays
|
|
167
|
-
correlated with the session's pageviews (`GET /v1/errors`). This is product
|
|
168
|
-
signal, *not* error tracking, and it never reaches Sentry on its own.
|
|
137
|
+
Each report is one `type:'error'` event carrying `error` (`type`, `message`,
|
|
138
|
+
`frames`, `stack`, `handled`) plus `release`, `environment`, `site`, `product` and
|
|
139
|
+
`level`. The server files it on the error plane and groups it into an issue.
|
|
169
140
|
|
|
170
141
|
The message and any `properties` are scrubbed of secrets and PII before sending,
|
|
171
142
|
and the message is capped at 8KB. `captureError` never throws back into your app,
|
|
172
|
-
|
|
143
|
+
|
|
173
144
|
|
|
174
145
|
## Publishable key (public pages, no bearer)
|
|
175
146
|
|
|
@@ -178,18 +149,8 @@ Marketing/public pages have no session. Mint a write-only publishable key
|
|
|
178
149
|
fetch and `?ingest_key` on an unload beacon, so the **event stream** accepts
|
|
179
150
|
anonymous traffic. It is safe to ship in a bundle (write-only, cannot read).
|
|
180
151
|
|
|
181
|
-
The `ingestKey` authenticates the event stream ONLY. The error plane
|
|
182
|
-
authenticates independently with the DSN key on `?sentry_key=`, and the two
|
|
183
|
-
credentials are never sent to each other's host. A public page that wants errors
|
|
184
|
-
in Sentry needs the `dsn` as well:
|
|
185
|
-
|
|
186
152
|
```ts
|
|
187
|
-
createAnalytics({
|
|
188
|
-
product: 'site',
|
|
189
|
-
host: 'https://api.hanzo.ai',
|
|
190
|
-
ingestKey: 'pk_live_…', // event stream
|
|
191
|
-
dsn: process.env.NEXT_PUBLIC_HANZO_EVENT_DSN, // error plane
|
|
192
|
-
})
|
|
153
|
+
createAnalytics({ product: 'site', host: 'https://api.hanzo.ai', ingestKey: 'pk_live_…' })
|
|
193
154
|
```
|
|
194
155
|
|
|
195
156
|
## Taxonomy, funnels & goals
|
package/dist/core.d.ts
CHANGED
|
@@ -13,25 +13,13 @@ export declare class Analytics {
|
|
|
13
13
|
private started;
|
|
14
14
|
/** The view pageview() last counted — path + location. */
|
|
15
15
|
private counted?;
|
|
16
|
-
/** Parsed error-plane DSN, or null when the plane is inert. */
|
|
17
|
-
private dsn;
|
|
18
16
|
/** Guards against an error thrown *inside* the error path re-entering it. */
|
|
19
17
|
private reentrant;
|
|
20
18
|
constructor(config: AnalyticsConfig);
|
|
21
19
|
/** adopt gives this client a credential it does not have. The key belongs to
|
|
22
20
|
* the stream, not to whichever caller happened to ask for the handle first,
|
|
23
|
-
* so a later caller carrying one hands it over.
|
|
24
|
-
* the key, so it comes up here too when it was inert for want of one.
|
|
25
|
-
* Present fields are never overwritten: the first caller's key stays. */
|
|
21
|
+
* so a later caller carrying one hands it over. Present fields are never overwritten: the first caller's key stays. */
|
|
26
22
|
adopt(config: AnalyticsConfig): void;
|
|
27
|
-
/** errorPlaneEnabled reports whether captured exceptions can actually reach the
|
|
28
|
-
* error host. False means a DSN was never configured — the documented
|
|
29
|
-
* fail-safe. Exposed so an app (or a test) can assert its wiring instead of
|
|
30
|
-
* discovering months later that nothing was ever reported. */
|
|
31
|
-
get errorPlaneEnabled(): boolean;
|
|
32
|
-
/** errorIngestUrl is the fully-derived envelope endpoint, or undefined when the
|
|
33
|
-
* plane is inert. Diagnostics only. */
|
|
34
|
-
get errorIngestUrl(): string | undefined;
|
|
35
23
|
/** init is idempotent and browser-only for its side effects: capture first-touch
|
|
36
24
|
* attribution, hydrate cohort, register the unload flush, and (unless opted out)
|
|
37
25
|
* auto-capture unhandled errors. Safe to call from a React effect on every
|
|
@@ -58,19 +46,11 @@ export declare class Analytics {
|
|
|
58
46
|
* fields (productId/quantity/revenue/currency) may be passed for order events. */
|
|
59
47
|
capture(event: string, properties?: Record<string, unknown>, commerce?: Pick<WireEvent, 'productId' | 'quantity' | 'revenue' | 'currency'>): void;
|
|
60
48
|
/** captureError reports a caught error, an unhandled rejection, a React render
|
|
61
|
-
* error, or a manual report
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* - the EVENT STREAM — a `type:'error'` row in the cloud event warehouse, so
|
|
67
|
-
* an error stays correlated with the session's pageviews for product
|
|
68
|
-
* analysis (readable via GET /v1/errors).
|
|
69
|
-
*
|
|
70
|
-
* Both carry the SAME session and subject id, so an error and the pageview
|
|
71
|
-
* before it join up. Never throws back into the app; errors are higher-signal
|
|
72
|
-
* than pageviews, so both planes flush promptly (a crash may unload the page
|
|
73
|
-
* moments later). */
|
|
49
|
+
* error, or a manual report as ONE event of type 'error' on the one stream.
|
|
50
|
+
* It carries the exception (type, message, frames, stack, handled) and the
|
|
51
|
+
* release, environment, site, product and level that group and scope it, and
|
|
52
|
+
* flushes promptly (a crash may unload the page moments later). Never throws
|
|
53
|
+
* back into the app. */
|
|
74
54
|
captureError(err: unknown, context?: CaptureErrorOptions): void;
|
|
75
55
|
/** setCohort persists cohort dimensions (e.g. signupWeek at signup) so they ride
|
|
76
56
|
* every subsequent event. */
|
|
@@ -87,16 +67,6 @@ export declare class Analytics {
|
|
|
87
67
|
* cookie fine).
|
|
88
68
|
*/
|
|
89
69
|
flush(beacon?: boolean): void;
|
|
90
|
-
/** sendError frames one exception as a Sentry envelope and posts it to the DSN's
|
|
91
|
-
* ingest URL. The DSN's own key rides ?sentry_key= (the credential channel the
|
|
92
|
-
* server trusts, and the only one a headerless beacon can carry), so NO bearer
|
|
93
|
-
* or publishable key is attached here — the two planes authenticate
|
|
94
|
-
* independently. Errors are sent one envelope per event, immediately: batching
|
|
95
|
-
* a crash report is how you lose it. */
|
|
96
|
-
private sendError;
|
|
97
|
-
/** errorIdentity is the SAME identity the event stream stamps — the OIDC subject
|
|
98
|
-
* once identify() has run, else the anon id. Never email/PII. */
|
|
99
|
-
private errorIdentity;
|
|
100
70
|
private enqueue;
|
|
101
71
|
private build;
|
|
102
72
|
private schedule;
|
package/dist/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAoCA,OAAO,EAKL,aAAa,EAEb,SAAS,EAEV,MAAM,WAAW,CAAA;AAGlB,OAAO,KAAK,EACV,eAAe,EAEf,mBAAmB,EACnB,MAAM,EAIN,SAAS,EACV,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,OAAO,EAAE,MAAM,W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