@mhubcloud/tms_core 3.3.0-beta.0 → 3.3.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +8 -5
- package/package.json +1 -1
- package/src/utils/utils.ts +9 -10
package/dist/index.js
CHANGED
|
@@ -57,7 +57,10 @@ var crypto = __toESM(require("crypto"));
|
|
|
57
57
|
var appInsights = __toESM(require("applicationinsights"));
|
|
58
58
|
var aiClient = null;
|
|
59
59
|
if (process.env.APPLICATIONINSIGHTS_CONNECTION_STRING || process.env.APPINSIGHTS_INSTRUMENTATIONKEY) {
|
|
60
|
-
|
|
60
|
+
const samplingLevel = process.env.SamplingLevel ?? "12.5";
|
|
61
|
+
appInsights.setup().setAutoCollectDependencies(false).setAutoCollectConsole(true, false).setSendLiveMetrics(false).setAutoCollectRequests(false).setAutoCollectPerformance(false).setUseDiskRetryCaching(false);
|
|
62
|
+
appInsights.defaultClient.config.samplingPercentage = parseFloat(samplingLevel);
|
|
63
|
+
appInsights.start();
|
|
61
64
|
aiClient = appInsights.defaultClient;
|
|
62
65
|
}
|
|
63
66
|
var EventPublisherBase = class {
|
|
@@ -89,12 +92,12 @@ function logMessage(level, message, properties) {
|
|
|
89
92
|
properties
|
|
90
93
|
});
|
|
91
94
|
}
|
|
92
|
-
function logEvent(publisher2, event, region
|
|
95
|
+
function logEvent(publisher2, event, region) {
|
|
93
96
|
const properties = {
|
|
94
97
|
publisher: publisher2,
|
|
95
98
|
event,
|
|
96
99
|
region,
|
|
97
|
-
sampling
|
|
100
|
+
sampling: process.env.SamplingLevel
|
|
98
101
|
};
|
|
99
102
|
logMessage(1, "Event dispatched to platform", properties);
|
|
100
103
|
}
|
|
@@ -226,10 +229,10 @@ async function handlePlatformRequest({
|
|
|
226
229
|
rawPlatformResponse,
|
|
227
230
|
event.event
|
|
228
231
|
);
|
|
229
|
-
logEvent(source, event.event, event.region
|
|
232
|
+
logEvent(source, event.event, event.region);
|
|
230
233
|
return processedPlatformResponse;
|
|
231
234
|
} else {
|
|
232
|
-
logEvent(source, event.event, event.region
|
|
235
|
+
logEvent(source, event.event, event.region);
|
|
233
236
|
}
|
|
234
237
|
}
|
|
235
238
|
async function handleTestRequest(params) {
|
package/package.json
CHANGED
package/src/utils/utils.ts
CHANGED
|
@@ -16,6 +16,8 @@ if (
|
|
|
16
16
|
process.env.APPLICATIONINSIGHTS_CONNECTION_STRING ||
|
|
17
17
|
process.env.APPINSIGHTS_INSTRUMENTATIONKEY
|
|
18
18
|
) {
|
|
19
|
+
const samplingLevel = process.env.SamplingLevel ?? '12.5';
|
|
20
|
+
|
|
19
21
|
appInsights
|
|
20
22
|
.setup() // Set environment variable APPLICATIONINSIGHTS_CONNECTION_STRING, so setup() can be called w/o parameters
|
|
21
23
|
.setAutoCollectDependencies(false)
|
|
@@ -23,8 +25,10 @@ if (
|
|
|
23
25
|
.setSendLiveMetrics(false)
|
|
24
26
|
.setAutoCollectRequests(false)
|
|
25
27
|
.setAutoCollectPerformance(false)
|
|
26
|
-
.setUseDiskRetryCaching(false)
|
|
27
|
-
|
|
28
|
+
.setUseDiskRetryCaching(false);
|
|
29
|
+
appInsights.defaultClient.config.samplingPercentage =
|
|
30
|
+
parseFloat(samplingLevel);
|
|
31
|
+
appInsights.start();
|
|
28
32
|
aiClient = appInsights.defaultClient;
|
|
29
33
|
}
|
|
30
34
|
|
|
@@ -76,13 +80,12 @@ export function logEvent(
|
|
|
76
80
|
publisher: string,
|
|
77
81
|
event: string,
|
|
78
82
|
region: string,
|
|
79
|
-
sampling: string,
|
|
80
83
|
): void {
|
|
81
84
|
const properties: Telemetry['properties'] = {
|
|
82
85
|
publisher,
|
|
83
86
|
event,
|
|
84
87
|
region,
|
|
85
|
-
sampling,
|
|
88
|
+
sampling: process.env.SamplingLevel,
|
|
86
89
|
};
|
|
87
90
|
logMessage(1, 'Event dispatched to platform', properties);
|
|
88
91
|
}
|
|
@@ -340,14 +343,10 @@ export async function handlePlatformRequest({
|
|
|
340
343
|
rawPlatformResponse,
|
|
341
344
|
event.event,
|
|
342
345
|
);
|
|
343
|
-
|
|
344
|
-
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
|
|
345
|
-
logEvent(source, event.event, event.region, process.env.Sampling as string);
|
|
346
|
-
|
|
346
|
+
logEvent(source, event.event, event.region);
|
|
347
347
|
return processedPlatformResponse;
|
|
348
348
|
} else {
|
|
349
|
-
|
|
350
|
-
logEvent(source, event.event, event.region, process.env.Sampling as string);
|
|
349
|
+
logEvent(source, event.event, event.region);
|
|
351
350
|
}
|
|
352
351
|
}
|
|
353
352
|
|