-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsights.js
44 lines (36 loc) · 1.23 KB
/
insights.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
const axios = require("axios");
const HttpsProxyAgent = require("https-proxy-agent");
const InsightsBaseURL = {
EU: "https://insights-collector.eu01.nr-data.net",
US: "https://insights-collector.newrelic.com",
};
module.exports.sendToInsights = (payload, newRelic) => {
const { insertKey, accountId, region } = newRelic;
const proxy = global.proxy ? global.proxy : false;
let proxyConfig = {
timeout: 3000,
proxy: false,
};
if (proxy) {
proxyConfig["httpsAgent"] = new HttpsProxyAgent(`${proxy.host}:${proxy.port}`);
}
const axiosClient = axios.create(proxyConfig);
if (global.debug) console.log(`Proxy: ${JSON.stringify(proxy)}`);
if (global.debug) console.log("Sending data to New Relic");
payload["eventType"] = "Email";
if (global.debug) console.log(`Payload: ${JSON.stringify(payload)}`);
return axiosClient
.post(
`${getInsightsBaseRegionUrl(region)}/v1/accounts/${accountId}/events`,
payload,
{
headers: {
"content-type": "application/json",
"x-insert-key": insertKey,
},
},
);
};
function getInsightsBaseRegionUrl (region) {
return InsightsBaseURL[region];
}