All Articles/Troubleshooting

SDK Initialization and Connection Issues

Fix common problems when setting up the SDK.


"Lognitor is not initialized"

This error means you called a log function before init(). Ensure initialization happens at application startup:

JavaScript
// app.js — first thing
import Lognitor from '@lognitor/node';
Lognitor.init({ apiKey: process.env.LOGNITOR_API_KEY });

Import Style Mismatch

All three import styles work, but don't mix initialization:

JavaScript
// Pick ONE approach:
import Lognitor from '@lognitor/node';
Lognitor.init({ apiKey: 'key' });

// OR
import { init, info } from '@lognitor/node';
init({ apiKey: 'key' });

// NOT both — the second init() overwrites the first

Environment Variable Not Set

If process.env.LOGNITOR_API_KEY is undefined, the SDK may initialize without a key and silently drop all logs. Always verify:

JavaScript
if (!process.env.LOGNITOR_API_KEY) {
  console.warn('LOGNITOR_API_KEY not set');
}

Serverless Cold Starts

In serverless environments (Lambda, Vercel Functions), the SDK initializes on every cold start. Keep init() outside the handler:

JavaScript
// Initialize OUTSIDE the handler (runs once per cold start)
const client = Lognitor.init({ apiKey: process.env.LOGNITOR_API_KEY });

// Handler runs per-request
export async function handler(event) {
  client.info('Processing');
  await client.flush();
}

React: Missing Provider

If useLognitor() throws "No provider found", ensure LognitorProvider wraps your component tree.