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

Commit 2f13dd0

Browse files
authored
feat(index.js): support ignoring payloads for Python (#107)
1 parent 0cdff30 commit 2f13dd0

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ Available options:
101101
|`collectorURL` |Optional |`-` |The address of the trace collector to send trace to |
102102
|`ignoredKeys` |Optional |`-` |May contain strings (will perform a loose match, so that First Name also matches first_name) |
103103
|`urlsToIgnore` |Optional |`-` |Ignore HTTP calls to specific domains |
104+
|`payloadsToIgnore` |Optional |`-` | Array of dictionaries to not instrument. Example: `'{"source": "serverless-plugin-warmup"}'` (Not yet available for Node) |
104105
|`labels` |Optional |`[]` |Global labels applied to all traces. For example "[['key', 'val']]". (Not available for Python) |
105106
|`wrapper`|Optional |`lambda_wrapper/lambdaWrapper` | The wrapper to use to wrap this function. See [wrappers](#wrappers)| |
106107

src/handlers.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,22 @@ const WRAPPER_CODE = ({
1313
collectorUrl,
1414
metadataOnly,
1515
urlsToIgnore,
16+
payloadsToIgnore,
1617
ignoredKeys,
1718
labels,
1819
}) => {
1920
const commonNode = `
20-
2121
if (!process.env.EPSAGON_IGNORED_KEYS) {
2222
process.env.EPSAGON_IGNORED_KEYS = "${ignoredKeys || ''}";
2323
}
2424
2525
if (!process.env.EPSAGON_URLS_TO_IGNORE) {
2626
process.env.EPSAGON_URLS_TO_IGNORE = "${urlsToIgnore || ''}";
2727
}
28+
29+
if (!process.env.EPSAGON_PAYLOADS_TO_IGNORE) {
30+
process.env.EPSAGON_PAYLOADS_TO_IGNORE = "${payloadsToIgnore || ''}";
31+
}
2832
2933
epsagon.init({
3034
token: '${token}',
@@ -44,6 +48,7 @@ try:
4448
4549
${urlsToIgnore ? `os.environ['EPSAGON_URLS_TO_IGNORE'] = '${urlsToIgnore}' if 'EPSAGON_URLS_TO_IGNORE' not in os.environ else os.environ['EPSAGON_URLS_TO_IGNORE']` : ''}
4650
${ignoredKeys ? `os.environ['EPSAGON_IGNORED_KEYS'] = '${ignoredKeys}' if 'EPSAGON_IGNORED_KEYS' not in os.environ else os.environ['EPSAGON_IGNORED_KEYS']` : ''}
51+
${payloadsToIgnore ? `os.environ['EPSAGON_PAYLOADS_TO_IGNORE'] = '${payloadsToIgnore}' if 'EPSAGON_PAYLOADS_TO_IGNORE' not in os.environ else os.environ['EPSAGON_PAYLOADS_TO_IGNORE']` : ''}
4752
4853
null = None # used to ignore arguments
4954
undefined = None # used to ignore arguments
@@ -96,7 +101,7 @@ export function generateWrapperCode(
96101
epsagonConf
97102
) {
98103
const {
99-
collectorURL, token, appName, metadataOnly, urlsToIgnore, ignoredKeys, labels,
104+
collectorURL, token, appName, metadataOnly, urlsToIgnore, payloadsToIgnore, ignoredKeys, labels,
100105
} = epsagonConf;
101106
const { wrapper = DEFAULT_WRAPPERS[func.language] } = (func.epsagon || {});
102107

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

110116
return WRAPPER_CODE({
111117
relativePath,
@@ -116,6 +122,7 @@ export function generateWrapperCode(
116122
collectorUrl: collectorURL ? `'${collectorURL}'` : undefined,
117123
metadataOnly: metadataOnly === true ? '1' : '0',
118124
urlsToIgnore,
125+
payloadsToIgnore: ignoredKeysFormatted,
119126
ignoredKeys,
120127
labels: labelsFormatted,
121128
})[func.language];

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export default class ServerlessEpsagonPlugin {
9292
collectorURL: { type: 'string' },
9393
ignoredKeys: { type: 'string' },
9494
urlsToIgnore: { type: 'string' },
95+
payloadsToIgnore: { type: 'array' },
9596
labels: { type: 'string' },
9697
wrapper: { type: 'string' },
9798
},

0 commit comments

Comments
 (0)