-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathmodule_importer.js
46 lines (37 loc) · 1.48 KB
/
module_importer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const { logDebug, updateDDTags } = require("../utils");
function compileCache () {
const { FileSystemBlobStore, NativeCompileCache } = require('v8-compile-cache').__TEST__
const cacheDir = __dirname
const prefix = 'module_importer'
const blobStore = new FileSystemBlobStore(cacheDir, prefix)
const nativeCompileCache = new NativeCompileCache()
nativeCompileCache.setCacheStore(blobStore)
nativeCompileCache.install()
process.once('exit', () => {
if (blobStore.isDirty()) {
blobStore.save()
}
nativeCompileCache.uninstall()
})
}
// Currently no way to prevent typescript from auto-transpiling import into require,
// so we expose a wrapper in js
exports.import = function (path) {
return import(path);
}
exports.initTracer = function () {
compileCache()
// Looks for the function local version of dd-trace first, before using
// the version provided by the layer
const path = require.resolve("dd-trace", { paths: ["/var/task/node_modules", ...module.paths] });
// tslint:disable-next-line:no-var-requires
// add lambda tags to DD_TAGS environment variable
const ddtags = updateDDTags({"_dd.origin": "lambda"})
const tracer = require(path).init({tags: ddtags});
logDebug("automatically initialized dd-trace");
// Configure the tracer to ignore HTTP calls made from the Lambda Library to the Extension
tracer.use("http", {
blocklist: /:8124\/lambda/,
});
return tracer;
}