Skip to content
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
5 changes: 5 additions & 0 deletions lib/instrumentation/core/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions test/integration/core/fs.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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 () {
Expand Down