Skip to main content

Logs, errors, and views

Custom Logs

Send structured logs with optional data and labels.

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

Shorthand signatures exists for all log severities:

CoralogixRum.debug('this is a debug log', {key: 'value', pi: 3.14});
CoralogixRum.error('this is an error log', {error: 'yes', is_bad: 'no'});
Note

Due to React Native limitations, not all value types are supported for the log data values. Our testing shows that React Native can't pass some types to the coralogix native layer; the ones we have identified as problematic are Map, Set, Date and Function. There could be more. For example:

// this would pass as an empty object to the coralogix native layer, same for Set and Date:
CoralogixRum.debug('this will be a problem', {key: new Map().set(1, 2)});

// this would pass as null to the coralogix native layer
CoralogixRum.debug('this will be a problem too', {key: () => {}});

in the event that you need to use any of these types please stringify them before you pass it to the log method

Error Reporting

Report handled errors with optional structured data and labels. Choose one of the variants below per error event — each call generates a single error report.

Parameters:

  • error (Error): The error object to report.
  • isCrash (boolean): Whether this error represents a crash (true) or a handled exception (false).
  • data (optional): Structured data object attached to the error event. Empty objects are omitted.
  • labels (optional): Key-value pairs for categorizing the error event. Empty objects are omitted.

Variant 1: Basic error reporting

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

try {
await processPayment(order);
} catch (error) {
CoralogixRum.reportError(error, false);
}

Variant 2: With structured data

try {
await processPayment(order);
} catch (error) {
CoralogixRum.reportError(error, false, {
orderId: '12345',
paymentMethod: 'visa',
amount: 99.99,
});
}

Variant 3: With data and labels

try {
await processPayment(order);
} catch (error) {
CoralogixRum.reportError(
error,
false,
{ orderId: '12345', amount: 99.99 },
{ team: 'payments', severity: 'high' }
);
}

Reporting crashes:

try {
await criticalOperation();
} catch (error) {
CoralogixRum.reportError(
error,
true, // isCrash = true
{ operation: 'criticalTask', stage: 'initialization' },
{ environment: 'production' }
);
}

View Tracking

To track views, set the view context whenever a view changes.

CoralogixRum.setViewContext({
view: 'Home',
});

You can automatically track view changes by using react-navigation. Use the NavigationContainer onStateChange callback to track route changes and update the view context manually, as shown below:

<NavigationContainer
ref={navigationRef}
onStateChange={() => {
const currentRouteName = navigationRef.current.getCurrentRoute().name;

CoralogixRum.setViewContext({ view: currentRouteName });
}}
>
{/* ... */}
</NavigationContainer>

Recreate Session

Recreate the RUM session on demand — for example, on user logout — so that subsequent events belong to a fresh session with a new session id.

CoralogixRum.createNewSession();
Last updated on
Was this page helpful?