The TrustPort Beacon Node.js SDK (@trusportidentity/beacon-node) provides fast performance monitoring for Express, Fastify, and NestJS applications. The middleware automatically captures every HTTP request and response; wrap database queries and outbound calls in beacon.startSpan() to trace them too.
Install via npm, yarn, or pnpm:
npm install @trusportidentity/beacon-nodeimport express from 'express';
import { BeaconSDK } from '@trusportidentity/beacon-node';
const app = express();
// Initialize SDK singleton
const beacon = new BeaconSDK({
ingestUrl: process.env.BEACON_INGEST_URL || 'https://beacon-api.trustportidentity.com',
apiKey: process.env.BEACON_API_KEY!, // tb_live_...
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 '@trusportidentity/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 {}Every request is already batched (batchSize/flushIntervalMs) instead of one network call per request. On top of that, set sampleRate (0β1, default 1) to trace only a fraction of requests in high-traffic services β this is what actually keeps you inside your plan's monthly quota. Exceptions are always sent regardless of sampling.
new BeaconSDK({ ..., sampleRate: 0.2 }) // trace ~20% of requestsOur engineering support team is ready to assist.