Skip to content

Commit 259cbdf

Browse files
crysmagskhanayan123
authored andcommitted
crysmags/ Adding support for Undici (#4293)
* Adding support Undici's fetch
1 parent 6ea733d commit 259cbdf

File tree

13 files changed

+612
-0
lines changed

13 files changed

+612
-0
lines changed

.github/workflows/plugins.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,23 @@ jobs:
12451245
uses: ./.github/actions/testagent/logs
12461246
- uses: codecov/codecov-action@v3
12471247

1248+
undici:
1249+
runs-on: ubuntu-latest
1250+
env:
1251+
PLUGINS: undici
1252+
steps:
1253+
- uses: actions/checkout@v4
1254+
- uses: ./.github/actions/testagent/start
1255+
- uses: ./.github/actions/node/setup
1256+
- run: yarn install
1257+
- uses: ./.github/actions/node/oldest
1258+
- run: yarn test:plugins:ci
1259+
- uses: ./.github/actions/node/latest
1260+
- run: yarn test:plugins:ci
1261+
- if: always()
1262+
uses: ./.github/actions/testagent/logs
1263+
- uses: codecov/codecov-action@v3
1264+
12481265
when:
12491266
runs-on: ubuntu-latest
12501267
env:

docs/API.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ tracer.use('pg', {
9494
<h5 id="restify-tags"></h5>
9595
<h5 id="restify-config"></h5>
9696
<h5 id="tedious"></h5>
97+
<h5 id="undici"></h5>
9798
<h5 id="when"></h5>
9899
<h5 id="winston"></h5>
99100
<h3 id="integrations-list">Available Plugins</h3>
@@ -146,6 +147,7 @@ tracer.use('pg', {
146147
* [restify](./interfaces/export_.plugins.restify.html)
147148
* [router](./interfaces/export_.plugins.router.html)
148149
* [tedious](./interfaces/export_.plugins.tedious.html)
150+
* [undici](./interfaces/export_.plugins.undici.html)
149151
* [when](./interfaces/export_.plugins.when.html)
150152
* [winston](./interfaces/export_.plugins.winston.html)
151153

docs/add-redirects.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ declare -a plugins=(
6060
"restify"
6161
"router"
6262
"tedious"
63+
"undici"
6364
"when"
6465
"winston"
6566
)

docs/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ tracer.use('selenium');
352352
tracer.use('sharedb');
353353
tracer.use('sharedb', sharedbOptions);
354354
tracer.use('tedious');
355+
tracer.use('undici');
355356
tracer.use('winston');
356357

357358
tracer.use('express', false)

index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ interface Plugins {
197197
"selenium": tracer.plugins.selenium;
198198
"sharedb": tracer.plugins.sharedb;
199199
"tedious": tracer.plugins.tedious;
200+
"undici": tracer.plugins.undici;
200201
"winston": tracer.plugins.winston;
201202
}
202203

@@ -1800,6 +1801,12 @@ declare namespace tracer {
18001801
*/
18011802
interface tedious extends Instrumentation {}
18021803

1804+
/**
1805+
* This plugin automatically instruments the
1806+
* [undici](https://github.com/nodejs/undici) module.
1807+
*/
1808+
interface undici extends HttpClient {}
1809+
18031810
/**
18041811
* This plugin patches the [winston](https://github.com/winstonjs/winston)
18051812
* to automatically inject trace identifiers in log records when the

packages/datadog-instrumentations/src/helpers/hooks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ module.exports = {
109109
sequelize: () => require('../sequelize'),
110110
sharedb: () => require('../sharedb'),
111111
tedious: () => require('../tedious'),
112+
undici: () => require('../undici'),
112113
when: () => require('../when'),
113114
winston: () => require('../winston')
114115
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict'
2+
3+
const {
4+
addHook
5+
} = require('./helpers/instrument')
6+
const shimmer = require('../../datadog-shimmer')
7+
8+
const tracingChannel = require('dc-polyfill').tracingChannel
9+
const ch = tracingChannel('apm:undici:fetch')
10+
11+
const { createWrapFetch } = require('./helpers/fetch')
12+
13+
addHook({
14+
name: 'undici',
15+
versions: ['^4.4.1', '5', '>=6.0.0']
16+
}, undici => {
17+
return shimmer.wrap(undici, 'fetch', createWrapFetch(undici.Request, ch))
18+
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict'
2+
3+
const FetchPlugin = require('../../datadog-plugin-fetch/src/index.js')
4+
5+
class UndiciPlugin extends FetchPlugin {
6+
static get id () { return 'undici' }
7+
static get prefix () {
8+
return 'tracing:apm:undici:fetch'
9+
}
10+
}
11+
12+
module.exports = UndiciPlugin

0 commit comments

Comments
 (0)