npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bitdrift/react-native

v0.12.13

Published

bitdrift integration for React Native

Readme

@bitdrift/react-native

bitdrift integration for React Native

Installation

npm install @bitdrift/react-native

Usage

Expo

If you are using Expo to build your React Native app and don't want to use an ejected workflow, you can use the @bitdrift/react-native package to initialize the Capture library and log messages at different log levels. Note that this initializes the library later than is ideal, but should still provide most of the benefits of using Capture.

import {
  init,
  trace,
  debug,
  info,
  warn,
  error,
  isTracingActive,
  setEntityId,
  clearEntityId,
  SessionStrategy,
} from '@bitdrift/react-native';

init('<api key>', SessionStrategy.Activity, {
  startResult: (result) => {
    console.log('Capture start result', result);
  },
  crashReporting: {
    enableNativeFatalIssues: true, // Enable native crash reporting (crashes, ANRs, etc.)
    UNSTABLE_enableJsErrors: true, // Enable JavaScript error reporting (fatal and non-fatal)
    UNSTABLE_onBeforeReportSend: (report) => {
      // Add your custom handling for report metadata.
      // Available fields: report.reportType, report.sessionId, report.details, report.reason, report.fields
    },
  },
});

info('Hello, World!');
setEntityId('user-123');
console.log('Tracing active?', isTracingActive());
clearEntityId();

For all Expo usages, make sure to add @bitdrift/react-native to the plugins field in your app.json file. This helps ensure setting up the native modules correctly.

{
  "expo": {
    "plugins": [
      "@bitdrift/react-native"
    ]
  }
}

Android-only WebView instrumentation note:

  • UNSTABLE_webViewInstrumentation currently only affects Android app builds.
  • In this package, automatic setup is only provided through the Expo config plugin / generated Android Gradle setup.
  • Non-Expo Android apps can still enable the same instrumentation manually by applying the Gradle plugin and configuring the bitdrift instrumentation block.
  • It does not affect iOS builds.
  • It does not automatically configure non-Expo / vanilla React Native Android projects.

Expo Go

Due to loading native modules, the @bitdrift/react-native package is not supported in Expo Go.

React Native / Ejected Expo

First initialize the Capture library by using the per-platform instructions found here.

For iOS, perform the initialization in didFinishLaunchingWithOptions in your AppDelegate.m file.

-
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

  [CAPLogger startWithAPIKey:@"<api key>" sessionStrategy: CAPSessionStrategy.fixed]];

  ...

For Android, perform the initialization in onCreate in your MainApplication.kt file.

  override fun onCreate() {
    super.onCreate()
    Capture.Logger.start(
      apiKey = "<api key>",
      sessionStrategy = SessionStrategy.Fixed()
    )
    ...
  }

To add custom log messages from your React Native app, import the log level functions from the @bitdrift/react-native package and use them to log messages at the desired log level.

Configuration Options

Crash Reporting

The crashReporting option allows you to configure crash and error reporting behavior:

init('<api key>', SessionStrategy.Activity, {
  crashReporting: {
    enableNativeFatalIssues: true, // Enable native crash reporting (crashes, ANRs, etc.)
    UNSTABLE_enableJsErrors: true, // Enable JavaScript error reporting (fatal and non-fatal)
    UNSTABLE_onBeforeReportSend: (report) => {
      // Add your custom handling for report metadata.
      // Available fields: report.reportType, report.sessionId, report.details, report.reason, report.fields
    },
  }
});
  • enableNativeFatalIssues: When true, enables reporting of native fatal issues including crashes, ANRs (Application Not Responding), and other critical errors. Defaults to true.
  • UNSTABLE_enableJsErrors: When true, enables reporting of JavaScript errors (both fatal and non-fatal) via React Native's global error handler. Captures unhandled exceptions with stack traces. This feature is experimental and may change in future releases. Defaults to false.
  • UNSTABLE_onBeforeReportSend: Called before an issue report is sent. Receives { reportType, reason, details, sessionId, fields }.

Previous Run Info

Use getPreviousRunInfo() to check whether the previous app run ended in a fatal termination.

import {
  getPreviousRunInfo,
  init,
  SessionStrategy,
  type PreviousRunInfo,
} from '@bitdrift/react-native';

init('<api key>', SessionStrategy.Activity);

const previousRunInfo: PreviousRunInfo = getPreviousRunInfo();

if (previousRunInfo?.hasFatallyTerminated) {
  console.log('Previous run terminated fatally', previousRunInfo.terminationReason);
}

PreviousRunInfo shape:

type PreviousRunInfo = {
  hasFatallyTerminated: boolean;
  terminationReason?: string;
} | null;
  • This API is synchronous.
  • Call it after init(...).
  • Android: available on API 30+ (Android 11+); returns null on older versions.
  • iOS simulator: returns null by design; use a physical device to validate.
  • terminationReason is currently populated on Android. iOS currently provides hasFatallyTerminated.

SDK Status

Use getSdkStatus() to inspect the SDK's current initialization state and recent backend activity.

import { getSdkStatus, init, SessionStrategy, type SdkStatus } from '@bitdrift/react-native';

init('<api key>', SessionStrategy.Activity);

const sdkStatus: SdkStatus = getSdkStatus();
console.log(sdkStatus.initializationState);

SdkStatus shape:

type SdkStatus = {
  initializationState: 'notStarted' | 'loaded' | 'running' | 'disabled';
  lastHandshakeTimeMs?: number;
  lastConfigDeliveryTimeMs?: number;
};
  • This API is synchronous.
  • It can be called before or after init(...).
  • When Capture has not started yet, initializationState is notStarted.

Start Result Callback

Use startResult to observe whether native SDK startup succeeded.

