-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
56 lines (48 loc) · 1.62 KB
/
index.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const debug = require('debug')('systemic-azure-metrics');
const appInsights = require('applicationinsights');
module.exports = () => {
// samplingPercentage, disableAppInsights, etc
const setupConfig = (client) => (property, value) => {
debug(`Setting up config: ${property} = ${value}`);
client.config.property = value;
};
const setupTag = (client) => (property, value) => {
debug(`Setting up context tag: ${property} = ${value}`);
client.context.tags[property] = value;
};
const start = async ({ config }) => {
const {
key,
internalLogging = false,
insightsConfig = {},
context: {
tags = {}
},
autoCollect: {
requests = true,
performance = true,
extendedPerformance = true,
exceptions = true,
dependencies = true,
console = true
}
} = config;
if (!key) throw new Error('No insights key has been provided!');
appInsights
.setup(key)
.setInternalLogging(internalLogging)
.setAutoCollectRequests(requests)
.setAutoCollectPerformance(performance, extendedPerformance)
.setAutoCollectExceptions(exceptions)
.setAutoCollectDependencies(dependencies)
.setAutoCollectConsole(console, console)
.start();
const { defaultClient } = appInsights;
const configureClient = setupConfig(defaultClient);
Object.keys(insightsConfig).forEach((key) => configureClient(key, insightsConfig[key]));
const configureTag = setupTag(defaultClient);
Object.keys(tags).forEach((key) => configureTag(key, tags[key]));
return defaultClient;
};
return { start };
};