@smarthivelabs-devs/observe-expo
v26.3.0
Published
SmartObserve SDK for Expo and React Native
Readme
@smarthivelabs-devs/observe-expo
Crashes, sessions, and traces for Expo and React Native. Failed ingest never throws. Events persist offline and flush when the network returns.
Use a public DSN (pk_) from SmartObserve project settings.
https://<pk_public_key>@observe.smarthivelabs.dev/<project-slug>Native traffic uses origin smartobserve-expo://native — you do not add that in project settings. If the same app also runs in a browser, allow that HTTPS origin separately (or use @smarthivelabs-devs/observe-web on web).
Install
npx expo install @smarthivelabs-devs/observe-expo expo-application expo-constants expo-device @react-native-async-storage/async-storage @react-native-community/netinfonpx expo install picks the versions of the native modules that match your Expo SDK. They are peer dependencies, so the app owns them (no duplicate native modules, no version clashes with the rest of your app).
Supported versions
| | Supported |
| --- | --- |
| Expo SDK | 52 – 58 (tested on 52 and 58 on every change) |
| React Native | 0.76+ (New Architecture and legacy) |
| React | 18.3+ and 19 |
| Builds | Expo Go, development builds, eas build, expo prebuild, EAS Update / expo export |
Every change to this package is checked by building throwaway apps on the oldest and newest SDK: install with strict peer dependencies, typecheck, resolve the config plugin, expo prebuild, and a Metro + Hermes expo export for Android and iOS. Run it yourself with pnpm compat:check.
Start
Call init once at the root of the app.
import { SmartObserve } from "@smarthivelabs-devs/observe-expo";
SmartObserve.init({ dsn: process.env.EXPO_PUBLIC_SMARTOBSERVE_DSN });Release and dist default to the native app version and build number. The global JS handler, AppState lifecycle, a session (active / exited / crashed), device/app context, and fetch are wired automatically.
What you send
SmartObserve.captureException(err);
SmartObserve.captureMessage("paywall shown", "info");
SmartObserve.log.warn("slow sync", { table: "orders" });
SmartObserve.setUser({ id: user.id });
SmartObserve.setTag("workspace", workspace.slug);
SmartObserve.trackScreen("Checkout", { step: "pay" });
await SmartObserve.startSpan({ name: "sync", operation: "db" }, async (span) => {
span.setAttribute("rows", count);
return sync();
});trackScreen is a navigation breadcrumb. beforeSend can drop or edit events. Tokens and passwords are redacted; add keys with redactKeys. Email / IP stay off the user unless sendDefaultPii: true.
Disable automations with trackNetwork: false or trackLifecycle: false. Outgoing fetch never gets traceparent unless you allow hosts you own:
SmartObserve.init({
dsn: process.env.EXPO_PUBLIC_SMARTOBSERVE_DSN,
allowTracePropagationTargets: ["https://api.yourapp.com", /^https:\/\/.*\.yourapp\.com$/],
});React Native UI
import { SmartObserveErrorBoundary } from "@smarthivelabs-devs/observe-expo/react";
<SmartObserveErrorBoundary fallback={<Text>Something broke.</Text>}>
<App />
</SmartObserveErrorBoundary>Config plugin
Writes dsn, environment and release into expo.extra.smartObserve; SmartObserve.init() reads them, so you can call init() without options. Source maps are not uploaded by the plugin (prebuild runs before the bundle exists): upload them after eas update / expo export with the CLI below.
{
"expo": {
"plugins": ["@smarthivelabs-devs/observe-expo"]
}
}["@smarthivelabs-devs/observe-expo", { dsn: process.env.EXPO_PUBLIC_SMARTOBSERVE_DSN }]Upload source maps
npx expo export --source-maps
npx smartobserve-expo upload-sourcemaps --path dist --release <version> --dist <build>--release defaults to the app.json version and --dist to the iOS buildNumber / Android versionCode, matching what the SDK sends. In CI set SMARTOBSERVE_AUTH_TOKEN to a release token from project settings (SMARTOBSERVE_RELEASE_TOKEN also works).
Options
| Option | Default | Notes |
| --- | --- | --- |
| dsn | — | Public key DSN |
| environment | production | Shown on issues |
| release / dist | native version / build | Override for EAS |
| 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 · trackScreen · startSpan · beforeSend · flush · close · SmartObserveExpoClient
