Skip to main content

Logs and errors

Sending custom logs

import { CoralogixRum, CoralogixLogSeverity } from '@coralogix/browser';

// send custom logs with different severity levels
CoralogixRum.log(CoralogixLogSeverity.Info, 'this is a custom log');

// send custom logs with extra data
CoralogixRum.log(CoralogixLogSeverity.Error, 'this is an error custom log with extra data', { data: 'tbd' });

// send custom logs with extra data, call the error severity log directly
CoralogixRum.error('this is a custom log with error severity', { data: 'tbd' });

// send custom logs with extra data and labels
CoralogixRum.warning(
'this is a custom log message with warning severity',
{
data: 'tbd',
},
{
my_label_key: 'my label value',
}
);

// data is optional unless labels are provided, in which case data is required (can be null
CoralogixRum.log(CoralogixLogSeverity.Info, 'this is a custom log message with info severity', null, {
my_label_key: 'my label value',
});

Stringifying custom log data

By default the data you pass to a custom log is sent as a nested structure. Set stringifyCustomLogData at initialization to send it as a string instead, which is useful when data holds nested objects or arrays. Circular references are handled rather than throwing.

CoralogixRum.init({
// ...
stringifyCustomLogData: true,
});

The SDK reads this option once, when it initializes, so it applies to every custom log from that point on and cannot be changed per call.

Instrumentation's

Turn on/off specific instrumentation, default to all trues. Each instrumentation is responsible for which data the SDK will track and collect for you.

CoralogixRum.init({
// ...
instrumentations: {
xhr: true,
fetch: true,
web_vitals: false,
interactions: false,
custom: true,
errors: true,
long_tasks: true,
resources: false,
},
});
Note

The fetch and xhr instrumentations also add the trace context headers to outgoing requests. Turning both off stops trace context propagation as well, even when traceParentInHeader is enabled.

Web Vitals: TBT metric

By default, the TBT (Total Blocking Time) metric is disabled. To enable it, explicitly configure it as shown below:

{
"instrumentations": {
"web_vitals": {
"enabled": true,
"metrics": {
"tbt": true
}
}
}
}

Manually capture errors

You can pass an Error object to capture it as an event.
Additionally, you can include custom data and labels with the event.

try {
// Some code that might throw an error
} catch (error) {
CoralogixRum.captureError(error);

CoralogixRum.captureError(error, { custom_data: { id: '123' } }); // add custom data

CoralogixRum.captureError(error, { custom_data: { id: '123' } }, { label1: 'value1' }); // add custom data and labels
}
Last updated on