Skip to content

Commit 0a4cdac

Browse files
committed
fix to undici tests
1 parent 975a4a1 commit 0a4cdac

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

packages/datadog-instrumentations/src/undici.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ const {
55
} = require('./helpers/instrument')
66
const shimmer = require('../../datadog-shimmer')
77

8-
const tracingChannel = require('node:diagnostics_channel')
9-
const ch = tracingChannel.tracingChannel('undici:fetch')
8+
const tracingChannel = require('dc-polyfill').tracingChannel
9+
const ch = tracingChannel('apm:undici:fetch')
10+
1011
const { createWrapFetch } = require('./helpers/fetch')
1112

1213
addHook({

packages/datadog-plugin-undici/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const FetchPlugin = require('../../datadog-plugin-fetch/src/index.js')
55
class UndiciPlugin extends FetchPlugin {
66
static get id () { return 'undici' }
77
static get prefix () {
8-
return 'tracing:undici:fetch'
8+
return 'tracing:apm:undici:fetch'
99
}
1010
}
1111

packages/datadog-plugin-undici/test/index.spec.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ describe('Plugin', () => {
3838
})
3939

4040
describe('without configuration', () => {
41-
beforeEach(function () {
42-
// this.timeout(10000)
41+
beforeEach(() => {
4342
return agent.load('undici', {
4443
service: 'test'
4544
})
@@ -49,6 +48,10 @@ describe('Plugin', () => {
4948
})
5049
})
5150

51+
afterEach(() => {
52+
express = null
53+
})
54+
5255
withNamingSchema(
5356
() => {
5457
const app = express()
@@ -65,20 +68,23 @@ describe('Plugin', () => {
6568
rawExpectedSchema.client
6669
)
6770

68-
it('should support URL input', done => {
71+
it('FIRST TEST FAILS BECAUSE.', () => {
72+
})
73+
74+
it('should do automatic instrumentation', function (done) {
6975
const app = express()
70-
app.post('/user', (req, res) => {
76+
app.get('/user', (req, res) => {
7177
res.status(200).send()
7278
})
7379
getPort().then(port => {
7480
agent
7581
.use(traces => {
76-
expect(traces[0][0]).to.have.property('service', SERVICE_NAME)
82+
expect(traces[0][0]).to.have.property('service', 'test')
7783
expect(traces[0][0]).to.have.property('type', 'http')
78-
expect(traces[0][0]).to.have.property('resource', 'POST')
84+
expect(traces[0][0]).to.have.property('resource', 'GET')
7985
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
8086
expect(traces[0][0].meta).to.have.property('http.url', `http://localhost:${port}/user`)
81-
expect(traces[0][0].meta).to.have.property('http.method', 'POST')
87+
expect(traces[0][0].meta).to.have.property('http.method', 'GET')
8288
expect(traces[0][0].meta).to.have.property('http.status_code', '200')
8389
expect(traces[0][0].meta).to.have.property('component', 'undici')
8490
expect(traces[0][0].meta).to.have.property('out.host', 'localhost')
@@ -87,29 +93,25 @@ describe('Plugin', () => {
8793
.catch(done)
8894

8995
appListener = server(app, port, () => {
90-
fetch.fetch(new URL(`http://localhost:${port}/user`), { method: 'POST' })
96+
fetch.fetch(`http://localhost:${port}/user`, { method: 'GET' })
9197
})
9298
})
9399
})
94100

95-
it('should do automatic instrumentation', function (done) {
96-
// this.timeout(10000)
101+
it('should support URL input', done => {
97102
const app = express()
98-
// setTimeout(done, 1000)
99-
app.get('/user', (req, res) => {
103+
app.post('/user', (req, res) => {
100104
res.status(200).send()
101105
})
102-
// setTimeout(done, 1000)
103106
getPort().then(port => {
104107
agent
105108
.use(traces => {
106-
// console.log('traces', traces[0][0])
107-
expect(traces[0][0]).to.have.property('service', 'test')
109+
expect(traces[0][0]).to.have.property('service', SERVICE_NAME)
108110
expect(traces[0][0]).to.have.property('type', 'http')
109-
expect(traces[0][0]).to.have.property('resource', 'GET')
111+
expect(traces[0][0]).to.have.property('resource', 'POST')
110112
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
111113
expect(traces[0][0].meta).to.have.property('http.url', `http://localhost:${port}/user`)
112-
expect(traces[0][0].meta).to.have.property('http.method', 'GET')
114+
expect(traces[0][0].meta).to.have.property('http.method', 'POST')
113115
expect(traces[0][0].meta).to.have.property('http.status_code', '200')
114116
expect(traces[0][0].meta).to.have.property('component', 'undici')
115117
expect(traces[0][0].meta).to.have.property('out.host', 'localhost')
@@ -118,10 +120,8 @@ describe('Plugin', () => {
118120
.catch(done)
119121

120122
appListener = server(app, port, () => {
121-
// setTimeout(done, 1000)
122-
fetch.fetch(`http://localhost:${port}/user`, { method: 'GET' })
123+
fetch.fetch(new URL(`http://localhost:${port}/user`), { method: 'POST' })
123124
})
124-
// setTimeout(() => {}, 1000)
125125
})
126126
})
127127

0 commit comments

Comments
 (0)