Installation

Currently Metlo’s Node Agent supports 3 frameworks:

  • Express
  • Koa
  • Fastify

It can be installed from npm by running:

Bash
npm install metlo

Or from yarn by running:

Bash
yarn add metlo

Configuration

Express

Metlo can be included as a standard Express Middleware.

import { initExpress as metlo } from "metlo";
// Or using require
const metlo = require("metlo").initExpress;
...
const app = express();
...
app.use(
  metlo(
    {
      key: <YOUR_METLO_API_KEY>,
      host: "http://<YOUR_METLO_HOST>:8081",
    }
  )
);

Koa

Metlo can be included as a standard Koa Middleware.

import { initKoa as metlo } from "metlo";
// Or using require
const metlo = require("metlo").initKoa;
...
const app = new Koa();
...
app.use(
  metlo(
    {
      key: <YOUR_METLO_API_KEY>,
      host: "http://<YOUR_METLO_HOST>:8081",
    }
  )
);

Fastify

Metlo can be included as a standard Fastify plugin.

import { initFastify as metlo } from "metlo";
// Or using require
const metlo = require("metlo").initFastify;
...
const fastify = Fastify();
...
fastify.register(
  metlo(
    {
      key: <YOUR_METLO_API_KEY>,
      host: "http://<YOUR_METLO_HOST>:8081",
    }
  )
);

Extra configuration

Metlo for NodeJS can further be customized to add more context to collected traces or to enable/disable functionality.

  • host : Location of the Metlo instance
  • key : API key used for collecting to Metlo
  • backendPort : Backend port used by Metlo.
  • collectorPort : Collector port used to capture traces. Defaults to 8081
  • logLevel : The log level Metlo should log at. Can be
    • trace
    • info
    • debug
    • warn
    • error
  • getUser : A function that takes in a request/response or context and returns the user for that request. By default, Metlo collects no information about user of a request.
  • rejectResponse : Response to return when Metlo is set to block malicious requests.
  • maxBodyCaptureSize : Max size of request/response bodies that Metlo should capture. Defaults to 5 KB
  • disableBlocking : Used to disable request blocking by Metlo.

In addition, Metlo accepts two environment variables

  • METLO_DISABLE_BLOCKING : If provided a truthy value (true, 1, yes), then will disable request blocking by Metlo. Defaults to false.
  • METLO_ENABLE : If left unset or provided a truthy value (true, 1, yes), then will enable Metlo. Conversely, providing a value other than that listed above would disable Metlo. Defaults to true