Repository: microsoft/ApplicationInsights-node.js
Pull request #1099 (2023-03-06 22:12:58)

[Beta] Rename samplingRate to samplingRatio


Patch:
diff --git a/README.md b/README.md
index 585b867..8482059 100644
--- a/README.md
+++ b/README.md
@@ -109,7 +109,7 @@ appInsights.start();
 |Property|Description|Default|
 | ------------------------------- |------------------------------------------------------------------------------------------------------------|-------|
 | connectionString                     | Application Insights Resource Connection String                                                    | |
-| samplingRatio              | Sampling ration must take a value in the range [0,1], 1 meaning all data will sampled and 0 all Tracing data will be sampled out.                       | 1|
+| samplingRatio              | Sampling ratio must take a value in the range [0,1], 1 meaning all data will sampled and 0 all Tracing data will be sampled out.                       | 1|
 | enableAutoCollectExceptions     | Sets the state of exception tracking. If true uncaught exceptions will be sent to Application Insights | true|
 | enableAutoCollectPerformance    | Sets the state of performance tracking. If true performance counters will be collected every second and sent to Application Insights | true|
 | enableAutoCollectStandardMetrics | Sets the state of Standard Metrics tracking. If true Standard Metrics will be collected every minute and sent to Application Insights | true|
@@ -128,7 +128,7 @@ All these properties except aadTokenCredential and resource could be configured
 ```json
 {
     "connectionString": "<YOUR_CONNECTION_STRING>",
-    "samplingRate": 0.8,
+    "samplingRatio": 0.8,
     "enableAutoCollectExceptions": true,
     "enableAutoCollectHeartbeat": true,
     "instrumentations":{
@@ -221,7 +221,7 @@ You may want to enable sampling to reduce your data ingestion volume which reduc
 ```typescript
 const config = new ApplicationInsightsConfig();
 config.connectionString = "<YOUR_CONNECTION_STRING>";
