diff --git a/src/shared/configuration/config.ts b/src/shared/configuration/config.ts index 90d137cd..b88bbb32 100644 --- a/src/shared/configuration/config.ts +++ b/src/shared/configuration/config.ts @@ -109,9 +109,6 @@ export class ApplicationInsightsConfig { options.instrumentationOptions ); this.resource = Object.assign(this.resource, options.resource); - if (typeof(options.samplingRatio) === "number") { - this.samplingRatio = options.samplingRatio; - } this.samplingRatio = options.samplingRatio !== undefined ? options.samplingRatio : this.samplingRatio; // Set console logging level from env var diff --git a/src/shim/shim-config.ts b/src/shim/shim-config.ts index eca8d03e..efbef798 100644 --- a/src/shim/shim-config.ts +++ b/src/shim/shim-config.ts @@ -151,8 +151,12 @@ class Config implements IConfig { ...options.instrumentationOptions, console: { enabled: false }, }; - if (this.samplingPercentage !== undefined) { - options.samplingRatio = this.samplingPercentage / 100; + const samplingRatio = this.samplingPercentage / 100; + if (samplingRatio >= 0 && samplingRatio <= 1) { + options.samplingRatio = samplingRatio; + } else { + options.samplingRatio = 1; + this._configWarnings.push(`Sampling percentage should be between 0 and 100. Defaulting to 100.`); } options.instrumentationOptions = { ...options.instrumentationOptions,