New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@madgex/datadog-monitoring

Package Overview
Dependencies
Maintainers
15
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@madgex/datadog-monitoring

All your Hapi + Datadog needs, in one handy package.

  • 1.3.0
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
15
Weekly downloads
 
Created
Source

Madgex Datadog Logging and Monitoring

All your Hapi + Datadog needs, in one handy package.

Usage

As a library

When used as a module, this library exports:

  • hapi-pino
  • autoLogErrors, a Hapi plugin to automatically log responses over a certain status code threshold, and all responses if passed a debug log level
  • a function to set up dd-trace

There are no mutual dependencies so each can be used independently of the others. You can use them in the setup file for your server like so:

const { pino, autoLogErrors, trace } = require('@madgex/datadog-monitoring');

async function createServer() {
  await trace({
    hostname: DD_AGENT_HOSTNAME || '',
    service: 'my-service-name',
    hapiOptions: {
      blacklist: ['/healthcheck']
    },
  });

  const Hapi = require('hapi');

  const server = new Hapi.Server({
    //etc
  })

  await server.register([
    {
      plugin: autoLogErrors,
      options: {
        level: LOG_LEVEL
      }
    },
    {
      plugin: pino,
      options: {
        prettyPrint: IS_DEV,
        level: LOG_LEVEL,
        redact: ['req.headers.authorization'],
        ignorePaths: ['/healthcheck'],
      },
    },
  ]);

  return server;
}

Note that the tracer must be initialised before requiring Hapi, in order to correctly initialise the APM.

All available options for the dd-trace Hapi plugin can be passed as hapiOptions. hostname, if not set, will default to the discoverable Datadog agent host on AWS. The trace function returns the tracer instance so further plugin configuration can be added if you wish, eg:

async function createServer() {
  const tracer = await trace({
    hostname: DD_AGENT_HOSTNAME || '',
    service: 'my-service-name',
    debug: true // enables debugging the tracer, do not enable in production
    hapiOptions: {
      blacklist: ['/healthcheck']
    },
  });

  tracer.use('redis', { analytics: true });

  // etc
}

The hapi-pino plugin should be set up as described in its documentation.

The autoLogErrors plugin accepts two config options:

  • level: the application's log level, to determine whether to log all requests. Defaults to 'info'.
  • threshold: the status code above which responses should be logged as 'warn'. Defaults to 399.

From the command line

This library also includes a custom transport to pipe Pino logs from a server's stdout to a Datadog agent over UDP, transforming the JSON format for processing and display. Optionally it can also echo the transformed messages to stdout- however this flag should not be used in production. It should be used in your npm scripts like so:

"start": "dd-monitor /path/to/server.js --hostname [hostname] --port [port] --echo --debug"

Hostname and port relate to the Datadog agent to which the transport should transmit logs, and are optional. If not set, hostname will default first to a DD_AGENT_HOSTNAME environment variable, and then to looking up the discoverable host on AWS. Port will default to a Logging__DataDogLoggingPort environment variable, but the CLI tool will throw an error and exit if no port number can be found. Passing the debug flag will additionally log when a packet is transmitted to the UDP socket; this should also not be enabled in production.

FAQs

Package last updated on 02 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc