Skip to content

Commit

Permalink
Update to send warning if sampling percentage is set incorrectly in t…
Browse files Browse the repository at this point in the history
…he app insights v3.
  • Loading branch information
JacksonWeber committed Jun 5, 2024
1 parent c7ab354 commit cd826ce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/shared/configuration/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/shim/shim-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit cd826ce

Please sign in to comment.