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

datadog-events

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datadog-events

Send events to DataDog *without* DogStatsD or StatsD

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4K
decreased by-43.65%
Maintainers
1
Weekly downloads
 
Created
Source

datadog-events

npm npm David Travis license Beerpay

Send events to DataDog without DogStatsD or StatsD, using the standard DataDog API. Supports Node 6+.

Getting Started

Install

npm install datadog-events --save

Use

By default, a function is exported that will create a new instance of DataDogEvents for you. You may either use the default or create your own instance of the class:

Default Exports
const ddEvents = require('datadog-events')({ /* options */ });

async function doSomething() {
    // ...
    
    if(err) {
        await ddEvents.error('Some error!', 'These are some details');
    }
}
Create Instance
const DataDogEvents = require('datadog-events').DataDogEvents;
const ddEvents = new DataDogEvents({ /* options */ });

API Documentation

Options

Global DataDogEvents Options

The following options are available when creating a new instance of DataDogEvents or when calling the default export function.

OptionTypeRequired?DescriptionDefault
apiKeyStringYesYour DataDog API key. This may be populated using environment variable DATADOG_API_KEY.process.env.DATADOG_API_KEY
domainStringNoDataDog domain to use for the API. Useful for switching to the EU version (ex. datadoghq.eu)."datadoghq.com"
titlePrefixStringNoOptional text to prefix all event titles with.null
bodyPrefixStringNoOptional text to prefix all event bodies with.null
bodyPostfixStringNoOptional test to postfix all event bodies with.null
priorityStringNoPriority for all events. Can be either normal or low."normal"
hostStringNoOptional host name to attach to all events.null
tagsArray[String]NoOptional tags to attach to all events.[]
aggregationKeyStringNoOptional key that will allow DataDog to aggregate all events under.null
sourceTypeStringNoOptional source type name. See here.null
markdownBooleanNoFormat all event bodies as markdown.true
Event Options

The following options may be provided when sending events with any of the methods documented below. Most of these options will override the global options listed above and are all optional.

OptionTypeDescription
dateDateDate object of the event. By default, it will be the current date/time.
priorityStringPriority for the event. Can be either normal or low.
hostStringOptional host name to attach to the event.
tagsArray[String]Tags to append to the event. Tags provided will be appended to the global options.tags.
aggregationKeyStringOptional key that will allow DataDog to aggregate all events under.
sourceTypeStringOptional source type name. See here.
markdownBooleanFormat the body as markdown.

DataDogEvents Class

The main class for datadog-events.

constructor([options={}])

The constructor for DataDogEvents.

ArgumentTypeRequired?Description
options?ObjectNoGlobal options for the class.
Example
// Shortcut
const ddEvents = require('datadog-events')({ /* options */ });

// Create your own instance
const DataDogEvents = require('datadog-events').DataDogEvents;
const ddEvents = new DataDogEvents({ /* options */ });
Returns - DataDogEvents

Returns instance of DataDogEvents.

Methods

ddEvents.<error|warning|info|success>(title, body[, options={}])

Shortcut methods for ddEvents.sendEvent(). Will send an event with the given type of the method.

ArgumentTypeRequired?Description
titleStringYesTitle for the event.
bodyStringObjectError
options?ObjectNoOptional event options.
Example
ddEvents.error('There was an error!', error)
    .then(response => console.log(response));

await ddEvents.success('Completed a process!', '**The process was completed!**');
Returns - Promise[Object]

Promise resolves with object returned from the DataDog API containing status and event keys. Rejects with error if failed to send.

ddEvents.sendEvent(type, title, body[, options={}])

Sends an event to DataDog.

ArgumentTypeRequired?Description
typeStringYesAlert type of the event. Can be error, warning, info or success.
titleStringYesTitle for the event.
bodyStringObjectError
options?ObjectNoOptional event options.
Example
ddEvents.sendEvent('warning', 'Something happened', '**Warning:** Something crazy happened')
    .then(resp => console.log(resp));

await ddEvents.sendEvent('info', 'Results from my process', resultsObject);
Returns - Promise[Object]

Promise resolves with object returned from the DataDog API containing status and event keys. Rejects with error if failed to send.

Properties

ddEvents.options - Object

The global options for the current instance of DataDogEvents. You may change any of the options at any time.

Environment Variables

Environment VariableTypeOptionDescription
DATADOG_API_KEYStringoptions.apiKeySets the API Key for DataDog automatically.
DATADOG_DOMAINStringoptions.domainSets the domain for the DataDog API.

Tests

Tests run automatically in Travis, although you may run them on your own machine. If you do, you must have your own DataDog account and API key. Make sure you add the DATADOG_API_KEY environment variable before running the tests.

DATADOG_API_KEY=MY_API_KEY npm run test

License

MIT License. See License in the repository.

Keywords

FAQs

Package last updated on 08 Apr 2019

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