microsoft / ApplicationInsights-node.js

Microsoft Application Insights SDK for Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to Disable Logging by Setting samplingRate to Zero

gunzip opened this issue · comments

In certain scenarios, it is useful to completely suppress logging by setting the samplingRate to zero. However, the current code prevents this by taking the default value when samplingRate is set to zero, as shown in the following segment:

https://github.com/microsoft/ApplicationInsights-node.js/blob/main/src/shared/configuration/config.ts#L112

To address this, we need to modify the code to allow samplingRate to be set to zero without reverting to the default value. This change will provide greater flexibility in controlling logging behavior.

@gunzip I agree that this should be possible. Looks like the current implementation contains an oversight regarding 0 being falsy. I'll update this and link the PR to this issue.

@gunzip Working on getting a fix in at the moment. I am curious though what scenario you rely on this 0 sampling rate for. Is this for testing scenarios? Or some other use case?

Yes, exactly. I'm doing some tests to compute AI overhead at different levels of sampling. Moreover it's useful when you have a setup for staging slots, ie. using some sticky setting.

Consider also that the current README states:

Setting samplingPercentage to 100 (the default) means all data will be sent, and 0 means nothing will be sent.

When in reality you currently obtain a defaut to 100% sampling, which of course increase costs.