Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
feat(index.js): add support for general wrapper (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranrib committed Apr 11, 2021
1 parent e8a5bfb commit 73f343c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
11 changes: 10 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export default class ServerlessEpsagonPlugin {
ignoredKeys: { type: 'string' },
urlsToIgnore: { type: 'string' },
labels: { type: 'string' },
wrapper: { type: 'string' },
},
additionalProperties: false,
},
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 73f343c

Please sign in to comment.