Ross Coundon
10/07/2021, 7:57 PMconst epsagon = LayerVersion.fromLayerVersionArn(this, 'EpsagonLayer', process.env.EPSAGON_LAYER_ARN);
this.addDefaultFunctionLayers([epsagon]);
this.addDefaultFunctionEnv({
EPSAGON_TOKEN: process.env.EPSAGON_TOKEN,
EPSAGON_APP_NAME: process.env.EPSAGON_APP_NAME,
NODE_OPTIONS: '-r epsagon-frameworks',
});
I can see that all the necessary env vars are getting set. However, and everything deploys okay with sst start
but when executing a function it fails and I can see a log in Cloudwatch that says:
internal/modules/cjs/loader.js:892
throw err;
^
Error: Cannot find module 'epsagon-frameworks'
Require stack:
- internal/preload
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
at Function.Module._load (internal/modules/cjs/loader.js:745:27)
at Module.require (internal/modules/cjs/loader.js:961:19)
at Module._preloadModules (internal/modules/cjs/loader.js:1231:12)
at loadPreloadModules (internal/bootstrap/pre_execution.js:468:5)
at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:71:3)
at internal/main/run_main_module.js:7:1 {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'internal/preload' ]
}
Adrián Mouly
10/07/2021, 7:58 PMAdrián Mouly
10/07/2021, 7:58 PMAdrián Mouly
10/07/2021, 7:58 PMAdrián Mouly
10/07/2021, 7:58 PMAdrián Mouly
10/07/2021, 7:59 PMAdrián Mouly
10/07/2021, 7:59 PMAdrián Mouly
10/07/2021, 7:59 PMapp.setDefaultFunctionProps(stack => {
return {
runtime: 'nodejs14.x',
srcPath: 'backend/src/',
logRetention: RetentionDays.TWO_WEEKS,
tracing: Tracing.DISABLED,
layers: [getEpsagonLayer(stack)],
environment: {
EPSAGON_APP_NAME: stack.stackName,
EPSAGON_TOKEN: getEpsagonToken(stack),
},
};
});
Ross Coundon
10/07/2021, 7:59 PMOur layers are publicly available for Python and Node.js Lambda runtimes. With just a few Environment Variables, the layer will automatically add tracing to your functions.
Adrián Mouly
10/07/2021, 7:59 PMexport function getEpsagonLayer(stack: Stack): ILayerVersion {
return LayerVersion.fromLayerVersionArn(stack, 'EpsagonLayer', constants.EPSAGON.LAYER_ARN);
}
export function getEpsagonToken(stack: Stack): string {
return StringParameter.valueForStringParameter(stack, constants.PARAMETERS.EPSAGON_TOKEN);
}
Adrián Mouly
10/07/2021, 8:00 PMAdrián Mouly
10/07/2021, 8:00 PMAdrián Mouly
10/07/2021, 8:00 PMAdrián Mouly
10/07/2021, 8:00 PMAdrián Mouly
10/07/2021, 8:00 PMRoss Coundon
10/07/2021, 8:00 PMAdrián Mouly
10/07/2021, 8:00 PMAdrián Mouly
10/07/2021, 8:00 PMRoss Coundon
10/07/2021, 8:01 PMRoss Coundon
10/07/2021, 8:01 PMAdrián Mouly
10/07/2021, 8:01 PMAdrián Mouly
10/07/2021, 8:01 PMAdrián Mouly
10/07/2021, 8:02 PMAdrián Mouly
10/07/2021, 8:02 PMAdrián Mouly
10/07/2021, 8:02 PMAdrián Mouly
10/07/2021, 8:02 PMRoss Coundon
10/07/2021, 8:13 PMAdrián Mouly
10/07/2021, 8:13 PMAdrián Mouly
10/07/2021, 8:14 PMAdrián Mouly
10/07/2021, 8:14 PMAdrián Mouly
10/07/2021, 8:14 PMAdrián Mouly
10/07/2021, 8:14 PMRoss Coundon
10/07/2021, 8:45 PMFrank
sst start
, but not after sst deploy
?Frank
Ross Coundon
10/07/2021, 9:24 PMsst start
Frank
Ross Coundon
10/07/2021, 9:26 PMRoss Coundon
10/07/2021, 9:30 PMAdrián Mouly
10/07/2021, 9:54 PMAdrián Mouly
10/07/2021, 9:54 PMFrank
NODE_OPTIONS: '-r epsagon-frameworks',
?Ross Coundon
10/07/2021, 9:59 PMFrank
if (!app.local) {
stack.addDefaultFunctionEnv({
EPSAGON_TOKEN: "<token>",
EPSAGON_APP_NAME: "<app_name>",
NODE_OPTIONS: "-r epsagon-frameworks"
})
}
thdxr
10/07/2021, 10:02 PMAdrián Mouly
10/07/2021, 10:05 PMNODE_OPTIONS
too.Adrián Mouly
10/07/2021, 10:06 PMapp.setDefaultFunctionProps(stack => {
return {
runtime: 'nodejs14.x',
srcPath: 'backend/src/services',
logRetention: RetentionDays.TWO_WEEKS,
tracing: Tracing.DISABLED,
layers: [getEpsagonLayer(stack)],
environment: {
EPSAGON_APP_NAME: stack.stackName,
EPSAGON_TOKEN: getEpsagonToken(stack),
},
};
});
Adrián Mouly
10/07/2021, 10:06 PMindex
.Adrián Mouly
10/07/2021, 10:07 PMAdrián Mouly
10/07/2021, 10:08 PMNODE_OPTIONS
with an inline if.Adrián Mouly
10/07/2021, 10:08 PMenvironment: {
EPSAGON_APP_NAME: stack.stackName,
EPSAGON_TOKEN: getEpsagonToken(stack),
NODE_OPTIONS: app.local ? '-r epsagon-frameworks' : '',
},