@atatus/browser-logs sends logs from the browser to Atatus. It collects console output and unhandled errors for you, and gives you a logger for your own structured messages. When RUM is running on the same page, logs share its session and user, so you can jump from a session to the logs it produced. This page covers setup, options, and the logger API.

Install and initialize

Install the package:
If you are not using a bundler, load it from the CDN instead and initialize window.ATATUS_LOGS with the same options:
Initialize it once, alongside your RUM setup:

Options

These options are specific to logs: The shared options also apply here, including licenseKey, appName, env, version, service, site, serverUrl, sessionSampleRate, trackingConsent, and the session storage settings. See Configuration for those. Pass the same site you pass to atatusRum.init() so logs and RUM reach the same region.
forwardConsoleLogs: 'all' captures every console call, including console.log. On a chatty application that can be a lot of volume. Start with ['error', 'warn'] and widen it if you need more.

Write logs

Use the default logger for most messages. Pass an object as the second argument to attach structured context:
The third argument is an Error, and the agent reads its stack trace.

Levels

Nine levels are available, in ascending order of severity: ok, debug, info, notice, warn, error, critical, alert, emerg Set a minimum level to drop anything below it:

Scoped loggers

Create a named logger per area of your application, so you can filter by it later:
Retrieve it elsewhere by name:

Add context to every log

Global context is attached to every log the SDK sends:
To attribute logs to a person or account, set the user and account, exactly as you do for RUM:

Redact before sending

beforeSend runs on each log just before it is sent. Return false to drop it:

Next steps