@kubesense/kubesense-browser-logs
v1.2.0
Published
Send logs to Kubesense from your browser pages. The Logs SDK forwards console errors and uncaught exceptions, and lets you send your own structured log entries with severity levels and custom context.
Readme
Kubesense Browser Logs
Send logs to Kubesense from your browser pages. The Logs SDK forwards console errors and uncaught exceptions, and lets you send your own structured log entries with severity levels and custom context.
It can run standalone or alongside @kubesense/kubesense-browser-rum — when
both are present, logs are automatically correlated with the active RUM session
and view.
Installation
npm install @kubesense/kubesense-browser-logs
# or
yarn add @kubesense/kubesense-browser-logsUsage
Initialize the SDK as early as possible in your application's lifecycle:
import { kubesenseLogs } from '@kubesense/kubesense-browser-logs'
kubesenseLogs.init({
clientToken: '<KUBESENSE_CLIENT_TOKEN>',
site: '<KUBESENSE_SITE>',
forwardErrorsToLogs: true,
sessionSampleRate: 100,
})Sending logs
import { kubesenseLogs } from '@kubesense/kubesense-browser-logs'
kubesenseLogs.logger.info('Button clicked', { name: 'buttonName', id: 123 })
try {
throw new Error('Wrong behavior')
} catch (error) {
kubesenseLogs.logger.error('Error occurred', { team: 'myTeam' }, error)
}The logger exposes debug, info, warn, and error methods. Each accepts a
message, an optional context object, and an optional Error.
Documentation
See the dedicated Kubesense documentation for configuration options, custom loggers, and log filtering.
