Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crysmags/ Adding support for Undici #4293

Merged
merged 11 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,23 @@ jobs:
uses: ./.github/actions/testagent/logs
- uses: codecov/codecov-action@v3

undici:
runs-on: ubuntu-latest
env:
PLUGINS: undici
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/testagent/start
- uses: ./.github/actions/node/setup
- run: yarn install
- uses: ./.github/actions/node/oldest
- run: yarn test:plugins:ci
- uses: ./.github/actions/node/latest
- run: yarn test:plugins:ci
- if: always()
uses: ./.github/actions/testagent/logs
- uses: codecov/codecov-action@v3

when:
runs-on: ubuntu-latest
env:
Expand Down
2 changes: 2 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ tracer.use('pg', {
<h5 id="restify-tags"></h5>
<h5 id="restify-config"></h5>
<h5 id="tedious"></h5>
<h5 id="undici"></h5>
<h5 id="when"></h5>
<h5 id="winston"></h5>
<h3 id="integrations-list">Available Plugins</h3>
Expand Down Expand Up @@ -146,6 +147,7 @@ tracer.use('pg', {
* [restify](./interfaces/export_.plugins.restify.html)
* [router](./interfaces/export_.plugins.router.html)
* [tedious](./interfaces/export_.plugins.tedious.html)
* [undici](./interfaces/export_.plugins.undici.html)
* [when](./interfaces/export_.plugins.when.html)
* [winston](./interfaces/export_.plugins.winston.html)

Expand Down
1 change: 1 addition & 0 deletions docs/add-redirects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ declare -a plugins=(
"restify"
"router"
"tedious"
"undici"
"when"
"winston"
)
Expand Down
1 change: 1 addition & 0 deletions docs/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ tracer.use('selenium');
tracer.use('sharedb');
tracer.use('sharedb', sharedbOptions);
tracer.use('tedious');
tracer.use('undici');
tracer.use('winston');

tracer.use('express', false)
Expand Down
7 changes: 7 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ interface Plugins {
"selenium": tracer.plugins.selenium;
"sharedb": tracer.plugins.sharedb;
"tedious": tracer.plugins.tedious;
"undici": tracer.plugins.undici;
"winston": tracer.plugins.winston;
}

Expand Down Expand Up @@ -1800,6 +1801,12 @@ declare namespace tracer {
*/
interface tedious extends Instrumentation {}

/**
* This plugin automatically instruments the
* [undici](https://github.com/nodejs/undici) module.
*/
interface undici extends HttpClient {}

/**
* This plugin patches the [winston](https://github.com/winstonjs/winston)
* to automatically inject trace identifiers in log records when the
Expand Down
1 change: 1 addition & 0 deletions packages/datadog-instrumentations/src/helpers/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ module.exports = {
sequelize: () => require('../sequelize'),
sharedb: () => require('../sharedb'),
tedious: () => require('../tedious'),
undici: () => require('../undici'),
when: () => require('../when'),
winston: () => require('../winston')
}
18 changes: 18 additions & 0 deletions packages/datadog-instrumentations/src/undici.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'

const {
addHook
} = require('./helpers/instrument')
const shimmer = require('../../datadog-shimmer')

const tracingChannel = require('dc-polyfill').tracingChannel
const ch = tracingChannel('apm:undici:fetch')

const { createWrapFetch } = require('./helpers/fetch')

addHook({
name: 'undici',
versions: ['^4.4.1', '5', '>=6.0.0']
}, undici => {
return shimmer.wrap(undici, 'fetch', createWrapFetch(undici.Request, ch))
})
12 changes: 12 additions & 0 deletions packages/datadog-plugin-undici/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict'

const FetchPlugin = require('../../datadog-plugin-fetch/src/index.js')

class UndiciPlugin extends FetchPlugin {
static get id () { return 'undici' }
static get prefix () {
return 'tracing:apm:undici:fetch'
}
}

module.exports = UndiciPlugin
Loading
Loading