-
Notifications
You must be signed in to change notification settings - Fork 774
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
Fix: Logs could be exported via ConsoleExporter after LoggerFactory is disposed #1848 #3578
Conversation
jackyshang12321
commented
Aug 15, 2022
•
edited
Loading
edited
Fix Issue 1848
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #3578 +/- ##
==========================================
+ Coverage 87.09% 87.33% +0.23%
==========================================
Files 280 280
Lines 10081 10081
==========================================
+ Hits 8780 8804 +24
+ Misses 1301 1277 -24
|
add the new function to publicAPI doc
…s that something went wrong
Rather than stop exporting data, added a special message telling users that something went wrong
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 think the 1st step is to define the expected behavior and agree on it. @jackyshang12321 would you update the PR description and explain what exact behavior should we expect?
After we agree on the design, we can move to the coding part (which should be fairly straightforward).
Hi @reyang , thanks so much for the feedback, PR comment updated, please have a looks, thanks |
What are the other options you've considered? What's the pros/cons? What's the design principle here? (e.g. usability, maintain 100% same with existing .NET Console Log Provider, or something else). |
Hi @reyang , thank you so much for such a quick reply and leading thought. I've repeatedly thought about the two solutions you mentioned. One is that when the logger factory is destroyed, the console will no longer output any log. In this case, if we can give a special message to inform the user that the logger factory has been destroyed, the log information may not be output in subsequent open-telemetry updates, that may be more friendly to running applications and users. One concern is that just modifying the console exporter will lead to inconsistent behavior with other exporters, but we can start from console exporter and roll out to others later. Another thought on this question is, when an object of the upper/parent layer is destroyed, the object derived or generated by it should also be destroyed (otherwise it will cause some problems, such as resource or memory leaks), which is a reasonable and expected behavior. I'm not sure if there are other more reasonable solutions and ways to deal with this problem |
Here is my thinking:
|
We could modify this code...
...to do this: protected override void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
// Wait for up to 5 seconds grace period
var processor = this.Processor;
if (processor != null)
{
processor.Shutdown(5000);
processor.Dispose();
this.Processor = null;
}
this.ownedServiceProvider?.Dispose();
}
this.disposed = true;
OpenTelemetrySdkEventSource.Log.ProviderDisposed(nameof(OpenTelemetryLoggerProvider));
}
base.Dispose(disposing);
} There is already an SDK log message there when it is disposed if anyone is interested. The log logic has a
And this would work across the board. I still question the usefulness of this, but might be a better approach to "fixing" it. |
Then it makes perfect sense to stop exporting console log if it's already been disposed. |
Thanks @CodeBlanch , if we get an agreement, then that will be the change Hey @CodeBlanch , I'm new to this, please correct me if I'm wrong, if we set this.Processor to null, will that impact exporters other than ConsoleExporter? like otlp exporter. I think our goal is to disable log export from console |
Hi @reyang , sorry to bother you again, so what's the next step for this? |
I've briefly discussed this with @CodeBlanch and here is my suggestion: For ConsoleExporter (this PR):
For InMemoryExporter (out of the scope of this PR):
|
2. If ConsoleExporter.Export is ever called after it is disposed, depending on whether it is the 1st time: 2.1 if it is the first time - outputs an error message - including "what happened" and "what's the consequence" and "what should be done in order to fix the issue", plus two callstacks 1) the callstack where the export is being called 2) the callstack where dispose happened. 2.2 if it is not the first time, simply drop the data and don't output anything. 3. Everything here has to be done in a thread-safe manner.
1. Record the callstack when the ConsoleExporter is disposed. 2. If ConsoleExporter.Export is ever called after it is disposed, depending on whether it is the 1st time: 2.1 if it is the first time - outputs an error message - including "what happened" and "what's the consequence" and "what should be done in order to fix the issue", plus two callstacks 1) the callstack where the export is being called 2) the callstack where dispose happened. 2.2 if it is not the first time, simply drop the data and don't output anything. 3. Everything here has to be done in a thread-safe manner.
Hey @reyang , thank you so much for such a detailed design, the code has been modified according to the decision, and the output is similar to the following Please suggest is that Ok? Or do you think it would be more appropriate to remove the call stack inside opentelemetry? |
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 with a changelog entry.
remove the SendDisposedMessage method
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.
Please find my comments.
remove lock and update changelog
fix code bugs and update changelog
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.
Co-authored-by: Reiley Yang <reyang@microsoft.com>
Hi @reyang , I am confused by the error, I checked the error messages in the build and code coverage steps, but I don't understand what is causing the failure, could you help check it when you get a chance, thank you |
Would you rebase to the latest main branch? |
Done, thank you |
@jackyshang12321 Would you update the PR description to reflect the final design? Also rebase from main, and we are good to merge! Thank you. |
this.isDisposeMessageSent = true; | ||
} | ||
|
||
this.WriteLine("The console exporter is still being invoked after it has been disposed. This could be the result of invalid lifecycle management of the OpenTelemetry .NET SDK."); |
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 could be the result of invalid lifecycle management of the OpenTelemetry .NET SDK.
This could be misinterpreted for OTel SDK being at fault. As in the OTel .NET SDK does not do lifecycle management of something correctly. I think we should clearly call out who is at fault.
this.WriteLine("The console exporter is still being invoked after it has been disposed. This could be the result of invalid lifecycle management of the OpenTelemetry .NET SDK."); | |
this.WriteLine("The console exporter is still being invoked after it has been disposed. This could be the due to the application's incorrect lifecycle management of the LoggerFactory/OpenTelemetry .NET SDK."); |
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.
Hi @utpilla , updated, thanks
Done, please check, thank you |
Hi @reyang , I want to say thank you, this is my first github PR, you know the first time you always feel like you can't figure it out, but thank you so much for being so patient with me, and for helping me figure everything out. |