Node.js
Fastify

Fastify Web Application

On this page, we help you install ShortLoop SDK in your Fastify web application, so that it can automatically sample traffic.

Install

Add ShortLoop Fastify 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 Fastify Plugin after you add any content parsers or any plugin which helps you parse the request body.

...
import fastify from 'fastify'
...
 
const server = fastify()
server.addContentTypeParser('text/html', htmlBodyParser);
server.register(multipart, { addToBody: true });
// any other parsers
...
 
server.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
});

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.

...
server.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 Fastify application.

Feel free to email for a quick support, reporting bug or improvements suggestions. Sumit B Mulchandani (sumit@shortloop.dev)

Copyright © 2023 ShortLoop, Inc. All rights reserved.