From 73f343c5254a11531d692f3b62454a9bc33f7bdc Mon Sep 17 00:00:00 2001 From: Ran Ribenzaft Date: Sun, 11 Apr 2021 13:19:44 +0300 Subject: [PATCH] feat(index.js): add support for general wrapper (#99) --- README.md | 3 +++ src/index.js | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c6f6bb..efaa0d1 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ Available options: |`ignoredKeys` |Optional |`-` |May contain strings (will perform a loose match, so that First Name also matches first_name) | |`urlsToIgnore` |Optional |`-` |Ignore HTTP calls to specific domains | |`labels` |Optional |`[]` |Global labels applied to all traces. For example "[['key', 'val']]". (Not available for Python) | +|`wrapper`|Optional |`lambda_wrapper/lambdaWrapper` - The wrapper to use to wrap this function. See [wrappers](#wrappers)| | ### Function Level Options These options are defined at the function level, under the `epsagon` member of your function in the `serverless.yml` file. @@ -131,10 +132,12 @@ Available options: * `lambda_wrapper` - regular lambda wrapper * `step_lambda_wrapper` - Used to wrap step functions * `python_wrapper` - Used to wrap regular Python functions (doesn't have to run on Lambda) + * `tencent_function_wrapper` - Wrapper for Tencent Cloud Serverless Cloud Functions * Node.js functions: * `lambdaWrapper` - regular lambda wrapper * `stepLambdaWrapper` - Used to wrap step functions * `nodeWrapper` - Used to wrap regular Node functions (doesn't have to run on Lambda) + * `tencentFunctionWrapper` - Wrapper for Tencent Cloud Serverless Cloud Functions ## Troubleshooting diff --git a/src/index.js b/src/index.js index bd2edaa..34ebe08 100644 --- a/src/index.js +++ b/src/index.js @@ -93,6 +93,7 @@ export default class ServerlessEpsagonPlugin { ignoredKeys: { type: 'string' }, urlsToIgnore: { type: 'string' }, labels: { type: 'string' }, + wrapper: { type: 'string' }, }, additionalProperties: false, }, @@ -221,7 +222,7 @@ export default class ServerlessEpsagonPlugin { return result; } - const language = SUPPORTED_LANGUAGES.find((lang => runtime.match(lang))); + const language = SUPPORTED_LANGUAGES.find((lang => runtime.toLowerCase().match(lang))); if (!language) { this.log(`Runtime "${runtime}" is not supported yet, skipping function ${key}`); return result; @@ -254,6 +255,14 @@ export default class ServerlessEpsagonPlugin { } } await Promise.all(this.funcs.map(async (func) => { + if (this.config().wrapper) { + if (!func.epsagon) { + // eslint-disable-next-line no-param-reassign + func.epsagon = {}; + } + // eslint-disable-next-line no-param-reassign + func.epsagon.wrapper = this.config().wrapper; + } const handlerCode = generateWrapperCode(func, this.config()); await writeFile( join(