-config.samplingRate = 0.1;
+config.samplingRatio = 0.1;
 const appInsights = new ApplicationInsightsClient(config);
 appInsights.start();
 ```
diff --git a/src/agent/agentLoader.ts b/src/agent/agentLoader.ts
index 100b70f..f0f4f91 100644
--- a/src/agent/agentLoader.ts
+++ b/src/agent/agentLoader.ts
@@ -34,7 +34,7 @@ export class AgentLoader {
             this._config.enableAutoCollectHeartbeat = true;
             this._config.enableAutoCollectPerformance = true;
             this._config.enableAutoCollectStandardMetrics = true;
-            this._config.samplingRate = 100;
+            this._config.samplingRatio = 1; // Sample all telemetry by default
             this._config.instrumentations.azureSdk.enabled = true;
             this._config.instrumentations.http.enabled = true;
             this._config.instrumentations.mongoDb.enabled = true;
diff --git a/src/shared/configuration/applicationInsightsConfig.ts b/src/shared/configuration/applicationInsightsConfig.ts
index 1313d9c..506bcab 100644
--- a/src/shared/configuration/applicationInsightsConfig.ts
+++ b/src/shared/configuration/applicationInsightsConfig.ts
@@ -24,7 +24,7 @@ const DEFAULT_ROLE_NAME = "Web";
 
 
 export class ApplicationInsightsConfig implements IConfig {
-    public samplingRate: number;
+    public samplingRatio: number;
     public aadTokenCredential?: azureCore.TokenCredential;
     public enableAutoCollectExceptions: boolean;
     public enableAutoCollectPerformance: boolean;
@@ -104,7 +104,7 @@ export class ApplicationInsightsConfig implements IConfig {
             this.enableAutoCollectStandardMetrics !== undefined
                 ? this.enableAutoCollectStandardMetrics
                 : true;
-        this.samplingRate = this.samplingRate !== undefined ? this.samplingRate : 1;
+        this.samplingRatio = this.samplingRatio !== undefined ? this.samplingRatio : 1;
         this.instrumentations = {
             http: { enabled: true },
             azureSdk: { enabled: false },
@@ -171,8 +171,8 @@ export class ApplicationInsightsConfig implements IConfig {
                 jsonConfig.enableAutoCollectStandardMetrics !== undefined
                     ? jsonConfig.enableAutoCollectStandardMetrics
                     : this.enableAutoCollectStandardMetrics;
-            this.samplingRate =
-                jsonConfig.samplingRate !== undefined ? jsonConfig.samplingRate : this.samplingRate;
+            this.samplingRatio =
+                jsonConfig.samplingRatio !== undefined ? jsonConfig.samplingRatio : this.samplingRatio;
             this.storageDirectory =
                 jsonConfig.storageDirectory !== undefined
                     ? jsonConfig.storageDirectory
diff --git a/src/shared/configuration/jsonConfig.ts b/src/shared/configuration/jsonConfig.ts
index 23367ea..08079bc 100644
--- a/src/shared/configuration/jsonConfig.ts
+++ b/src/shared/configuration/jsonConfig.ts
@@ -9,7 +9,7 @@ export class JsonConfig implements IBaseConfig {
     private static _instance: JsonConfig;
 
     public connectionString: string;
-    public samplingRate: number;
+    public samplingRatio: number;
     public enableAutoCollectExceptions: boolean;
     public enableAutoCollectPerformance: boolean;
     public enableAutoCollectStandardMetrics: boolean;
@@ -48,7 +48,7 @@ export class JsonConfig implements IBaseConfig {
             if (jsonConfig.connectionString !== undefined) {
                 this.connectionString = jsonConfig.connectionString;
             }
-            this.samplingRate = jsonConfig.samplingRate;
+            this.samplingRatio = jsonConfig.samplingRatio;
             this.enableAutoCollectExceptions = jsonConfig.enableAutoCollectExceptions;
             this.enableAutoCollectPerformance = jsonConfig.enableAutoCollectPerformance;
             this.enableAutoCollectStandardMetrics = jsonConfig.enableAutoCollectStandardMetrics;
diff --git a/src/shared/configuration/types.ts b/src/shared/configuration/types.ts
index abecb74..6bdc2f7 100644
--- a/src/shared/configuration/types.ts
+++ b/src/shared/configuration/types.ts
@@ -11,7 +11,7 @@ export interface IBaseConfig {
     /** Connection String used to send telemetry payloads to */
     connectionString: string;
     /** The rate of telemetry items tracked that should be transmitted (Default 1.0) */
-    samplingRate: number;
+    samplingRatio: number;
     /**
      * Sets the state of exception tracking (enabled by default)
      * if true uncaught exceptions will be sent to Application Insights
diff --git a/src/traces/traceHandler.ts b/src/traces/traceHandler.ts
index 2e584fa..489d4b5 100644
--- a/src/traces/traceHandler.ts
+++ b/src/traces/traceHandler.ts
@@ -48,7 +48,7 @@ export class TraceHandler {
         this._config = config;
         this._metricHandler = metricHandler;
         this._instrumentations = [];
-        const aiSampler = new ApplicationInsightsSampler(this._config.samplingRate);
+        const aiSampler = new ApplicationInsightsSampler(this._config.samplingRatio);
         const tracerConfig: NodeTracerConfig = {
             sampler: aiSampler,
             resource: this._config.resource,


Test patch:
diff --git a/test/functionalTests/testApp/main.js b/test/functionalTests/testApp/main.js
index 1d918f0..e9369a5 100644
--- a/test/functionalTests/testApp/main.js
+++ b/test/functionalTests/testApp/main.js
@@ -6,7 +6,7 @@ if (testconfig.AppInsightsEnabled) {
 
     let config = new ApplicationInsightsConfig();
     config.connectionString = `InstrumentationKey=${testconfig.InstrumentationKey};IngestionEndpoint=${testconfig.EndpointBaseAddress}`;
-    config.samplingRate = parseFloat(testconfig.SampleRate);
+    config.samplingRatio = parseFloat(testconfig.SampleRate);
     config.instrumentations["http"].enabled = true;
     config.instrumentations["azureSdk"].enabled = true;
     config.instrumentations["mongoDb"].enabled = true;
diff --git a/test/unitTests/shared/config.json b/test/unitTests/shared/config.json
index 814857f..078e586 100644
--- a/test/unitTests/shared/config.json
+++ b/test/unitTests/shared/config.json
@@ -1,6 +1,6 @@
 {
     "connectionString": "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;IngestionEndpoint=https://centralus-0.in.applicationinsights.azure.com/",
-    "samplingRate": 0.3,
+    "samplingRatio": 0.3,
     "enableAutoCollectExceptions": false,
     "enableAutoCollectPerformance": false,
     "enableAutoCollectStandardMetrics": false,
diff --git a/test/unitTests/shared/config.tests.ts b/test/unitTests/shared/config.tests.ts
index a57d5b6..da30d93 100644
--- a/test/unitTests/shared/config.tests.ts
+++ b/test/unitTests/shared/config.tests.ts
@@ -74,7 +74,7 @@ describe("Library/Config", () => {
                     config["_connectionString"],
                     "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;IngestionEndpoint=https://centralus-0.in.applicationinsights.azure.com/"
                 );
-                assert.equal(config.samplingRate, 0.3, "Wrong samplingRate");
+                assert.equal(config.samplingRatio, 0.3, "Wrong samplingRatio");
                 assert.equal(config.disableOfflineStorage, true, "Wrong disableOfflineStorage");
                 assert.equal(config.storageDirectory, "testPath", "Wrong storageDirectory");
                 assert.equal(
@@ -113,7 +113,7 @@ describe("Library/Config", () => {
 
             it("Default config", () => {
                 const config = new ApplicationInsightsConfig();
-                assert.equal(config.samplingRate, 1, "Wrong samplingRate");
+                assert.equal(config.samplingRatio, 1, "Wrong samplingRatio");
                 assert.equal(
                     config.enableAutoCollectExceptions,
                     true,
@@ -191,7 +191,7 @@ describe("Library/Config", () => {
                 const config = new ApplicationInsightsConfig();
                 config.connectionString = "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333";
                 assert(typeof config.getInstrumentationKey() === "string");
-                assert(typeof config.samplingRate === "number");
+                assert(typeof config.samplingRatio === "number");
             });
 
             it("instrumentation key validation-valid key passed", () => {
diff --git a/test/unitTests/shared/jsonConfig.tests.ts b/test/unitTests/shared/jsonConfig.tests.ts
index 60bcdaa..834b4dc 100644
--- a/test/unitTests/shared/jsonConfig.tests.ts
+++ b/test/unitTests/shared/jsonConfig.tests.ts
@@ -75,7 +75,7 @@ describe("Json Config", () => {
                 config.connectionString,
                 "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;IngestionEndpoint=https://centralus-0.in.applicationinsights.azure.com/"
             );
-            assert.equal(config.samplingRate, 0.3, "Wrong samplingRate");
+            assert.equal(config.samplingRatio, 0.3, "Wrong samplingRatio");
             assert.equal(
                 config.enableAutoCollectExceptions,
                 false,