Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@madgex/datadog-monitoring
Advanced tools
All your Hapi + Datadog needs, in one handy package.
When used as a module, this library exports:
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, dataDogStats } = 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'],
},
},
{
plugin: dataDogStats,
options: {
DD_AGENT_HOSTNAME,
DD_AGENT_DSTATS_PORT,
},
},
]);
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
version: pkg.version,
profiling: true,
analytics: true,
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:
The dataDogStats plugin decorates your hapi server object with dStats client. This client can call dstats functions like increment() with parameters:
server.dataDogStats.increment(name, value, tags)
similarJobsCallSuccess:success
]This plugin is running hot-shots module. Full usage docs here: https://www.npmjs.com/package/hot-shots#check
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. It works by running the server in a separate, child process and piping that process's stdout stream through a transform and write stream to send to the Datadog agent. It's intended to be used as a replacement for the usual node /entry/point.js
in the npm start script, like so:
"start": "dd-monitor /path/to/server.js --hostname [hostname] --port [port] --echo --debug"
It accepts the following flags:
The log transport is fundamentally very simple, but requires a basic understanding of Node streams- I'd recommend reading this article from Node Source on Understanding Streams in Node.js. All the transport does is spawn a child process to run the passed server, and hook the stream of that child process's standard output into a transform stream, to format the logs for Datadog, and then pipe that transform stream to a write stream which sends what it receives over a UDP connection to the Datadog Agent.
The unit tests can be run with Jest by running npm run test
.
The integration tests for the transport check that it is successfully transmitting messages from an emitter process (which just logs a sequence of messages into stdout, standing in for the server) to a listener process (which is a simple UDP socket, standing in for the Datadog Agent). They can be run with npm run test:integration
. The test can be controlled with the constants in test/integration/constants.js.
FAQs
All your Hapi + Datadog needs, in one handy package.
The npm package @madgex/datadog-monitoring receives a total of 96 weekly downloads. As such, @madgex/datadog-monitoring popularity was classified as not popular.
We found that @madgex/datadog-monitoring demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.