import type { NativeModule } from 'expo'; import type { LogAttributeValue, LogEventOptions, MetricAttributes } from 'expo-app-metrics'; /** * Value types accepted as attribute values in `setGlobalAttributes` and the * other Observe APIs. Strings, numbers, and booleans are stored as typed * primitives; arrays and nested maps preserve their structure. */ export type ObserveAttribute = LogAttributeValue; /** * A map of attribute key to value, as accepted by `setGlobalAttributes` and * other Observe APIs that take a free-form attributes payload. */ export type ObserveAttributes = Record; export type ObserveConfig = { /** * The environment for observability events * * @default process.env.NODE_ENV */ environment?: string; /** * Whether to dispatch observability events to the server. * * When `false`, any pending metrics are marked as sent without being dispatched * and no further metrics are dispatched until this is set back to `true`. * * @default true */ dispatchingEnabled?: boolean; /** * Whether to dispatch metrics that were collected in a debug build of the host app. * * When `false`, metrics produced by debug builds are marked as sent without being dispatched. * When `true`, debug-build metrics are dispatched alongside release-build metrics. * * Has no effect on release builds. * * If `dispatchingEnabled` is `false` or this device is out-of-sample for `sampleRate`, nothing * is dispatched regardless of `dispatchInDebug`. * * @default false */ dispatchInDebug?: boolean; /** * Fraction of installations that should dispatch metrics, in `[0, 1]`. Values outside that range * are clamped. * * The decision is **deterministic per installation** — a device is either permanently in-sample * or out-of-sample for a given rate, so the choice is stable across app launches. * * Interaction with `dispatchingEnabled`: * - If `dispatchingEnabled` is `false`, metrics are never dispatched * - If `dispatchingEnabled` is `true` (or unset), metrics are dispatched only when this device * is in-sample. * * > Note: Devices that end up out-of-sample drop pending metrics rather than accumulating them. * * @default undefined - metrics from all devices are sent */ sampleRate?: number; /** * Opt in to per-integration behavior. */ integrations?: ObserveIntegrationsConfig; }; export type ObserveNavigationIntegrationConfig = { /** * Route or query parameter keys to remove from exported navigation metric * `routeParams`. When any configured parameter is removed from a metric, * the exported resolved URL/path is replaced with `urlHidden: true`. * Does not affect `routeName`. */ filteredParams?: string[]; }; export interface ObserveIntegrationsConfig { /** * Enables the `expo-router` integration, which records navigation metrics * (`cold_ttr`, `warm_ttr`, `tti`) from router state changes. * * Requires `expo-router` to be installed. * * Pass an object to filter exported route/query params. * * @default false */ 'expo-router'?: boolean | ObserveNavigationIntegrationConfig; /** * Enables the `@react-navigation/native` integration, which records * navigation metrics (`cold_ttr`, `warm_ttr`, `tti`). * * Requires `@react-navigation/native` to be installed and the app tree * to be wrapped in `` instead of the stock * ``. * * Pass an object to filter exported route/query params. * * @default false */ 'react-navigation'?: boolean | ObserveNavigationIntegrationConfig; } /** * Events emitted by the native `ExpoObserve` module. */ export type ObserveModuleEvents = { /** * Fired on every `configure(...)` call, carrying the resolved `integrations` * config */ configure: (payload: { integrations: ObserveIntegrationsConfig; }) => void; }; export declare class ObserveModule extends NativeModule { dispatchEvents(): Promise; /** * Configures observability settings. */ configure(config: ObserveConfig): void; /** * Returns the `integrations` config from the most recent `configure(...)` * call, or an empty object if `configure` has not run yet. */ getIntegrations(): ObserveIntegrationsConfig; /** * Invokes a callback once when the named integration configuration becomes available. * * @param name Integration name. * @param callback Function called with the integration configuration. * * @example * ```ts * Observe.registerIntegration('expo-router', config => { * console.log(config); * }); * ``` */ registerIntegration(name: K, callback: (config: ObserveIntegrationsConfig[K]) => void): void; /** * Records a log event against the current main session. The event is * persisted locally and dispatched on the next `dispatchEvents()` flush. * * Severity defaults to `"info"` when not provided. * * @param name Event name. * @param options Optional body, attributes, and severity overrides. */ logEvent(name: string, options?: LogEventOptions): void; /** * Reports an error your code caught and handled, recorded as a non-fatal `exception` event. Use it * to keep visibility into failures you recover from, which never reach the automatic global handler * or an error boundary. * * The thrown value is normalized: an `Error`'s `name`, `message`, and `stack` are captured; any * other value (a string, a plain object) is stringified as the message. * * @param error The caught value. An `Error` is preferred, but any thrown value is accepted. * * @example * ```ts * try { * await syncCart(); * } catch (error) { * Observe.reportError(error); * } * ``` */ reportError(error: unknown): void; /** * Marks the first render of the app. Used to compute the `cold_ttr` and * `warm_ttr` metrics. */ markFirstRender(): void; /** * Marks the moment the app becomes interactive. Used to compute the `tti` * metric. Custom `routeName` and `params` can be attached via `attributes`. * * > Note: When the `expo-router` or `@react-navigation/native` integration * > is active, prefer `useObserve().markInteractive(...)` — the hook fills * > in `routeName` from the current route, while this raw call does not. */ markInteractive(attributes?: MetricAttributes): void; /** * Sets attributes merged into every subsequent metric and log event. * Per-record keys win on collision. Pass `null`, `undefined`, or an empty * object to clear. * * @example * ```ts * Observe.setGlobalAttributes({ * subscription_tier: 'pro', * experiment_variant: 'B', * }); * ``` */ setGlobalAttributes(attributes?: ObserveAttributes | null): void; /** * Pushes JS-bundle-derived facts (`process.env.NODE_ENV`, `__DEV__`) into native * storage. Called automatically once when the package is first imported; should * not be called by host apps directly. * * @internal */ setBundleDefaults(defaults: { environment: string; isJsDev: boolean; }): void; } //# sourceMappingURL=types.d.ts.map