Configuration
Configure the Node.js SDK with Owl.configure() — API key, endpoint, isDev, and flush options.
Call Owl.configure() once at application startup before logging any events.
Basic Configuration
import { Owl } from "@owlmetry/node";
Owl.configure({
endpoint: "https://ingest.owlmetry.com",
apiKey: "owl_client_...",
serviceName: "payment-service",
appVersion: "1.4.0",
});Options
| Option | Type | Default | Description |
|---|---|---|---|
endpoint | string | required | Owlmetry server URL. Trailing slashes are stripped automatically. |
apiKey | string | required | Client API key for a backend-platform app. Must start with owl_client_. |
serviceName | string | "unknown" | Name of this service. Useful for identifying which backend emitted an event when you run multiple services. |
appVersion | string | undefined | Version string included on every event. |
debug | boolean | false | When true, SDK internals log to console.error -- failed requests, slug corrections, experiment save errors. |
isDev | boolean | process.env.NODE_ENV !== "production" | Marks all events with is_dev: true. Defaults to true unless NODE_ENV is "production". See Data Mode. |
flushIntervalMs | number | 5000 | Milliseconds between automatic buffer flushes. |
flushThreshold | number | 20 | Maximum buffered events before an automatic flush is triggered. |
maxBufferSize | number | 10000 | Hard cap on buffered events. When the buffer is full, the oldest event is dropped. |
consoleLogging | boolean | true | Print events to the console. Each line is prefixed with 🦉 Owlmetry and the log level. Set to false to suppress. |
What Happens on Configure
When Owl.configure() is called:
- Validates the endpoint URL and API key format
- Generates a session ID -- a fresh UUID that groups all events until the next
configure()call orshutdown(). This is the default session ID; for servers that handle many clients, per-request overrides are available viaOwl.withSession()and theoptions.sessionIdparameter on event methods - Starts the flush timer -- the buffer is flushed every
flushIntervalMsmilliseconds - Registers a
beforeExithandler -- automatically flushes remaining events when the Node.js process exits gracefully - Loads experiment assignments from
~/.owlmetry/experiments.json(see Experiments) - Prepares the session bracket -- a
sdk:session_startedevent is emitted lazily, just before the first user-tracked event. Cold-started processes that never callOwl.info()/Owl.step()/ etc. produce no events at all. The matchingsdk:session_endedevent is emitted onshutdown()only if a session ever started
If you call configure() again (for example during hot reload), the previous transport is shut down cleanly before the new one starts.
isDev and Data Mode
The isDev option controls whether events are tagged as development or production data. The Data Mode filter in the dashboard and CLI lets you separate the two.
By default, isDev is true when NODE_ENV is anything other than "production". This means:
- Running
node server.jslocally tags events as dev - Running
NODE_ENV=production node server.jstags events as production
Override it explicitly if you need different behavior:
Owl.configure({
endpoint: "https://ingest.owlmetry.com",
apiKey: "owl_client_...",
isDev: false, // always production, regardless of NODE_ENV
});Graceful Shutdown
Call Owl.shutdown() before your process exits to flush remaining events and stop the background timer:
process.on("SIGTERM", async () => {
await Owl.shutdown();
process.exit(0);
});For serverless environments, see the serverless guide which covers Owl.wrapHandler() as an alternative.
