forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigurationDefaultsPlugin.ts
More file actions
30 lines (26 loc) · 986 Bytes
/
ConfigurationDefaultsPlugin.ts
File metadata and controls
30 lines (26 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { Utils } from '../../Utils';
import { EventPluginContext } from '../EventPluginContext';
import { IEventPlugin } from '../IEventPlugin';
export class ConfigurationDefaultsPlugin implements IEventPlugin {
public priority: number = 10;
public name: string = 'ConfigurationDefaultsPlugin';
public run(context: EventPluginContext, next?: () => void): void {
const config = context.client.config;
const defaultTags: string[] = config.defaultTags || [];
for (const tag of defaultTags) {
if (tag && context.event.tags.indexOf(tag) < 0) {
context.event.tags.push(tag);
}
}
const defaultData: Record<string, unknown> = config.defaultData || {};
for (const key in defaultData) {
if (defaultData[key]) {
const result = JSON.parse(Utils.stringify(defaultData[key], config.dataExclusions));
if (!Utils.isEmpty(result)) {
context.event.data[key] = result;
}
}
}
next && next();
}
}