Installing the SDK
Before you can use Honeycomb’s OpenTelemetry React Native SDK, you need to install it and configure platform-specific dependencies.-
Configure Metro to recognize
package.jsonexports. To do this, create a new file,metro.config.js, in your application’s root directory. Enablepackage.jsonexports in your Metro configuration.Here’s an example Metro configuration: -
Install Honeycomb’s OpenTelemetry React Native SDK in your application’s root directory using your preferred package manager.
- npm
- yarn
-
Install the necessary dependencies for each mobile platform your application supports.
- Android
- iOS
Add the following dependencies to your application’sbuild.gradle.If your application’sminSDKversion is lower than 26, add core library desugaring to yourandroid/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.- Android
- iOS
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 theresourceAttributes configuration option.
Enabling sampling
The SDK includes optional deterministic head sampling. The sample rate is1 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.
- Android
- iOS
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 theendpoint option when initializing the Honeycomb React Native SDK:
- Android
- iOS
For Android, use
.setApiEndpoint():Sending to Honeycomb
To send telemetry data directly to Honeycomb, set theapiKey option with your Ingest API Key.
- Android
- iOS
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
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:Podfile is missing the use_frameworks! line.
To resolve this error:
-
Add
use_frameworks!immediately belowprepare_react_native_project!in yourPodfile: -
Install the iOS dependencies by navigating to your
iosdirectory and runningpod install:
Not receiving native telemetry data
Unlike JavaScript code, native code does not hot reload on changes. So if you updated yourAppDelegate.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.