SonarQube coverage complaints log and instrumentation code?

My company uses SonarQube 9.9 which is integrated with Jenkins.
I am trying to understand the code coverage result of my PR.
I found that SonarQube complains log output, like this:

logger.Debug("Verbose logging is turned on.")

SonarQube warned the above line was not covered by tests, is it really necessary to enforce the log output should be tested?

It also complains the instrumentation code, where publish metrics, like this:
metricSink.SetGauge([]string{metricChangeBlocked}, float32(1))

I am not sure if there any rules can skip checking these instrumentation code? It is useless to spend lots of time to design the tests around logs and instrumentation.



Welcome to the community!

First, if a file is included in your coverage report, SonarQube goes entirely by what the report says about it.

So it’s really not a question of SonarQube ignoring logging, but of convincing the maintainers of your coverage engine they should ignore it.

My understanding is that a line is generally considered “covered” if a test makes it run. So apparently you didn’t have any tests that executed that line. If it were me, I would be less concerned about that particular line than about the lines before and after it. But that’s really a discussion to have with your team.

And if all else fails, you can consider excluding the entire file from coverage calculations.