Skip to content

Environments

The auralog SDK works in Node.js, browsers, and edge runtimes. Each environment has small differences in setup.

Standard setup. Call shutdown() before your process exits to flush remaining logs:

import { init, auralog, shutdown } from "auralog-sdk";
init({ apiKey: "aura_..." });
auralog.info("Server started", { port: 3000 });
process.on("SIGTERM", async () => {
await shutdown();
process.exit(0);
});

Works the same as Node.js. The SDK automatically listens for browser-specific error events (window.onerror, window.onunhandledrejection).

import { init } from "auralog-sdk";
init({
apiKey: "aura_...",
environment: "production",
});

For projects without a bundler, see Installation — IIFE bundle.

Cloudflare Workers don’t allow setTimeout in the global scope. Use a lazy initialization pattern — initialize auralog inside your request handler and pass the Worker’s fetch function:

import { init, auralog, shutdown } from "auralog-sdk";
let initialized = false;
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
if (!initialized) {
init({ apiKey: env.AURALOG_API_KEY }, fetch);
initialized = true;
}
try {
// Your handler logic
return new Response("OK");
} catch (err) {
auralog.error(err.message, {}, err.stack);
return new Response("Internal Error", { status: 500 });
} finally {
ctx.waitUntil(shutdown());
}
},
};

Key differences:

  • Lazy init — call init() inside the handler, not at the top level.
  • Pass fetch — Workers require an explicit fetch reference as the second argument.
  • ctx.waitUntil — ensures logs are flushed before the Worker exits.