Skip to main content

Official Coralogix React Native plugin

npm version

This package replaces the old @coralogix/react-native-sdk package.

Usage​

To use Coralogix SDK, call CoralogixRum.init(options) at the soonest available moment after the app loads. This will initialize the SDK based on the options you provided. init is an async function.

import { CoralogixRum } from '@coralogix/react-native-plugin'

await CoralogixRum.init({
application: 'app-name',
environment: 'production',
public_key: 'abc-123-456',
coralogixDomain: 'EU2',
version: 'v1.0.3',
labels: {
payment: 'visa',
},
ignoreErrors: ['some error message to ignore'],
ignoreUrls: [/.*\.svg/, /.*\.ico/], // will ignore all requests to .svg and .ico files
sessionSampleRate: 100, // Percentage of overall sessions being tracked, Default to 100%
});

The native SDK applies sessionSampleRate once per session, including each new session after the previous one expires. Set it to a whole percentage in 0-100. The plugin rounds a fractional value to an integer, and never rounds a non-zero rate down to 0, because the native bridges read the value as an integer.

A sampled-out session still initializes the SDK and, when traceParentInHeader is enabled, still adds the traceparent header to outgoing requests, so backend traces stay correlated. Beyond that it reports nothing unless excludeFromSampling lists at least one category: no initialization event, and no session_replay_init even when Session Replay starts. List a category and that category is reported, together with the SDK's own internal events.

To provide contextual information or transmit manual logs, utilize the exported functions of CoralogixRum. Keep in mind that these functions will remain inactive until you've invoked CoralogixRum.init().

import { CoralogixRum } from '@coralogix/react-native-plugin';

// Update user context dynamically
CoralogixRum.setUserContext({
user_id: '123',
user_name: 'name',
user_email: '[email protected]',
account_id: 'acc-42', // optional, from 0.12.0
account_name: 'Acme Corp', // optional, from 0.12.0
user_metadata: {
role: 'admin',
// ...
},
});

// Update custom labels dynamically
CoralogixRum.setLabels({
...CoralogixRum.getLabels(),
paymentMethod: 'visa',
userTheme: 'dark',
// ...
});

// Update application context dynamically
CoralogixRum.setApplicationContext({
application: 'app-name',
version: '1.0.0',
});

CoralogixRum.log(CoralogixLogSeverity.Error, 'this is a log', { key: 'value' });
CoralogixRum.error('this is a log with error severity', { key: 'value' });

Optional - Coralogix Gradle plugin (Android)​

The Coralogix Gradle Plugin automatically instruments all OkHttp clients in your app (including third-party SDKs) at build time. This ensures that all network traffic is automatically traced and reported to Coralogix, with no manual setup or code changes required. This plugin is especially useful for instrumenting networking libraries that create their own OkHttpClient instances internally and would otherwise be impossible to monitor.

Apply the plugin​

  1. Add the plugin to your project classpath
    In your project-level build.gradle file:

    buildscript {
    dependencies {
    classpath "com.coralogix.gradle.plugin:gradle-plugin:0.0.2"
    }
    }
  2. Apply the plugin in your app module
    At the top of your app-level build.gradle file:

    apply plugin: "com.coralogix.gradle.plugin"

Configure the plugin​

The plugin exposes a simple Gradle extension you can use in your app module:

coralogix {
// Enable or disable instrumentation (default: true)
enabled = true

// Print debug logs during the build process (default: false)
log = false
}

If the default configuration suits your needs, you can safely omit this block — the defaults will apply automatically.

Note​

This plugin is optional. Regular JavaScript fetch calls and standard network requests will still be instrumented without it.

However, the plugin is the only way to capture network activity from third-party libraries or SDKs that use their own OkHttpClient instances internally.

Troubleshooting​

URL.origin is not implemented​

  1. npm install react-native-url-polyfill
  2. At the top of your entry-point file (index.js) add: import "react-native-url-polyfill/auto"
Last updated on
On this page
Was this page helpful?