Configuration
Every option the Apperio constructor accepts, with its type and default.
This page describes apperio 1.5.2, the current version on npm. Every option is passed to the Apperio constructor.
Minimal setup
import { Apperio } from 'apperio';
const logger = new Apperio({
apiKey: 'your-api-key',
projectId: 'your-project-id',
});apiKey and projectId are required; the constructor throws Apperio: API Key is required. or Apperio: Project ID is required. without them. The constructor also starts the logger, so don’t call init() yourself.
All options
| Option | Type | Default | What it does |
|---|---|---|---|
apiKey | string | required | Your project’s API key, sent as X-API-Key. |
projectId | string | required | Your project’s ID. |
endpoint | string | https://apperioserver.onrender.com/api/v1 | Where logs are sent. Leave it alone unless Apperio tells you otherwise. |
minLogLevel | LogLevel | LogLevel.INFO | Logs below this level are dropped in the SDK and never sent. |
batchSize | number | 10 | Send as soon as this many logs are waiting. The API takes at most 100 logs per request, so keep it at 100 or less. |
flushIntervalMs | number | 5000 | Send whatever is waiting this often, in milliseconds. |
maxRetries | number | 3 | Extra attempts when sending fails with a network error or a 5xx response. |
retryDelayMs | number | 1000 | Wait before the first retry. It doubles for each later one. |
environment | string | 'development' | Tags every log. Set it to 'production' in production. |
serviceName | string | 'unknown-service' | Tags every log with the part of your system that sent it. |
release | string | none | Tags every log with the version of your code. |
autoCapture | object | see below | Which browser events are captured automatically. |
sanitization | { enabled?, config? } | { enabled: true } | PII redaction. See Data sanitization. |
offline | OfflineManagerConfig | {} | The browser’s offline queue. See Delivery and offline. |
remoteConfig | RemoteConfigOptions | { enabled: false } | Fetch some settings from the dashboard. See Delivery and offline. |
tracing | { enabled? } | { enabled: false } | Trace and span IDs on logs. See Tracing. |
replay | ReplayOptions | follows the dashboard | Session replay, browser only. See Replay options. |
enablePatternDetection | boolean | true | Log a warning when the same error repeats or errors spike. See Error tracking. |
onPatternDetected | function | none | Called with each detected pattern. |
autoCapture
| Field | Default | Captures |
|---|---|---|
errors | true | Uncaught errors and unhandled promise rejections. |
performance | true | Page load, resource and paint timing, and Web Vitals. |
networkRequests | true | fetch and XMLHttpRequest calls. |
pageViews | true | The first page view and every history change. |
consoleMessages | false | console.error, warn, log, info and debug calls. |
userInteractions | false | Clicks, focus, blur, scrolling and key presses (without the keys). |
Fields you leave out keep their defaults. All of these are browser only. Details and log levels are in Auto-instrumentation.
Passing a log level
LogLevel is a TypeScript enum, so in TypeScript import it rather than passing a string:
import { Apperio, LogLevel } from 'apperio';
const logger = new Apperio({
apiKey: 'your-api-key',
projectId: 'your-project-id',
minLogLevel: LogLevel.WARN,
});In plain JavaScript the string works too: minLogLevel: 'warn'. The levels, lowest first, are trace, debug, info, warn, error and fatal.
A fuller example
import { Apperio, LogLevel } from 'apperio';
export const logger = new Apperio({
apiKey: 'your-api-key',
projectId: 'your-project-id',
environment: 'production',
serviceName: 'web',
release: '2.4.1',
minLogLevel: LogLevel.INFO,
batchSize: 20,
flushIntervalMs: 10000,
autoCapture: {
consoleMessages: false,
userInteractions: false,
},
replay: {
enabled: true,
sampleRate: 0.1,
},
});Options with no effect in 1.5.2
These are part of the type, so TypeScript accepts them, but the SDK ignores them. Leave them out:
serviceVersion: never sent. Userelease.autoCapture.logLevels: auto-captured events always use the levels listed in Auto-instrumentation.tracing.autoTraceNetworkRequests: no spans are created for requests.
Settings in the dashboard
remoteConfig, and even then only some of its fields apply. See Remote config.