Skip to main content
The Honeycomb OpenTelemetry React Native SDK is Honeycomb’s distribution of OpenTelemetry for React Native applications. It includes instrumentation for things like detecting slow event loops or unhandled exceptions, and provides a component to simplify navigation instrumentation. This page covers basic usage of the SDK. If you just want to see some code, check out the example on GitHub.

Installing the SDK

Before you can use Honeycomb’s OpenTelemetry React Native SDK, you need to install it and configure platform-specific dependencies.
  1. Configure Metro to recognize package.json exports. To do this, create a new file, metro.config.js, in your application’s root directory. Enable package.json exports in your Metro configuration.
    Here’s an example Metro configuration:
    To learn more about Metro configuration, visit Configuring Metro.
  2. Install Honeycomb’s OpenTelemetry React Native SDK in your application’s root directory using your preferred package manager.
  3. Install the necessary dependencies for each mobile platform your application supports.
    Add the following dependencies to your application’s build.gradle.
    If your application’s minSDK version is lower than 26, add core library desugaring to your android/app/build.gradle.

Initializing

Initialize the SDK at the start of your React Native application. This ensures that events such as startup time and early view loads are captured.
Initialize the SDK at the start of the onCreate() method in your main Application class.

Configuring

The Honeycomb React Native SDK can be configured using many of the configuration options from the Honeycomb Web SDK.

Adding resource attributes

Resource attributes are available on every span your instrumentation emits. Adding custom, application-specific attributes makes it easier to correlate your data to important business information. You can set resource attributes using the resourceAttributes configuration option.

Enabling sampling

The SDK includes optional deterministic head sampling. The sample rate is 1 by default, meaning every trace is exported. The example below sets a sampleRate of 40, meaning 1 in 40 traces will be exported. This sample rate will only apply to JavaScript/TypeScript traces.
You can configure a sample rate for Android traces with .setSampleRate():

Sending to OpenTelemetry Collector

In production, we recommend running an OpenTelemetry Collector. Your application sends telemetry to your Collector instead of directly to Honeycomb. Your Collector then forwards the telemetry data to Honeycomb, keeping your API key stored securely in the Collector’s configuration. Configure your Collector’s URL by setting the endpoint option when initializing the Honeycomb React Native SDK:
This example works for all platforms and shows the core configuration needed to connect your application to a Collector.
For Android, use .setApiEndpoint():

Sending to Honeycomb

To send telemetry data directly to Honeycomb, set the apiKey option with your Ingest API Key.
This example works for all platforms and shows the core configuration needed to send data directly to Honeycomb.
For Android, use .setApiKey():

Adding automatic instrumentation

The Honeycomb OpenTelemetry React Native SDK includes auto-instrumentation options for:
  • Application startup time, measured from when the native SDKs start to when the JavaScript SDK finishes initializing
  • Errors or uncaught exceptions
  • Fetch instrumentation, using the opentelemetry-instrumentation-fetch package
  • Slow event loop detection
Automatic instrumentation is enabled by default. You can enable or disable individual auto-instrumentation libraries in your configuration.

Adding custom instrumentation

Automatic instrumentation is a fast way to instrument your code, but you get more insight into your application by adding custom, otherwise known as manual, instrumentation.

Adding attributes to an active span

You can retrieve the currently active span in a trace and add attributes to it. This lets you add more context to traces and gives you more ways to group or filter traces in your queries.

Acquiring a tracer

For manual tracing, you need to get a tracer:

Creating spans

Create custom spans to get a clear view of the critical parts in your application.

Adding instrumentation to navigation

You can instrument React NativeRouter or Expo Router navigation in your application using the <NavigationInstrumentation> component.

React NativeRouter

Add a <NavigationInstrumentation> component as a child of your <NavigationContainer> component. Pass the container ref to your navigation container and your navigation instrumentation components.

Expo Router

Wrap your navigation code with a <NavigationInstrumentation> component and pass the container ref to the <NavigationInstrumentation> component.

Troubleshooting

Running into issues? Here are some common problems and ways to fix them. To explore common issues when sending data, visit Common Issues with Sending Data in Honeycomb.

File not found error on iOS

If you see an error like this when running your application on iOS:
It usually means your application’s Podfile is missing the use_frameworks! line. To resolve this error:
  1. Add use_frameworks! immediately below prepare_react_native_project! in your Podfile:
  2. Install the iOS dependencies by navigating to your ios directory and running pod install:

Not receiving native telemetry data

Unlike JavaScript code, native code does not hot reload on changes. So if you updated your AppDelegate.swift or MainApplication.kt files and still not getting native telemetry you’ll need to rebuild your application. Stop metro, the simulator, and restart the build. If this still doesn’t work try uninstalling the app and reinstalling it.