@smarthivelabs-devs/observe-web
v26.3.0
Published
SmartObserve SDK for browsers, React, and Next.js
Readme
@smarthivelabs-devs/observe-web
Browser errors, sessions, and performance for SPAs, React, and Next.js. Failed ingest never throws into the page.
Use a public DSN (pk_) from SmartObserve project settings. Allow this site’s HTTPS origin on the project. Node backends use @smarthivelabs-devs/observe-node and an sk_ DSN.
https://<pk_public_key>@observe.smarthivelabs.dev/<project-slug>Install
pnpm add @smarthivelabs-devs/observe-webStart
Call init once on the client (not in a Node-only module).
import { SmartObserve } from "@smarthivelabs-devs/observe-web";
SmartObserve.init({
dsn: process.env.NEXT_PUBLIC_SMARTOBSERVE_DSN,
release: process.env.NEXT_PUBLIC_SMARTOBSERVE_RELEASE,
});window.onerror, unhandled rejections, fetch, navigation, LCP/FCP, console, and a session (active / exited) are captured automatically. Events queue while offline and flush when the tab is back online.
What you send
SmartObserve.captureException(err);
SmartObserve.captureMessage("paywall shown", "info");
SmartObserve.log.warn("slow image", { src });
SmartObserve.setUser({ id: user.id });
SmartObserve.setTag("plan", user.plan);
SmartObserve.setContext("page", { route: location.pathname });
SmartObserve.addBreadcrumb({ category: "ui", message: "opened cart" });
await SmartObserve.startSpan({ name: "load-profile", operation: "ui.action" }, async (span) => {
span.setAttribute("user.id", user.id);
return loadProfile();
});beforeSend can drop or edit events. Passwords, tokens, and cookies are redacted; extend with redactKeys. Email and IP stay off the user object unless sendDefaultPii: true.
Browser noise nobody can act on (extension scripts, ResizeObserver loop warnings, cross-origin Script error.) is dropped by default; set ignoreDefaultErrors: false to keep it. Chunk-load failures and network errors are tagged error.kind:chunk_load / error.kind:network, and every chunk-load failure groups into one issue instead of one per chunk file.
After a deploy, tabs still running the previous build hit ChunkLoadError. Set reloadOnChunkError: true to report it and reload the page once (at most once a minute), so users land on the new build.
Turn off noisy automations with trackFetch, trackNavigation, trackPerformance, or trackConsole set to false. Ignore third-party script noise with denyUrls.
Outgoing fetch never gets traceparent unless you allow hosts you own:
SmartObserve.init({
dsn: process.env.NEXT_PUBLIC_SMARTOBSERVE_DSN,
allowTracePropagationTargets: ["https://api.yourapp.com"],
});User feedback
Let users tell you what went wrong. Feedback shows up in the dashboard's User Feedback inbox, and on the issue when it is attached to an error.
// A floating "Report a problem" button on every page:
SmartObserve.init({ dsn: process.env.NEXT_PUBLIC_SMARTOBSERVE_DSN, feedbackButton: true });
// Or open the dialog yourself, attached to an error:
const eventId = SmartObserve.captureException(error);
SmartObserve.showFeedbackDialog({ associatedEventId: eventId, name: user.name, email: user.email });
// Or send feedback from your own form:
SmartObserve.captureFeedback({ message, email, associatedEventId: eventId });With React, <SmartObserveErrorBoundary showDialog fallback={…}> opens the dialog after a crash, attached to that error. The dialog renders in a Shadow DOM, follows the user's light/dark preference, and is keyboard and screen-reader accessible.
React
Wrap the tree you care about. Uncaught render errors become issues with a component stack.
import { SmartObserveErrorBoundary } from "@smarthivelabs-devs/observe-web/react";
<SmartObserveErrorBoundary fallback={<p>Something broke.</p>}>
<App />
</SmartObserveErrorBoundary>Next.js
withSmartObserve injects NEXT_PUBLIC_SMARTOBSERVE_* and, on production webpack builds, uploads .map files so stack frames symbolicate.
import { withSmartObserve } from "@smarthivelabs-devs/observe-web/next";
export default withSmartObserve(nextConfig, {
dsn: process.env.SMARTOBSERVE_DSN,
});In CI set SMARTOBSERVE_AUTH_TOKEN to a release token from project settings (SMARTOBSERVE_RELEASE_TOKEN also works). Release defaults to SMARTOBSERVE_RELEASE, then VERCEL_GIT_COMMIT_SHA / CF_PAGES_COMMIT_SHA. Fail the build on upload errors with requireUpload: true. Keep maps locally with deleteAfterUpload: false.
next is an optional peer. Vanilla React / Vite apps only need the root package plus /react if you want the boundary.
Options
| Option | Default | Notes |
| --- | --- | --- |
| dsn | NEXT_PUBLIC_SMARTOBSERVE_DSN | Public key DSN |
| release | NEXT_PUBLIC_SMARTOBSERVE_RELEASE | Tie events to a deploy |
| enabled | true if DSN is set | Set false in tests |
| errorSampleRate | 1 | 0–1 |
| tracesSampleRate | 0.1 | Root transactions |
| sendDefaultPii | false | Include email / IP |
| debug | false | Logs transport failures |
API
SmartObserve.init · captureException · captureMessage · log · setUser · setTag · setContext · addBreadcrumb · startSpan · beforeSend · flush · close · SmartObserveBrowserClient
