Skip to content

Commit

Permalink
feat: Added support for fs.glob in Node 22+ (#2369)
Browse files Browse the repository at this point in the history
jsumners-nr authored Jul 17, 2024
1 parent afd3ab4 commit 1791a4e
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/instrumentation/core/fs.js
Original file line number Diff line number Diff line change
@@ -45,6 +45,11 @@ function initialize(agent, fs, moduleName, shim) {
'ftruncate'
]

if (Object.hasOwnProperty.call(fs, 'glob') === true) {
// The `glob` method was added in Node 22.
methods.push('glob')
}

const nonRecordedMethods = ['write', 'read']

shim.record(fs, methods, recordFs)
22 changes: 22 additions & 0 deletions test/integration/core/fs.tap.js
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@ const helper = require('../../lib/agent_helper')
const verifySegments = require('./verify')
const NAMES = require('../../../lib/metrics/names')

const isGlobSupported = require('semver').satisfies(process.version, '>=22.0.0')

// delete temp files before process exits
temp.track()

@@ -835,6 +837,26 @@ test('watchFile', function (t) {
}, 10)
})

test('glob', { skip: isGlobSupported === false }, function (t) {
const name = path.join(tempDir, 'glob-me')
const content = 'some-content'
fs.writeFileSync(name, content)
const agent = setupAgent(t)
helper.runInTransaction(agent, function (tx) {
fs.glob(`${tempDir}${path.sep}*glob-me*`, function (error, matches) {
t.error(error)

const match = matches.find((m) => m.includes('glob-me'))
t.ok(match, 'glob found file')

verifySegments(t, agent, NAMES.FS.PREFIX + 'glob')

tx.end()
t.ok(checkMetric(['glob'], agent, tx.name), 'metric should exist after transaction end')
})
})
})

function setupAgent(t) {
const agent = helper.instrumentMockedAgent()
t.teardown(function () {

0 comments on commit 1791a4e

Please sign in to comment.