From a32817a8840738ac88bff96da4a29fe4e8867576 Mon Sep 17 00:00:00 2001 From: Rob Brackett Date: Wed, 10 Sep 2025 19:03:54 -0700 Subject: [PATCH 1/9] Convert integration check to ESM This also breaks it up into a library and an actual script. This is in preparation for making it possible to run in TypeScript for Deno. --- .eslintrc.json | 7 +++++++ package.json | 2 +- test-other/integration_check.mjs | 12 +++++++++++ test-other/integration_check_deno.ts | 12 +++++++++++ ...ion_check.js => integration_check_lib.mjs} | 21 ++++++------------- 5 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 test-other/integration_check.mjs create mode 100644 test-other/integration_check_deno.ts rename test-other/{integration_check.js => integration_check_lib.mjs} (91%) diff --git a/.eslintrc.json b/.eslintrc.json index 8d437c7..e457dc8 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -48,6 +48,13 @@ "rules": { "max-statements": ["off"] } + }, + { + "files": ["**/*.mjs"], + "parserOptions": { + "ecmaVersion": 2019, + "sourceType": "module" + } } ] } diff --git a/package.json b/package.json index 3c44beb..3c1724f 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "scripts": { "prepack": "npm run clean && npm run build-types && npm run check-types", "test": "mocha --reporter spec", - "check-integration": "node test-other/integration_check.js", + "check-integration": "node test-other/integration_check.mjs", "check-codestyle": "npx eslint .", "check-text": "test-other/lint_text.sh", "build-types": "tsc --build", diff --git a/test-other/integration_check.mjs b/test-other/integration_check.mjs new file mode 100644 index 0000000..bd3f274 --- /dev/null +++ b/test-other/integration_check.mjs @@ -0,0 +1,12 @@ +/** + * A basic test of our complete integration with Datadog. This check sends some + * metrics, then queries to make sure they actually got ingested correctly by + * Datadog and will show up as expected. + */ + +import { main } from './integration_check_lib.mjs'; + +main().catch(error => { + process.exitCode = 1; + console.error(error); +}); diff --git a/test-other/integration_check_deno.ts b/test-other/integration_check_deno.ts new file mode 100644 index 0000000..552ec9e --- /dev/null +++ b/test-other/integration_check_deno.ts @@ -0,0 +1,12 @@ +/** + * A basic test of our complete integration with Datadog. This check sends some + * metrics, then queries to make sure they actually got ingested correctly by + * Datadog and will show up as expected. + */ + +import { main } from './integration_check_lib.mjs'; + +main({ variant: 'deno' }).catch(error => { + process.exitCode = 1; + console.error(error); +}); diff --git a/test-other/integration_check.js b/test-other/integration_check_lib.mjs similarity index 91% rename from test-other/integration_check.js rename to test-other/integration_check_lib.mjs index a9c884a..868041f 100644 --- a/test-other/integration_check.js +++ b/test-other/integration_check_lib.mjs @@ -4,10 +4,8 @@ * Datadog and will show up as expected. */ -'use strict'; - -const { client, v1 } = require('@datadog/datadog-api-client'); -const datadogMetrics = require('..'); +import { client, v1 } from '@datadog/datadog-api-client'; +import datadogMetrics from '../index.js'; function floorTo(value, points) { const factor = 10 ** points; @@ -46,7 +44,7 @@ const testMetrics = [ }, ]; -async function main() { +export async function main() { datadogMetrics.init({ flushIntervalSeconds: 0 }); for (const metric of testMetrics) { @@ -64,7 +62,7 @@ async function main() { } } -async function sendMetric(metric) { +export async function sendMetric(metric) { console.log(`Sending random points for ${metric.type} "${metric.name}"`); for (const [timestamp, value] of testPoints) { @@ -75,7 +73,7 @@ async function sendMetric(metric) { } } -async function queryMetric(metric) { +export async function queryMetric(metric) { const configuration = client.createConfiguration({ authMethods: { apiKeyAuth: process.env.DATADOG_API_KEY, @@ -95,7 +93,7 @@ async function queryMetric(metric) { return data.series && data.series[0]; } -async function waitForSentMetric(metric) { +export async function waitForSentMetric(metric) { const endTime = Date.now() + MAX_WAIT_TIME; while (Date.now() < endTime) { console.log(`Querying Datadog for sent points in ${metric.type} "${metric.name}"...`); @@ -131,10 +129,3 @@ async function waitForSentMetric(metric) { console.log('✘ Nothing found and gave up waiting. Test failed!'); return false; } - -if (require.main === module) { - main().catch(error => { - process.exitCode = 1; - console.error(error); - }); -} From c40a505807dade549e84d82354df7c3183539ad2 Mon Sep 17 00:00:00 2001 From: Rob Brackett Date: Wed, 10 Sep 2025 19:09:53 -0700 Subject: [PATCH 2/9] Add integration check for Deno --- .github/workflows/ci.yml | 18 ++++++++++++++++++ package.json | 1 + test-other/integration_check_deno.ts | 2 +- test-other/integration_check_lib.mjs | 8 +++++++- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fb9c53f..6c194a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,6 +58,24 @@ jobs: run: | npm run check-integration + test-deno-integration: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Deno + uses: denoland/setup-deno@v2 + with: + deno-version: '~2.0' + - name: Check Integration + env: + DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }} + DATADOG_APP_KEY: ${{ secrets.DATADOG_APP_KEY }} + DATADOG_SITE: ${{ secrets.DATADOG_API_HOST }} + run: | + cd test-other + deno --allow-all integration_check_deno.ts + lint: runs-on: ubuntu-latest steps: diff --git a/package.json b/package.json index 3c1724f..e0fa85a 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "datadog-metrics", "version": "0.13.0-dev", "description": "Buffered metrics reporting via the Datadog HTTP API", + "type": "commonjs", "main": "index.js", "types": "dist/index.d.ts", "repository": { diff --git a/test-other/integration_check_deno.ts b/test-other/integration_check_deno.ts index 552ec9e..d4bc933 100644 --- a/test-other/integration_check_deno.ts +++ b/test-other/integration_check_deno.ts @@ -6,7 +6,7 @@ import { main } from './integration_check_lib.mjs'; -main({ variant: 'deno' }).catch(error => { +main({ tagSuffix: '-deno' }).catch(error => { process.exitCode = 1; console.error(error); }); diff --git a/test-other/integration_check_lib.mjs b/test-other/integration_check_lib.mjs index 868041f..3173226 100644 --- a/test-other/integration_check_lib.mjs +++ b/test-other/integration_check_lib.mjs @@ -44,7 +44,13 @@ const testMetrics = [ }, ]; -export async function main() { +export async function main({ tagSuffix = '' } = {}) { + if (tagSuffix) { + for (const metric of testMetrics) { + metric.tags = metric.tags.map(tag => `${tag}${tagSuffix}`); + } + } + datadogMetrics.init({ flushIntervalSeconds: 0 }); for (const metric of testMetrics) { From 4af223a7a03f0168fb247644b05ae7475dcaf9ab Mon Sep 17 00:00:00 2001 From: Rob Brackett Date: Wed, 10 Sep 2025 19:17:17 -0700 Subject: [PATCH 3/9] Note Deno support in README --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 13c6f72..e456351 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![NPM Version][npm-image]][npm-url] [![Build Status][ci-status-image]][ci-status-url] [![Downloads Stats][npm-downloads]][npm-url] +![deno compatibility][deno-image] Datadog-metrics lets you collect application metrics through Datadog's HTTP API. Using the HTTP API has the benefit that you **don't need to install the Datadog Agent (StatsD)**. Just get an API key, install the module and you're ready to go. @@ -11,7 +12,7 @@ The downside of using the HTTP API is that it can negatively affect your app's p ## Installation -Datadog-metrics is compatible with Node.js v14 and later. You can install it with NPM: +Datadog-metrics is compatible with Node.js v14 and later and Deno 2.0 and later. You can install it with NPM: ```sh npm install datadog-metrics --save @@ -371,13 +372,13 @@ Contributions are always welcome! For more info on how to contribute or develop **Breaking Changes:** -* The minimum required Node.js version is now v14.0.0. +* The minimum required Node.js version is now v14.0.0 and Deno version is 2.0.0. * The `code` property on `AuthorizationError` instances has been changed to `DATADOG_METRICS_AUTHORIZATION_ERROR` for clarity and consistency (it was previously `DATADOG_AUTHORIZATION_ERROR`). If you are using `errorInstance.code` to check types, make sure to update the string you were looking for. **New Features:** -TBD +* Clarify this package is compatible with Deno (>= v2.0). We’ve silently worked on Deno for a long time, but never formally supported it before this release. **Deprecations:** @@ -799,3 +800,4 @@ Your contributions are always welcome! See [`CONTRIBUTING.md`](./CONTRIBUTING.md [npm-downloads]: https://img.shields.io/npm/dm/datadog-metrics.svg?style=flat-square [ci-status-image]: https://github.com/dbader/node-datadog-metrics/actions/workflows/ci.yml/badge.svg?branch=main [ci-status-url]: https://github.com/dbader/node-datadog-metrics/actions/workflows/ci.yml?query=branch%3Amain +[deno-image]: https://shield.deno.dev/deno/2.0 From 4ce46181c8f3920a67d5a3d3bf7eb2fac587fec3 Mon Sep 17 00:00:00 2001 From: Rob Brackett Date: Wed, 10 Sep 2025 19:38:41 -0700 Subject: [PATCH 4/9] Whoops, need to deno install to test against NPM modules --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6c194a3..a44e53a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,6 +67,10 @@ jobs: uses: denoland/setup-deno@v2 with: deno-version: '~2.0' + + - name: Install dependencies + run: deno install + - name: Check Integration env: DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }} From 092cc5f9df54d823d4a73e3fe8c89c3302937ab3 Mon Sep 17 00:00:00 2001 From: Rob Brackett Date: Wed, 10 Sep 2025 19:41:02 -0700 Subject: [PATCH 5/9] Path issue? Works for me, fails on CI, yay. --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a44e53a..39e2df5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,8 +77,7 @@ jobs: DATADOG_APP_KEY: ${{ secrets.DATADOG_APP_KEY }} DATADOG_SITE: ${{ secrets.DATADOG_API_HOST }} run: | - cd test-other - deno --allow-all integration_check_deno.ts + deno --allow-all test-other/integration_check_deno.ts lint: runs-on: ubuntu-latest From 1dcb064a52399a320127ba8e14b61f54e427ddbb Mon Sep 17 00:00:00 2001 From: Rob Brackett Date: Wed, 10 Sep 2025 19:44:19 -0700 Subject: [PATCH 6/9] I lied, we require Deno 2.1+ --- .github/workflows/ci.yml | 2 +- README.md | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 39e2df5..380a52d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,7 +66,7 @@ jobs: - name: Install Deno uses: denoland/setup-deno@v2 with: - deno-version: '~2.0' + deno-version: '~2.1' - name: Install dependencies run: deno install diff --git a/README.md b/README.md index e456351..278098d 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ The downside of using the HTTP API is that it can negatively affect your app's p ## Installation -Datadog-metrics is compatible with Node.js v14 and later and Deno 2.0 and later. You can install it with NPM: +Datadog-metrics is compatible with Node.js v14 and later and Deno 2.1 and later. You can install it with NPM: ```sh npm install datadog-metrics --save @@ -372,13 +372,13 @@ Contributions are always welcome! For more info on how to contribute or develop **Breaking Changes:** -* The minimum required Node.js version is now v14.0.0 and Deno version is 2.0.0. +* The minimum required Node.js version is now v14.0.0 and Deno version is 2.1.0. * The `code` property on `AuthorizationError` instances has been changed to `DATADOG_METRICS_AUTHORIZATION_ERROR` for clarity and consistency (it was previously `DATADOG_AUTHORIZATION_ERROR`). If you are using `errorInstance.code` to check types, make sure to update the string you were looking for. **New Features:** -* Clarify this package is compatible with Deno (>= v2.0). We’ve silently worked on Deno for a long time, but never formally supported it before this release. +* Clarify this package is compatible with Deno (>= v2.1). We’ve silently worked on Deno for a long time, but never formally supported it before this release. **Deprecations:** @@ -800,4 +800,4 @@ Your contributions are always welcome! See [`CONTRIBUTING.md`](./CONTRIBUTING.md [npm-downloads]: https://img.shields.io/npm/dm/datadog-metrics.svg?style=flat-square [ci-status-image]: https://github.com/dbader/node-datadog-metrics/actions/workflows/ci.yml/badge.svg?branch=main [ci-status-url]: https://github.com/dbader/node-datadog-metrics/actions/workflows/ci.yml?query=branch%3Amain -[deno-image]: https://shield.deno.dev/deno/2.0 +[deno-image]: https://shield.deno.dev/deno/2.1 From 4ec1e130f9ace917a1dd8e8d61e65dece0562b6e Mon Sep 17 00:00:00 2001 From: Rob Brackett Date: Wed, 10 Sep 2025 19:57:48 -0700 Subject: [PATCH 7/9] Fix Deno compatibility badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 278098d..abf2e93 100644 --- a/README.md +++ b/README.md @@ -800,4 +800,4 @@ Your contributions are always welcome! See [`CONTRIBUTING.md`](./CONTRIBUTING.md [npm-downloads]: https://img.shields.io/npm/dm/datadog-metrics.svg?style=flat-square [ci-status-image]: https://github.com/dbader/node-datadog-metrics/actions/workflows/ci.yml/badge.svg?branch=main [ci-status-url]: https://github.com/dbader/node-datadog-metrics/actions/workflows/ci.yml?query=branch%3Amain -[deno-image]: https://shield.deno.dev/deno/2.1 +[deno-image]: https://shield.deno.dev/deno/^2.1 From cc10597bd731665e1acf37a84b8d37148ec64cd8 Mon Sep 17 00:00:00 2001 From: Rob Brackett Date: Wed, 10 Sep 2025 20:08:51 -0700 Subject: [PATCH 8/9] Stop using deprecated features in integration test --- test-other/integration_check_lib.mjs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test-other/integration_check_lib.mjs b/test-other/integration_check_lib.mjs index 3173226..df29d31 100644 --- a/test-other/integration_check_lib.mjs +++ b/test-other/integration_check_lib.mjs @@ -73,9 +73,7 @@ export async function sendMetric(metric) { for (const [timestamp, value] of testPoints) { datadogMetrics[metric.type](metric.name, value, metric.tags, timestamp); - await new Promise((resolve, reject) => { - datadogMetrics.flush(resolve, reject); - }); + await datadogMetrics.flush(); } } From fb07dcc32d3aeabd18c998514cb747153381ca97 Mon Sep 17 00:00:00 2001 From: Rob Brackett Date: Wed, 10 Sep 2025 20:58:54 -0700 Subject: [PATCH 9/9] Formally declare Bun support (#149) This is a follow-on to the official Deno support work in #148. --- .github/workflows/ci.yml | 21 +++++++++++++++++++++ README.md | 12 +++++++----- test-other/integration_check.mjs | 2 +- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 380a52d..4f88945 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,6 +79,27 @@ jobs: run: | deno --allow-all test-other/integration_check_deno.ts + test-bun-integration: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Bun + uses: oven-sh/setup-bun@v2 + with: + bun-version: '1.0.36' + + - name: Install dependencies + run: bun install + + - name: Check Integration + env: + DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }} + DATADOG_APP_KEY: ${{ secrets.DATADOG_APP_KEY }} + DATADOG_SITE: ${{ secrets.DATADOG_API_HOST }} + run: | + bun test-other/integration_check.mjs '-bun' + lint: runs-on: ubuntu-latest steps: diff --git a/README.md b/README.md index abf2e93..44654b0 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,8 @@ [![NPM Version][npm-image]][npm-url] [![Build Status][ci-status-image]][ci-status-url] [![Downloads Stats][npm-downloads]][npm-url] -![deno compatibility][deno-image] +![Supports Deno 2.1 and Newer][deno-image] +![Supports Bun 1.0 and Newer][bun-image] Datadog-metrics lets you collect application metrics through Datadog's HTTP API. Using the HTTP API has the benefit that you **don't need to install the Datadog Agent (StatsD)**. Just get an API key, install the module and you're ready to go. @@ -12,7 +13,7 @@ The downside of using the HTTP API is that it can negatively affect your app's p ## Installation -Datadog-metrics is compatible with Node.js v14 and later and Deno 2.1 and later. You can install it with NPM: +Datadog-metrics is compatible with Node.js v14+, Deno 2.1+, and Bun 1.0+. You can install it with NPM: ```sh npm install datadog-metrics --save @@ -372,13 +373,13 @@ Contributions are always welcome! For more info on how to contribute or develop **Breaking Changes:** -* The minimum required Node.js version is now v14.0.0 and Deno version is 2.1.0. +* The minimum required Node.js version is now v14.0.0, Deno version is 2.1.0, and Bun version is 1.0.0. * The `code` property on `AuthorizationError` instances has been changed to `DATADOG_METRICS_AUTHORIZATION_ERROR` for clarity and consistency (it was previously `DATADOG_AUTHORIZATION_ERROR`). If you are using `errorInstance.code` to check types, make sure to update the string you were looking for. **New Features:** -* Clarify this package is compatible with Deno (>= v2.1). We’ve silently worked on Deno for a long time, but never formally supported it before this release. +* Clarify this package is compatible with Deno (>= v2.1) and Bun (>= 1.0). We’ve silently worked on Deno and Bun for a long time, but never formally supported them before this release. **Deprecations:** @@ -800,4 +801,5 @@ Your contributions are always welcome! See [`CONTRIBUTING.md`](./CONTRIBUTING.md [npm-downloads]: https://img.shields.io/npm/dm/datadog-metrics.svg?style=flat-square [ci-status-image]: https://github.com/dbader/node-datadog-metrics/actions/workflows/ci.yml/badge.svg?branch=main [ci-status-url]: https://github.com/dbader/node-datadog-metrics/actions/workflows/ci.yml?query=branch%3Amain -[deno-image]: https://shield.deno.dev/deno/^2.1 +[deno-image]: https://img.shields.io/badge/Deno-^2.1-blue?logo=deno&color=70ffaf&logoColor=ffffff +[bun-image]: https://img.shields.io/badge/Bun-^1.0-blue?logo=bun&color=f368e0 diff --git a/test-other/integration_check.mjs b/test-other/integration_check.mjs index bd3f274..d57f847 100644 --- a/test-other/integration_check.mjs +++ b/test-other/integration_check.mjs @@ -6,7 +6,7 @@ import { main } from './integration_check_lib.mjs'; -main().catch(error => { +main({ tagSuffix: process.argv[2] || '' }).catch(error => { process.exitCode = 1; console.error(error); });