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.

Long tasks​

The long_tasks instrumentation reports each time the page's main thread is blocked for more than 50 ms as a longtask event.

From SDK version 4.6.0, in Chromium-based browsers from version 123, these events come from the Long Animation Frame API, and a frame made only of short tasks is not reported. Their longtask_context.entryType is long-animation-frame, and longtask_context.scripts lists each script that ran for longer than 5 ms during the block, with what triggered it (invoker), its file (sourceURL), its function (sourceFunctionName) and its character position in that file (sourceCharPosition). Older Chromium versions report the event from the Long Tasks API, without scripts. Firefox and Safari report no long tasks.

Network request duration​

From SDK version 4.6.0, network_request_context.duration runs from the start of the request, redirects included, until the browser received the last byte of the response. Time the response spent waiting for a blocked main thread is not included. network_request_context.span_duration is the full time, from the request until the page handled the response, so the difference between the two shows how much a busy page delayed it. When the browser has no Resource Timing entry for a request, duration is that full time too.

Web Vitals: attribution​

From version 5.0.0, each web vital carries the full attribution that the web-vitals library reports, in web_vitals_context.attribution. That includes the performance entries behind the metric, such as the LCP entry, the page's navigation entry and the long animation frames behind INP, without their DOM references. web_vitals_context.navigationURL holds the URL of the page the metric was measured on.

The LCP element's selector is in attribution.target. attribution.element holds the same value, so existing queries keep working.

From version 5.0.0, some metrics are no longer reported:

  • FID: web-vitals removed it in favor of INP. The fid option is removed.
  • TBT and TTI: they are lab metrics, not field metrics. The tbt option is removed. For responsiveness in the field, use INP and long tasks.

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