Hapi Web Application
On this page, we help you install ShortLoop SDK in your Hapi web application, so that it can automatically sample traffic.
Install
Add ShortLoop Hapi SDK from public npm registry.
npm install @shortloop/node@0.0.10
Configure
To configure the SDK, you need to register the plugin in your application.
Import the SDK from installed package.
import { ShortloopPlugin } from "@shortloop/node";
Initialize SDK with options - url and applicationName as shown in below example and register the middleware.
...
const server = Hapi.server({
port: 3000,
host: "localhost",
});
...
await server.register({
plugin: ShortloopPlugin,
options: {
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.
...
await server.register({
plugin: ShortloopPlugin,
options: {
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 Hapi application.
Feel free to email for a quick support, reporting bug or improvements suggestions. Sumit B Mulchandani (sumit@shortloop.dev)