-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
consolidate instances of
loadInst
, so code isn't repeated
- Loading branch information
Showing
4 changed files
with
72 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use strict' | ||
|
||
const fs = require('fs') | ||
const path = require('path') | ||
const proxyquire = require('proxyquire') | ||
|
||
function loadInstFile (file, instrumentations) { | ||
const instrument = { | ||
addHook (instrumentation) { | ||
instrumentations.push(instrumentation) | ||
} | ||
} | ||
|
||
const instPath = path.join(__dirname, `../../../../datadog-instrumentations/src/${file}`) | ||
|
||
proxyquire.noPreserveCache()(instPath, { | ||
'./helpers/instrument': instrument, | ||
'../helpers/instrument': instrument | ||
}) | ||
} | ||
|
||
function loadOneInst (name) { | ||
const instrumentations = [] | ||
|
||
try { | ||
loadInstFile(`${name}/server.js`, instrumentations) | ||
loadInstFile(`${name}/client.js`, instrumentations) | ||
} catch (e) { | ||
try { | ||
loadInstFile(`${name}/main.js`, instrumentations) | ||
} catch (e) { | ||
loadInstFile(`${name}.js`, instrumentations) | ||
} | ||
} | ||
|
||
return instrumentations | ||
} | ||
|
||
function getAllInstrumentations () { | ||
const names = fs.readdirSync(path.join(__dirname, '../../../../', 'datadog-instrumentations', 'src')) | ||
.filter(file => file.endsWith('.js')) | ||
.map(file => file.slice(0, -3)) | ||
|
||
const instrumentations = names.reduce((acc, key) => { | ||
const name = key | ||
let instrumentations = loadOneInst(name) | ||
|
||
instrumentations = instrumentations.filter(i => i.versions) | ||
if (instrumentations.length) { | ||
acc[key] = instrumentations | ||
} | ||
|
||
return acc | ||
}, {}) | ||
|
||
return instrumentations | ||
} | ||
|
||
module.exports = { | ||
getInstrumentation: loadOneInst, | ||
getAllInstrumentations | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters