Skip to content

Commit b3f6863

Browse files
author
Hanzo AI
committed
fix(telemetry): wire the error plane to Sentry
This app already pointed @hanzo/event at the correct door, but carried no DSN, so its error plane was inert: every captured error — auto (window.onerror, unhandledrejection), React (ErrorBoundary) and manual (errorLogger via setErrorReporter) — went only to the cloud event warehouse and never reached the Sentry dashboard. Pass a DSN (NEXT_PUBLIC_HANZO_EVENT_DSN, the `hanzo-app` project) so those same call sites now also emit a real Sentry envelope. Publishable, write-only key — build env, never committed. Unset leaves the plane inert and analytics unaffected. Also corrects the comment claiming Cloud fans the one /v1/event stream out to the error (sentry) lens. It does not — that belief is exactly why this app reported no errors. Requires @hanzo/event >= 0.3.2.
1 parent 179e32b commit b3f6863

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

components/providers/analytics.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,24 @@ import { createAnalytics } from '@hanzo/event';
88
import { AnalyticsProvider, ErrorBoundary, useAnalytics, usePageview } from '@hanzo/event/react';
99
import { setErrorReporter, type ErrorContext } from '@/lib/error-handling/error-logger';
1010

11-
/** The ONE Hanzo Cloud telemetry front door — POST api.hanzo.ai/v1/event. Cloud
12-
* fans the one batched stream out to the web (analytics), product (insights), and
13-
* error (sentry) lenses; the client never sends the org — Cloud resolves the
14-
* tenant server-side from the validated bearer (or the publishable key). */
11+
/** The Hanzo Cloud event-stream door — POST api.hanzo.ai/v1/event. The client
12+
* never sends the org; Cloud resolves the tenant server-side from the validated
13+
* bearer (or the publishable key).
14+
*
15+
* NOTE: this door does NOT fan out to sentry. An earlier comment here claimed
16+
* Cloud fanned the one stream into the error (sentry) lens — it does not, and
17+
* that mistaken belief is why this app reported zero errors to sentry.hanzo.ai.
18+
* A `type:'error'` event lands in the cloud event warehouse (readable via
19+
* GET /v1/errors); reaching sentry requires the DSN below. */
1520
const HOST = 'https://api.hanzo.ai';
1621

22+
/** Hanzo-minted Sentry DSN for the `hanzo-app` project — the ERROR plane.
23+
* "https://<version>:<hmac>@<host>/v1/sentry/<projectId>". Publishable and
24+
* write-only, so it is safe in the bundle. Unset => the error plane is inert
25+
* (fail-safe: analytics keeps working, nothing throws). Set in the build env;
26+
* never committed. Mint: POST /v1/sentry/projects */
27+
const EVENT_DSN = process.env.NEXT_PUBLIC_HANZO_EVENT_DSN || undefined;
28+
1729
/** Optional publishable ingest key (pk_…) that lets LOGGED-OUT marketing/public
1830
* views emit accepted telemetry (pageviews + errors + unload beacons) — the key
1931
* HMAC-verifies to the org server-side, so anonymous events light up all three
@@ -53,7 +65,8 @@ function Identity() {
5365
* the bearer the @hanzo/iam SDK already holds — it emits pageviews, a stable-id
5466
* identify() once auth resolves, AND captures errors (auto: window.onerror +
5567
* unhandledrejection; React: the ErrorBoundary below; manual: errorLogger, wired
56-
* through setErrorReporter). One client, one stream — errors are just events.
68+
* through setErrorReporter). One client, two planes: every captured error goes to
69+
* sentry.hanzo.ai as a Sentry envelope AND stays correlated on the event stream.
5770
* The token is read through a live ref so a single stable client survives token
5871
* refresh without re-initializing.
5972
*/
@@ -71,6 +84,9 @@ export function AnalyticsRoot({ children }: { children: ReactNode }) {
7184
host: HOST,
7285
getToken: () => tokenRef.current ?? undefined,
7386
ingestKey: INGEST_KEY,
87+
// Error plane -> sentry.hanzo.ai. Inert (fail-safe) when the DSN is unset.
88+
dsn: EVENT_DSN,
89+
environment: process.env.NODE_ENV,
7490
// Consent gate: honor the browser Do-Not-Track signal.
7591
enabled: !doNotTrack(),
7692
}),

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@hanzo/ai": "^0.2.1",
3030
"@hanzo/base": "^0.2.1",
3131
"@hanzo/brand": "^1.4.1",
32-
"@hanzo/event": "^0.3.1",
32+
"@hanzo/event": "^0.3.2",
3333
"@hanzo/gui": "7.3.0",
3434
"@hanzo/iam": "^0.13.8",
3535
"@hanzo/logo": "^1.0.13",

0 commit comments

Comments
 (0)