import { init, SessionStrategy } from '@bitdrift/react-native';

init('<api key>', SessionStrategy.Activity, {
  startResult: (result) => {
    if (result.success) {
      console.log('Capture started successfully');
    } else {
      console.log('Capture failed to start', result.error);
    }
  },
});

StartResult shape:

type StartResult = {
  success: boolean;
  error?: string;
};
  • The callback is invoked at most once per init(...) call.
  • This callback is experimental and may change.
import { trace, debug, info, warn, error } from '@bitdrift/react-native';

// Log at the desired log level using the different log level functions.

trace('Hello, World!');

debug('Hello, World!');

info('Hello, World!');

warn('Hello, World!');

error('Hello, World!');

// Optionally pass an Error object to automatically capture error details
try {
  // some code that might throw
} catch (err) {
  error('Failed to process request', err);
  // Or with additional fields
  error('Failed to process request', err, { userId: '123' });
}

Feature Flag Tracking

Track feature flag exposures to understand which variants users are seeing:

import { setFeatureFlagExposure } from '@bitdrift/react-native';

// Track string variant
setFeatureFlagExposure('dark_mode', 'enabled');
setFeatureFlagExposure('new_ui', 'variant_b');

// Track boolean variant
setFeatureFlagExposure('experimental_feature', true);
setFeatureFlagExposure('beta_mode', false);

Entity Identification

Sets an entity identifier for backend correlation with device identifier. The value is hashed for storage and the exact value is never persisted.

import { clearEntityId, setEntityId } from '@bitdrift/react-native';

setEntityId('user-123');
setEntityId('account-456');
clearEntityId();

Tracing State

Use isTracingActive() to synchronously check whether trace propagation is currently active.

import { init, isTracingActive, SessionStrategy } from '@bitdrift/react-native';

init('<api key>', SessionStrategy.Activity);

const tracingActive = isTracingActive();
console.log('Tracing active?', tracingActive);
  • It returns false when tracing is not active or the SDK is not running.

Network Integration

The automatic capture of network requests can be achieved in a few different ways depending on the platform and the networking library being used.

iOS

When initializing via JS, pass enableNetworkInstrumentation: true as one of the options to init:

import { init, SessionStrategy } from '@bitdrift/react-native';

init('<api key>', sessionStrategy: SessionStrategy.Activity, {
  enableNetworkInstrumentation: true
});

Enabling this via the Objective-C API is not yet supported if initialization is done via the native API - please reach out if there is interest in this feature.

Android

To enable automatic OkHttp instrumentation on Android, add the io.bitdrift.capture-plugin plugin in the app build.gradle file:

plugins {
    id 'io.bitdrift.capture-plugin' version '<version>'
}

To find the version to use, use the same version of the Capture SDK that is being used in the React Native project. Check the build.gradle file in the node_modules/@bitdrift/react-native/android directory for the version of the Capture SDK being used.

For manual Gradle setup, enable plugin instrumentation:

bitdrift {
    instrumentation {
        automaticOkHttpInstrumentation = true
        // Optional. Defaults to PROXY when omitted.
        // okHttpInstrumentationType = OVERWRITE
    }
}

In addition to this the plugin repository needs to be added to the pluginManagement block in the settings.gradle file:

pluginManagement {
    repositories {
        mavenCentral()
        gradlePluginPortal()
        maven {
            url 'https://dl.bitdrift.io/sdk/android-maven'
            content {
                includeGroupByRegex "io\\.bitdrift.*"
            }
        }
    }
}

When using Expo to generate the project, this can be achieved by setting the networkInstrumentation option to true in the app.json file:

{
  "expo": {
    "plugins": [
        [
          '@bitdrift/react-native',
          {
            networkInstrumentation: true,
          },
        ],
    ]
  }
}

When using the Expo plugin with networkInstrumentation: true, the Android Gradle plugin and bitdrift { instrumentation { ... } } block are generated automatically.

WebView Integration

UNSTABLE_webViewInstrumentation is currently Android-only and is intended for Android app builds.

Runtime capture is enabled separately with UNSTABLE_webView in init(...):

import { init, SessionStrategy } from '@bitdrift/react-native';

init('<api key>', SessionStrategy.Activity, {
  UNSTABLE_webView: {
    capturePageViews: true,
    captureNetworkRequests: true,
    captureNavigationEvents: true,
    captureWebVitals: true,
    captureLongTasks: true,
    captureConsoleLogs: true,
    captureUserInteractions: true,
    captureErrors: true,
  },
});

For Expo-generated Android apps, enable build-time WebView bytecode instrumentation with:

{
  "expo": {
    "plugins": [
      [
        "@bitdrift/react-native",
        {
          "UNSTABLE_webViewInstrumentation": true
        }
      ]
    ]
  }
}

Notes:

  • UNSTABLE_webViewInstrumentation currently only affects Android app builds.
  • It is not used by iOS.
  • It is not automatically applied to vanilla React Native Android builds outside the Expo config plugin flow.
  • For non-Expo Android apps, apply the Gradle plugin and bitdrift { instrumentation { automaticWebViewInstrumentation = true } } manually.

The Android plugin mode can be configured with okHttpInstrumentationType:

{
  "expo": {
    "plugins": [
      [
        "@bitdrift/react-native",
        {
          "networkInstrumentation": true,
          "okHttpInstrumentationType": "OVERWRITE"
        }
      ]
    ]
  }
}

okHttpInstrumentationType is Android-only and has no effect on iOS.

  • PROXY (default): preserves existing EventListener.Factory behavior in OkHttp clients.
  • OVERWRITE: replaces the listener factory and can avoid duplicate network spans in some app setups.

If you recently upgraded and started seeing duplicate spans on Android, set okHttpInstrumentationType to OVERWRITE.