@mhubcloud/tms_core 3.3.0-beta.0 → 3.3.0-beta.1

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 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
- appInsights.setup().setAutoCollectDependencies(false).setAutoCollectConsole(true, false).setSendLiveMetrics(false).setAutoCollectRequests(false).setAutoCollectPerformance(false).setUseDiskRetryCaching(false).start();
60
+ const samplingLevel = process.env.Sampling ?? "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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mhubcloud/tms_core",
3
- "version": "3.3.0-beta.0",
3
+ "version": "3.3.0-beta.1",
4
4
  "description": "Core function for mHub Cloud TMS publishers",
5
5
  "homepage": "https://mhubcloud.com/",
6
6
  "license": "Apache 2.0",
@@ -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
- .start();
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
- // eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
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