-
Notifications
You must be signed in to change notification settings - Fork 8
/
appInsight-api.js
24 lines (23 loc) · 991 Bytes
/
appInsight-api.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
if (process.env.NEXT_PUBLIC_APP_INSIGHT_CONNECTION_STRING) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
let appInsights = require("applicationinsights");
appInsights
.setup(process.env.NEXT_PUBLIC_APP_INSIGHT_CONNECTION_STRING)
.setAutoCollectConsole(true)
.setAutoCollectExceptions(true)
.setAutoCollectRequests(true)
.setDistributedTracingMode(appInsights.DistributedTracingModes.AI_AND_W3C)
.setSendLiveMetrics(true);
appInsights.defaultClient.addTelemetryProcessor((envelope, context) => {
if (envelope.data.baseType === "RequestData") {
envelope.data.baseData.properties ??= {};
if (context["http.ServerRequest"]?.headers["user-agent"])
envelope.data.baseData.properties.userAgent =
context["http.ServerRequest"].headers["user-agent"];
}
});
appInsights.start();
} else {
// eslint-disable-next-line no-console
console.log("🚨 App Insights - Server Side logging is not turned on!");
}