@pushpress/datadog
v0.5.1
Published
datadog SDK for pushpress applications
Readme
PushPress Datadog
The PushPress Datadog package provides a simple interface for creating traces in Datadog.
Installation
Install the package from npm:
npm install @pushpress/datadogUsage
Initialization
Import the initDDTrace function and call it with the appropriate configuration.
const tracer = await initDDTracer({
hypervisorApiUrl: "http://<some-ip-address>",
defaults: { service: "auth", env: "development" },
metrics: [{ name: "auth.login.success" }],
});
export { tracer };Metrics
Use the Tracer instance to submit metrics.
// increments a counter metric
tracer.increment("auth.login.success");Optionally pass custom configuration such as tags and tune the sampling rate.
tracer.increment("auth.login.success", {
tags: {
outcome: "login",
oauthRateLimitThreshold: 100,
}
sampleRate: 0.1,
});Lower sample rates may be appropriate for more frequently occurring metrics while custom tags can be used to filter and aggregate metrics in Datadog by custom dimensions.
Development
Get stated by cloning the repo and running the following commands:
pnpm installInteractive Development
To execute traces interactively see the statsd repo for instructions on how to run the daemon.
While running the statsd daemon you can create traces using @pushpress/datadog from the node REPL.
pnpm replThen use the @pushpress/datadog package to create traces.
> const { initDDTracer } = require('./dist/datadog')
> const tracer = initDDTracer({ overrides: { fetchAgentHost: false }, metrics: [{ name: "sample"}, defaults: { service: "repl", env: "repl"}]})
> tracer.increment("sample")You should see the trace in stdout of the statsd daemon.
Testing
To run the unit tests with pnpm:
pnpm testSemantic Versioning
This project follows semantic versioning. All merges to main will trigger a release. Commit messages will be parsed to determine the next version. Minor version bumps will be triggered by commits that include MINOR in the commit message. Major version bumps will be triggered by commits that include MAJOR in the commit message. Patch version bumps will be triggered by all other commits.
See semantic versioning documentation for details on semantic versioning.
