-
Notifications
You must be signed in to change notification settings - Fork 790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[sdk-logs] Improve OpenTelemetryLogger.IsEnabled #5375
Conversation
@@ -111,7 +110,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except | |||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |||
public bool IsEnabled(LogLevel logLevel) | |||
{ | |||
return logLevel != LogLevel.None; | |||
return logLevel != LogLevel.None && !Sdk.SuppressInstrumentation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was never clear to me why the LogLevel.None check was needed.. If the LogLevel.None is used, the ILogger infra should not be even sending the log to this provider at all (maybe thats just my interpretation!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does appear somewhat standard: https://github.com/dotnet/runtime/blob/703f6e846027681a052970929989bd36e81636cd/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLogger.cs#L73-L76
But you are correct the LoggerFactory
also does a fast-check up front: https://github.com/dotnet/runtime/blob/703f6e846027681a052970929989bd36e81636cd/src/libraries/Microsoft.Extensions.Logging/src/LoggerInformation.cs#L32-L35
My guess would be it is because someone might swap out the default ILoggerFactory
with their own implementation which might not have the logic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it appears standard in the sense - every logging provider I have seen has that logic! I wasn't expecting that providers have to do that job, instead handled by ILogger itself.!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This change should be almost transparent to the user, unless the user is relying on the side effect:
With this change, it will be possible to save some CPU time if it is expensive to prepare the logging arguments:
The logic was originally written by me in #1329.
It was later refactored (with no change to the actual logic) https://github.com/open-telemetry/opentelemetry-dotnet/pull/1869/files#r588851416.