-
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
OpenTelemetryLoggerProvider is now unaffected by changes to OpenTelemetryLoggerOptions after the LoggerFactory is built. #3055
OpenTelemetryLoggerProvider is now unaffected by changes to OpenTelemetryLoggerOptions after the LoggerFactory is built. #3055
Conversation
This reverts commit 9dcb839.
Codecov Report
@@ Coverage Diff @@
## main #3055 +/- ##
=======================================
Coverage ? 84.78%
=======================================
Files ? 259
Lines ? 9187
Branches ? 0
=======================================
Hits ? 7789
Misses ? 1398
Partials ? 0
|
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 once a changelog entry is added
Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
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.
Perf concern on hotpath https://github.com/open-telemetry/opentelemetry-dotnet/pull/3055/files#r830227799
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.
@@ -30,38 +30,15 @@ | |||
|
|||
namespace OpenTelemetry.Logs.Tests | |||
{ | |||
public sealed class LogRecordTest : IDisposable | |||
public sealed class LogRecordTest |
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.
The loggerfactory was disposed in IDisposable impln. It does not look like factory is disposed in the new tests.
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.
changed the helper method to return the factory. calling method is responsible for using using
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.
Code changes looks good (Thanks for addressing the perf issues !)
The test changes does not seem to be disposing the factory. This needs to be fixed before we merge.
@@ -595,7 +595,7 @@ public void ParseStateValuesUsingCustomTest() | |||
Assert.Same(state, actualState.Value); | |||
} | |||
|
|||
private static void InitializeLoggerFactory(out ILogger logger, out List<LogRecord> exportedItems, Action<OpenTelemetryLoggerOptions> configure = null) | |||
private static ILoggerFactory InitializeLoggerFactory(out ILogger logger, out List<LogRecord> exportedItems, Action<OpenTelemetryLoggerOptions> configure = 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.
why do we have to have the helper method create a ILogger? It can just do what it claims to do (from the name) - initialize and return a loggerfactory, configured as per the configure
action given to it.
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.
This was meant to simplify the individual tests by removing a dozen lines of identical boilerplate code.
I can move some or all of this into every test, but I don't think that improves the value of the tests themselves.
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.
The name of the helper method did not indicate its intended purpose. The latest commit looks better.
(if we want to achieve less duplication in tests, we can do that, with aptly named helper. but this looks good for me now)
Fixes #2902.
Changes
OpenTelemetryLoggerProvider
will now copy the values fromOpenTelemetryLoggerOptions
. This prevents changes to the Provider after being initialized.Please provide a brief description of the changes here.
For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changesOptions
I investigated 3 options.
Option 1,
ctor of LoggerProvider copies Options to local fields.
Logger.Log references
this.provider.<local fields>
.This introduces an ldfld.
Option 2,
ctor of LoggerProvider copies Options to local fields.
ctor of Logger copies Options to local fields.
Logger.Log references
this.<local fields>
.Option 3,
ctor of LoggerProvider copies Options to local fields.
Logger.Log first creates a local var for the provider
var provider = this.provider
then references all other properties/fields from the local varprovider.<local fields>
.This was done in an attempt to mitigate the ldfld.
Benchmarks
Test
For this test, I initialized the Provider and Logger.
For the benchmark, I invoke the hotpath (Logger.Log) which accesses the Options.
The results are inconclusive, I'm seeing a negligible difference between implementations.
Benchmark code
Option 1:
Option 2:
Option 3
IL
The IL code is a bit more revealing.
Option 1 introduces additional
ldfld
when accessing every field.Original, Option 2, and Option 3 are nearly identical.
Considering this, I'm recommending Option 3.