npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

winston-datadog

v1.1.0

Published

Super light transport for logging Datadog events

Downloads

1,401

Readme

Build Status Coverage Status

Winston-Datadog

Super light transport for logging Datadog events

Install

npm install --save winston-datadog

Examples

Basic setup

const winston = require('winston');
const DatadogTransport = require('winston-datadog');
const ddTransport = new DatadogTransport({
    api_key: '',
    app_key: '' //optional
});
const logger = new winston.Logger({
    transports: [
        ddTransport
    ]
});

Receiving Results from Datadog

ddTransport.receiveResults(logger);
logger.on('DatadogResult', (res) => {
    console.log(res);
});

// disable receiver
// ddTransport.stopResults();

// start receiver on last logger
// ddTransport.receiveResults();

Event Options

var ddTransport = new Datadog({ ... });
//have the text be used in place of title (default: false)
ddTransport.useTextAsTitle = true;
//or...set the new title to use
ddTransport.options.title = 'My Custom Title';
//set the new tags to use
ddTransport.options.tags = ['env:local', 'version:1', 'region:us-west-1'];

//do stuff ...

//reset options
ddTransport.resetOptions();

Permanently Override Default Options

In case you have multiple instances of the transport running and/or find you need to permanently change the default DatadogTransport.Options

var DatadogTransport = require('winston-datadog');
var Options = DatadogTransport.prototype.Options;
Options.prototype.title = 'Custom Global Title';
Options.prototype.tags = ['custom:MyCustomTag'];
//now these changes will persist through each instance
var ddTransport = new DatadogTransport({ ... });
console.log(ddTransport.options.title);
// 'Custom Global Title'

Loglevels

When Winston passes logs off to the Datadog transport, winston-datadog will map the log type (info, warn, error, etc...) to the corresponding ddTransport.options.alert_type. A check will be done to see if the log type exists in ddTransport.loglevels, if found it will override the default log type sent from winston. We have to do this, for isntance, in order to map Winston->warn() to DatadogTransport->warning();

var ddTransport = new Datadog({ ... });
console.log(ddTransport.loglevels);
// {
//     silly: 'info',
//     debug: 'info',
//     verbose: 'info',
//     warn: 'warning'
// }

// make all info messages route to ddTransport.options.alert_type = 'success'
ddTransport.loglevels.info = 'success';
// make all verbose messages route to ddTransport.options.alert_type = 'success'
ddTransport.loglevels.verbose = 'success';

Receiving Response Data

By default, this transport only sends logs, it does not do anything with the response object. Enabling the receiver will add some overhead, but may be necessary.

Events

DatadogResult - emitted by the logger when a response object has finished receiving data. The response object will have a body object containing the resulting data.

Logging

The body of the event(log) is limited to 4000 characters and supports markdown.

Options

Each Datadog Transport instance will expose the following options via ddTransport.options

  • title [default=LOG] - The event title. Limited to 100 characters.
  • date_happened [optional, default=now] - POSIX timestamp of the event.
  • priority [optional, default='normal'] - The priority of the event ('normal' or 'low').
  • host [optional, default=os.hostname()] - Host name to associate with the event.
  • tags [optional, default='env:process.env.NODE_ENV'] - A list of tags to apply to the event.
  • alert_type [optional, default='info'] - "error", "warning", "info" or "success". (These are overriden by the default winston log levels, but you can do something about that through ddTransport.loglevels
  • aggregation_key [optional, default=None] - An arbitrary string to use for aggregation, max length of 100 characters.
  • source_type_name [optional, default=None] - The type of event being posted. Options: nagios, hudson, jenkins, user, my apps, feed, chef, puppet, git, bitbucket, fabric, capistrano

Updates

  • Added new feature useTextAsTitle / updated for NodeJS 9 - @v1.1.0 08:30 PST Nov 27th, 2017
  • Adds name to winston transports - @v1.0.2 09:03 PDT Feb 28th, 2016
  • Stable Release - @v1.0.1 21:58 PDT Feb 27th, 2016
  • Initial Release - 20:11 PDT Feb 27th, 2016
  • Check back notice - 08:09 PDT Feb 27th, 2016