-
Notifications
You must be signed in to change notification settings - Fork 772
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
Logformatter null check #2200
Logformatter null check #2200
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2200 +/- ##
==========================================
+ Coverage 79.36% 80.96% +1.60%
==========================================
Files 217 217
Lines 6992 6994 +2
==========================================
+ Hits 5549 5663 +114
+ Misses 1443 1331 -112
|
try | ||
{ | ||
// Pass null as formatter function | ||
this.logger.Log(LogLevel.Information, default, "Hello World!", null, null); |
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.
@jviau - Please review!
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.
I am not sure this was a bug to begin with. Many other log implementations all explicitly throw on a null formatter.
ConsoleLogger
EventLogLogger
ApplicationInsightsLogger
But with that said, the aggregate logger doesn't throw. So I am guessing it is up to each logger to decide what to do.
Either way, this change is fine within context of how otel currently behaves.
src/OpenTelemetry/CHANGELOG.md
Outdated
@@ -5,6 +5,9 @@ | |||
* Removes upper constraint for Microsoft.Extensions.Logging | |||
dependencies. ([#2179](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2179)) | |||
|
|||
* Fix bug which caused ILogger.Log calls to throw exception, when the |
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.
Do we consider this as a bug?
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.
Good qn. After seeing some other implementations, which throw in Log(...formatter=null)., I am thinking we should follow the regular pattern of "not throwing from instrumentation APIs after successful initialization". So Otel logging provider can chose to not throw, end user may still see exception from other providers they have enabled.
And I can reword the changelog to just say:
"OpenTelemetry Logger modified to not throw when formatter is null"
ilogger.Log(LogLevel.Information, default, "Hello World!", null, null);
(note the last param is null, which is the formatter) when combined withIncludeFormattedMessage=true
will result in an unhandled exception. This PR check if formatter is not null, before invoking it.Also removed some netcoreapp2.1 checks. (leftover cleanups)