Skip to content

Commit ac63250

Browse files
pabloerhardsimon-id
authored andcommitted
chore: add ESM tests for instrumentations missing them (#6814)
* Added ESM tests for instrumentations without integration tests * fix knex ESM and unit tests * Added todo entry and removed unnecessary require
1 parent 785ec33 commit ac63250

File tree

37 files changed

+1196
-47
lines changed

37 files changed

+1196
-47
lines changed

.github/workflows/apm-integrations.yml

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@ jobs:
200200
api_key: ${{ secrets.DD_API_KEY }}
201201
service: dd-trace-js-tests
202202

203+
crypto:
204+
runs-on: ubuntu-latest
205+
env:
206+
PLUGINS: crypto
207+
steps:
208+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
209+
- uses: ./.github/actions/plugins/test
210+
with:
211+
dd_api_key: ${{ secrets.DD_API_KEY }}
212+
203213
confluentinc-kafka-javascript:
204214
strategy:
205215
matrix:
@@ -267,6 +277,16 @@ jobs:
267277
with:
268278
dd_api_key: ${{ secrets.DD_API_KEY }}
269279

280+
cookie:
281+
runs-on: ubuntu-latest
282+
env:
283+
PLUGINS: cookie
284+
steps:
285+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
286+
- uses: ./.github/actions/plugins/test
287+
with:
288+
dd_api_key: ${{ secrets.DD_API_KEY }}
289+
270290
couchbase:
271291
strategy:
272292
matrix:
@@ -434,6 +454,16 @@ jobs:
434454
with:
435455
dd_api_key: ${{ secrets.DD_API_KEY }}
436456

457+
generic-pool:
458+
runs-on: ubuntu-latest
459+
env:
460+
PLUGINS: generic-pool
461+
steps:
462+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
463+
- uses: ./.github/actions/plugins/test
464+
with:
465+
dd_api_key: ${{ secrets.DD_API_KEY }}
466+
437467
graphql:
438468
runs-on: ubuntu-latest
439469
env:
@@ -454,6 +484,16 @@ jobs:
454484
with:
455485
dd_api_key: ${{ secrets.DD_API_KEY }}
456486

487+
handlebars:
488+
runs-on: ubuntu-latest
489+
env:
490+
PLUGINS: handlebars
491+
steps:
492+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
493+
- uses: ./.github/actions/plugins/test
494+
with:
495+
dd_api_key: ${{ secrets.DD_API_KEY }}
496+
457497
hapi:
458498
runs-on: ubuntu-latest
459499
env:
@@ -577,6 +617,16 @@ jobs:
577617
api_key: ${{ secrets.DD_API_KEY }}
578618
service: dd-trace-js-tests
579619

620+
knex:
621+
runs-on: ubuntu-latest
622+
env:
623+
PLUGINS: knex
624+
steps:
625+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
626+
- uses: ./.github/actions/plugins/test
627+
with:
628+
dd_api_key: ${{ secrets.DD_API_KEY }}
629+
580630
koa:
581631
runs-on: ubuntu-latest
582632
env:
@@ -587,6 +637,16 @@ jobs:
587637
with:
588638
dd_api_key: ${{ secrets.DD_API_KEY }}
589639

640+
ldapjs:
641+
runs-on: 'ubuntu-latest'
642+
env:
643+
PLUGINS: ldapjs
644+
steps:
645+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
646+
- uses: ./.github/actions/plugins/test
647+
with:
648+
dd_api_key: ${{ secrets.DD_API_KEY }}
649+
590650
limitd-client:
591651
runs-on: ubuntu-latest
592652
services:
@@ -607,6 +667,16 @@ jobs:
607667
with:
608668
dd_api_key: ${{ secrets.DD_API_KEY }}
609669

670+
lodash:
671+
runs-on: 'ubuntu-latest'
672+
env:
673+
PLUGINS: lodash
674+
steps:
675+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
676+
- uses: ./.github/actions/plugins/test
677+
with:
678+
dd_api_key: ${{ secrets.DD_API_KEY }}
679+
610680
mariadb:
611681
runs-on: ubuntu-latest
612682
services:
@@ -712,6 +782,16 @@ jobs:
712782
with:
713783
dd_api_key: ${{ secrets.DD_API_KEY }}
714784

785+
multer:
786+
runs-on: ubuntu-latest
787+
env:
788+
PLUGINS: multer
789+
steps:
790+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
791+
- uses: ./.github/actions/plugins/test
792+
with:
793+
dd_api_key: ${{ secrets.DD_API_KEY }}
794+
715795
mysql:
716796
runs-on: ubuntu-latest
717797
services:
@@ -833,6 +913,16 @@ jobs:
833913
api_key: ${{ secrets.DD_API_KEY }}
834914
service: dd-trace-js-tests
835915

916+
node-serialize:
917+
runs-on: ubuntu-latest
918+
env:
919+
PLUGINS: node-serialize
920+
steps:
921+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
922+
- uses: ./.github/actions/plugins/test
923+
with:
924+
dd_api_key: ${{ secrets.DD_API_KEY }}
925+
836926
opensearch:
837927
runs-on: ubuntu-latest
838928
services:
@@ -963,6 +1053,16 @@ jobs:
9631053
with:
9641054
dd_api_key: ${{ secrets.DD_API_KEY }}
9651055

1056+
process:
1057+
runs-on: ubuntu-latest
1058+
env:
1059+
PLUGINS: process
1060+
steps:
1061+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
1062+
- uses: ./.github/actions/plugins/test
1063+
with:
1064+
dd_api_key: ${{ secrets.DD_API_KEY }}
1065+
9661066
protobufjs:
9671067
runs-on: ubuntu-latest
9681068
env:
@@ -974,6 +1074,16 @@ jobs:
9741074
with:
9751075
dd_api_key: ${{ secrets.DD_API_KEY }}
9761076

1077+
pug:
1078+
runs-on: ubuntu-latest
1079+
env:
1080+
PLUGINS: pug
1081+
steps:
1082+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
1083+
- uses: ./.github/actions/plugins/test
1084+
with:
1085+
dd_api_key: ${{ secrets.DD_API_KEY }}
1086+
9771087
redis:
9781088
runs-on: ubuntu-latest
9791089
services:
@@ -1067,6 +1177,16 @@ jobs:
10671177
with:
10681178
dd_api_key: ${{ secrets.DD_API_KEY }}
10691179

1180+
sequelize:
1181+
runs-on: ubuntu-latest
1182+
env:
1183+
PLUGINS: sequelize
1184+
steps:
1185+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
1186+
- uses: ./.github/actions/plugins/test
1187+
with:
1188+
dd_api_key: ${{ secrets.DD_API_KEY }}
1189+
10701190
sharedb:
10711191
runs-on: ubuntu-latest
10721192
env:
@@ -1130,6 +1250,26 @@ jobs:
11301250
with:
11311251
dd_api_key: ${{ secrets.DD_API_KEY }}
11321252

1253+
url:
1254+
runs-on: ubuntu-latest
1255+
env:
1256+
PLUGINS: url
1257+
steps:
1258+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
1259+
- uses: ./.github/actions/plugins/test
1260+
with:
1261+
dd_api_key: ${{ secrets.DD_API_KEY }}
1262+
1263+
vm:
1264+
runs-on: ubuntu-latest
1265+
env:
1266+
PLUGINS: vm
1267+
steps:
1268+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
1269+
- uses: ./.github/actions/plugins/test
1270+
with:
1271+
dd_api_key: ${{ secrets.DD_API_KEY }}
1272+
11331273
winston:
11341274
runs-on: ubuntu-latest
11351275
env:

packages/datadog-instrumentations/test/knex.spec.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
const { expect } = require('chai')
44
const { describe, it, beforeEach, afterEach } = require('mocha')
55

6+
const agent = require('../../dd-trace/test/plugins/agent')
67
const { storage } = require('../../datadog-core')
78
const { withVersions } = require('../../dd-trace/test/setup/mocha')
89

9-
require('../src/knex')
10-
1110
describe('Instrumentation', () => {
1211
let knex
1312
let client
@@ -16,27 +15,41 @@ describe('Instrumentation', () => {
1615
describe('knex', () => {
1716
withVersions('knex', 'knex', version => {
1817
describe('without configuration', () => {
18+
/**
19+
* TODO (Pablo Erhard): Implement a single mechanism to automatically trigger hook loading
20+
* across all tests. This should allow test hooks to initialize programmatically
21+
* without requiring explicit `agent.load()` calls in every individual test file.
22+
*/
23+
before(async () => {
24+
await agent.load()
25+
})
26+
1927
beforeEach(() => {
2028
knex = require(`../../../versions/knex@${version}`).get()
2129
client = knex({
22-
client: 'pg',
30+
client: 'sqlite3',
2331
connection: {
2432
filename: ':memory:'
2533
}
2634
})
2735
})
2836

2937
afterEach(() => client.destroy())
38+
after(async () => {
39+
await agent.close()
40+
})
3041

31-
it('should propagate context', () =>
32-
storage('legacy').run(store, () =>
33-
client.raw('PRAGMA user_version')
34-
.finally(() => {
35-
expect(storage('legacy').getStore()).to.equal(store)
36-
})
37-
.catch(() => {})
42+
it('should propagate context', async () => {
43+
let isInstrumented = false
44+
45+
await storage('legacy').run(store, () =>
46+
client.raw('PRAGMA user_version').then(() => {
47+
isInstrumented = storage('legacy').getStore() === store
48+
}).catch(() => {})
3849
)
39-
)
50+
51+
expect(isInstrumented).to.equal(true)
52+
})
4053
})
4154
})
4255
})

packages/datadog-plugin-cookie-parser/test/integration-test/client.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const {
44
sandboxCwd, useSandbox, varySandbox, curl,
55
FakeAgent, spawnPluginIntegrationTestProc
66
} = require('../../../../integration-tests/helpers')
7-
const { assert } = require('chai')
7+
const assert = require('node:assert/strict')
88
const { withVersions } = require('../../../dd-trace/test/setup/mocha')
99

1010
withVersions('cookie-parser', 'cookie-parser', version => {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict'
2+
3+
const {
4+
sandboxCwd, useSandbox, varySandbox, curl,
5+
FakeAgent, spawnPluginIntegrationTestProc
6+
} = require('../../../../integration-tests/helpers')
7+
const assert = require('node:assert/strict')
8+
const { withVersions } = require('../../../dd-trace/test/setup/mocha')
9+
10+
withVersions('cookie', 'cookie', version => {
11+
describe('ESM', () => {
12+
let variants, proc, agent
13+
14+
useSandbox([`'cookie@${version}'`, 'express'], false,
15+
['./packages/datadog-plugin-cookie/test/integration-test/*'])
16+
17+
before(function () {
18+
variants = varySandbox('server.mjs', 'cookie')
19+
})
20+
21+
beforeEach(async () => {
22+
agent = await new FakeAgent().start()
23+
})
24+
25+
afterEach(async () => {
26+
proc?.kill()
27+
await agent.stop()
28+
})
29+
30+
for (const variant of varySandbox.VARIANTS) {
31+
it(`is instrumented loaded with ${variant}`, async () => {
32+
proc = await spawnPluginIntegrationTestProc(sandboxCwd(), variants[variant], agent.port)
33+
const response = await curl(proc)
34+
assert.equal(response.headers['x-counter'], '1')
35+
})
36+
}
37+
})
38+
})
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import 'dd-trace/init.js'
2+
import express from 'express'
3+
import cookie from 'cookie'
4+
import dc from 'dc-polyfill'
5+
6+
const cookieParseCh = dc.channel('datadog:cookie:parse:finish')
7+
let counter = 0
8+
cookieParseCh.subscribe(() => {
9+
counter += 1
10+
})
11+
12+
const app = express()
13+
14+
app.get('/', (req, res) => {
15+
cookie.parse('hello=world')
16+
res.setHeader('X-Counter', counter)
17+
res.end('ok')
18+
})
19+
20+
const server = app.listen(0, () => {
21+
const port = server.address().port
22+
process.send({ port })
23+
})

0 commit comments

Comments
 (0)