forked from keyoke/docker-ghost-ai
-
Notifications
You must be signed in to change notification settings - Fork 5
/
ai-bootstrap.js
37 lines (31 loc) · 1.82 KB
/
ai-bootstrap.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
// Based on the Original file from - https://github.com/microsoft/Application-Insights-K8s-Codeless-Attach/blob/master/agents/agents/2.8.33/nodejs/ai-bootstrap.js
const appInsights = require('applicationinsights');
const ikey = process.env.APPINSIGHTS_INSTRUMENTATIONKEY;
const connectionString = process.env.APPLICATIONINSIGHTS_CONNECTION_STRING;
const setupString = connectionString || ikey;
const path = require('path');
if (setupString) {
// TODO: log to etw the ikey used
// TODO: check if applicationinsights/other modules are also present
// TODO: potentially we should try loading using `require('applicationinsights')` to allow standard loader to search for already existing applicationinsights
// TODO: make this script to create and maintain the status file, see https://mseng.visualstudio.com/AppInsights/_git/StatusMonitor/?path=%2FExtensions%2FExtension%2FExtensionStatus%2FStatusManager.cs&version=GBmaster&line=74
// TODO: wrap init logic into try-catch and log errors, once loggin is implemented
// const appInsights = require(path.join(__dirname,'node_modules','applicationinsights'));
appInsights.setup(setupString)
.setAutoCollectConsole(true, true)
.setSendLiveMetrics(true)
.enableWebInstrumentation(true);
if (process.env.APPLICATIONINSIGHTS_ROLE_NAME) {
appInsights.defaultClient.addTelemetryProcessor(envelope => {
envelope.tags["ai.cloud.role"] = process.env.APPLICATIONINSIGHTS_ROLE_NAME;
});
}
if (process.env.APPLICATIONINSIGHTS_ROLE_INSTANCE) {
appInsights.defaultClient.addTelemetryProcessor(envelope => {
envelope.tags["ai.cloud.roleInstance"] = process.env.APPLICATIONINSIGHTS_ROLE_INSTANCE;
});
}
appInsights.start();
} else {
// TODO: log to etw that ikey is not set, hence attach is skipped
}