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): support ignoring payloads for Python (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
ojongerius authored Aug 5, 2021
1 parent 0cdff30 commit 2f13dd0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Available options:
|`collectorURL` |Optional |`-` |The address of the trace collector to send trace to |
|`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 |
|`payloadsToIgnore` |Optional |`-` | Array of dictionaries to not instrument. Example: `'{"source": "serverless-plugin-warmup"}'` (Not yet available for Node) |
|`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)| |

Expand Down
11 changes: 9 additions & 2 deletions src/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@ const WRAPPER_CODE = ({
collectorUrl,
metadataOnly,
urlsToIgnore,
payloadsToIgnore,
ignoredKeys,
labels,
}) => {
const commonNode = `
if (!process.env.EPSAGON_IGNORED_KEYS) {
process.env.EPSAGON_IGNORED_KEYS = "${ignoredKeys || ''}";
}
if (!process.env.EPSAGON_URLS_TO_IGNORE) {
process.env.EPSAGON_URLS_TO_IGNORE = "${urlsToIgnore || ''}";
}
if (!process.env.EPSAGON_PAYLOADS_TO_IGNORE) {
process.env.EPSAGON_PAYLOADS_TO_IGNORE = "${payloadsToIgnore || ''}";
}
epsagon.init({
token: '${token}',
Expand All @@ -44,6 +48,7 @@ try:
${urlsToIgnore ? `os.environ['EPSAGON_URLS_TO_IGNORE'] = '${urlsToIgnore}' if 'EPSAGON_URLS_TO_IGNORE' not in os.environ else os.environ['EPSAGON_URLS_TO_IGNORE']` : ''}
${ignoredKeys ? `os.environ['EPSAGON_IGNORED_KEYS'] = '${ignoredKeys}' if 'EPSAGON_IGNORED_KEYS' not in os.environ else os.environ['EPSAGON_IGNORED_KEYS']` : ''}
${payloadsToIgnore ? `os.environ['EPSAGON_PAYLOADS_TO_IGNORE'] = '${payloadsToIgnore}' if 'EPSAGON_PAYLOADS_TO_IGNORE' not in os.environ else os.environ['EPSAGON_PAYLOADS_TO_IGNORE']` : ''}
null = None # used to ignore arguments
undefined = None # used to ignore arguments
Expand Down Expand Up @@ -96,7 +101,7 @@ export function generateWrapperCode(
epsagonConf
) {
const {
collectorURL, token, appName, metadataOnly, urlsToIgnore, ignoredKeys, labels,
collectorURL, token, appName, metadataOnly, urlsToIgnore, payloadsToIgnore, ignoredKeys, labels,
} = epsagonConf;
const { wrapper = DEFAULT_WRAPPERS[func.language] } = (func.epsagon || {});

Expand All @@ -106,6 +111,7 @@ export function generateWrapperCode(
func.relativePath
);
const labelsFormatted = typeof labels === 'object' ? JSON.stringify(labels) : labels;
const ignoredKeysFormatted = typeof payloadsToIgnore === 'object' ? JSON.stringify(payloadsToIgnore) : payloadsToIgnore;

return WRAPPER_CODE({
relativePath,
Expand All @@ -116,6 +122,7 @@ export function generateWrapperCode(
collectorUrl: collectorURL ? `'${collectorURL}'` : undefined,
metadataOnly: metadataOnly === true ? '1' : '0',
urlsToIgnore,
payloadsToIgnore: ignoredKeysFormatted,
ignoredKeys,
labels: labelsFormatted,
})[func.language];
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default class ServerlessEpsagonPlugin {
collectorURL: { type: 'string' },
ignoredKeys: { type: 'string' },
urlsToIgnore: { type: 'string' },
payloadsToIgnore: { type: 'array' },
labels: { type: 'string' },
wrapper: { type: 'string' },
},
Expand Down

0 comments on commit 2f13dd0

Please sign in to comment.