The TrustPort Beacon Node.js SDK offers zero-config auto-instrumentation for Express, Fastify, and NestJS applications, automatically timing database queries (Prisma, TypeORM, Mongoose) and HTTP fetch calls.
Install via npm, yarn, or pnpm:
npm install @trustport/beacon-nodeimport express from 'express';
import { BeaconSDK } from '@trustport/beacon-node';
const app = express();
// Initialize SDK singleton
const beacon = new BeaconSDK({
ingestUrl: process.env.BEACON_INGEST_URL || 'http://localhost:8443',
apiKey: process.env.BEACON_API_KEY || 'tp_live_9f8a3c4e12',
serviceName: 'billing-api',
environment: 'production',
sanitizePii: true, // Automatically masks credit cards and auth headers
});
// Register global telemetry middleware before any routes
app.use(beacon.expressMiddleware());
app.get('/api/v1/invoices', async (req, res) => {
const span = beacon.startSpan('db.prisma.findMany_invoices');
try {
// Database query execution...
span.setTag('tenant_id', req.headers['x-tenant-id']);
res.json({ success: true, count: 12 });
} finally {
span.end();
}
});
app.listen(3000, () => console.log('Server running with Beacon APM'));import { Module } from '@nestjs/common';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { BeaconInterceptor, BeaconModule } from '@trustport/beacon-node/nestjs';
@Module({
imports: [
BeaconModule.forRoot({
ingestUrl: process.env.BEACON_INGEST_URL,
apiKey: process.env.BEACON_API_KEY,
serviceName: 'user-service-nestjs',
}),
],
providers: [
{
provide: APP_INTERCEPTOR,
useClass: BeaconInterceptor,
},
],
})
export class AppModule {}Our engineering support team is ready to assist.