launchlayer-apm
v0.2.1
Published
Lightweight APM SDK for Node.js — auto-instruments Express, Fastify, Next.js, PostgreSQL, and Prisma
Maintainers
Readme
launchlayer-apm
Lightweight APM SDK for Node.js. Auto-instruments Express, Fastify, Next.js, PostgreSQL, and Prisma with zero code changes.
Quick Start
npm install launchlayer-apmconst { initAPM } = require('launchlayer-apm');
initAPM({
serviceName: 'my-api',
collectorUrl: 'https://apm.launchlayer.store',
apiKey: 'your-api-key',
});That's it. Express routes, pg queries, and HTTP spans are captured automatically.
Auto Mode (zero code)
APM_SERVICE_NAME=my-api APM_API_KEY=your-key APM_COLLECTOR_URL=https://apm.launchlayer.store \
node --require launchlayer-apm/auto app.jsEnvironment Variables
| Variable | Default | Description |
|----------|---------|-------------|
| APM_COLLECTOR_URL | http://127.0.0.1:9999 | Collector endpoint (or local agent) |
| APM_SERVICE_NAME | unknown | Your service name |
| APM_ENV | production | Environment (production/staging/dev) |
| APM_VERSION | 0.0.0 | Service version |
| APM_API_KEY | — | Bearer token for authentication |
| APM_SAMPLE_RATE | 1.0 | Trace sampling rate (0-1) |
| APM_DEBUG | false | Enable debug logging |
Framework Examples
Express (automatic)
const { initAPM } = require('launchlayer-apm');
initAPM({ serviceName: 'express-app' });
// Express routes are auto-instrumented — no middleware needed
const app = require('express')();
app.get('/api/users', (req, res) => res.json([]));
app.listen(3000);Fastify (plugin)
const { initAPM, apmFastifyPlugin } = require('launchlayer-apm');
const transport = initAPM({ serviceName: 'fastify-app' });
const app = require('fastify')();
app.register(apmFastifyPlugin, { transport, serviceName: 'fastify-app' });
app.listen({ port: 3000 });Next.js
// instrumentation.ts (Next.js 13+)
const { initAPM } = require('launchlayer-apm');
initAPM({ serviceName: 'nextjs-app' });Prisma
const { initAPM, createPrismaMiddleware, createPrismaQueryHandler } = require('launchlayer-apm');
const { PrismaClient } = require('@prisma/client');
const transport = initAPM({ serviceName: 'my-api' });
const prisma = new PrismaClient({ log: [{ emit: 'event', level: 'query' }] });
// Option A: Model-level operations
prisma.$use(createPrismaMiddleware(transport, { serviceName: 'my-api' }));
// Option B: Raw SQL with timing
prisma.$on('query', createPrismaQueryHandler(transport, { serviceName: 'my-api' }));How It Works
- Express/Next.js: Monkey-patches router to capture HTTP method, route, status, duration
- PostgreSQL (pg): Patches
Client.prototype.queryto capture SQL, table, duration - Prisma: Hooks into middleware/$on events
- Batching: Spans are batched (default 100) and flushed every 5s
- Fire-and-forget: Never blocks your application
License
MIT
