diff --git a/lib/instrumentation/core/fs.js b/lib/instrumentation/core/fs.js index 9a912aa74c..57bae87be3 100644 --- a/lib/instrumentation/core/fs.js +++ b/lib/instrumentation/core/fs.js @@ -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) diff --git a/test/integration/core/fs.tap.js b/test/integration/core/fs.tap.js index 1050a5a910..9b58727297 100644 --- a/test/integration/core/fs.tap.js +++ b/test/integration/core/fs.tap.js @@ -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 () {