NestJS Web Application (Using Fastify as an underlying web framework)
On this page, we help you install ShortLoop SDK in your NestJS web application, so that it can automatically sample traffic.
Install
Add ShortLoop NestJS SDK from public npm registry.
npm install @shortloop/fastify@0.0.6
Configure
To configure the SDK, you need to register the plugin in your application.
Import the SDK from installed package.
import { fastifyShortloopPlugin } from '@shortloop/fastify';
Initialize SDK with options - url and applicationName as shown in below example and register the plugin.
Register ShortLoop NestJS (Fastify) Plugin after you add any content parsers or any plugin which helps you parse the request body.
...
const app = await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter(), {bufferLogs: true});
...
app.register(fastifyShortloopPlugin, {
url: "https://shortloop.company-name.com", // ShortLoop URL. (Provided by ShortLoop team.)
applicationName: 'service-name', // your application name here
authKey: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // ShortLoop Auth Key. (Provided by ShortLoop team.)
environment: "your-environment", // for e.g stage or prod
});
...
await app.listen(8080);
To mask sensitive headers, provide a list as maskHeaders
field as shown in below example.
Note that maskHeaders
field is optional and headers are case insensitive.
...
app.register(fastifyShortloopPlugin, {
url: "https://shortloop.company-name.com", // ShortLoop URL. (Provided by ShortLoop team.)
applicationName: 'service-name', // your application name here
authKey: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // ShortLoop Auth Key. (Provided by ShortLoop team.)
environment: "your-environment", // for e.g stage or prod
maskHeaders: ["cookie", "x-auth"] // [Optional]. The following headers values will be masked at the SDK level itself. (Will not be sent to the server)
});
Verify
Quickly test if project is building after configuring SDK.
Build command maybe custom to your project.
npm run build
After the changes, redeploy your NestJS (Fastify) application.
Feel free to email for a quick support, reporting bug or improvements suggestions. Sumit B Mulchandani (sumit@shortloop.dev)