Skip to content
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

Merged
merged 23 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
51bc047
Fix Issue 1848
jackyshang12321 Aug 15, 2022
5b6cc57
Merge pull request #3 from fidelity/Fix-Issue-1848
jackyshang12321 Aug 15, 2022
d44c7a8
add the new function to publicAPI doc
jackyshang12321 Aug 15, 2022
2157ebb
Merge pull request #4 from fidelity/Fix-Issue-1848
jackyshang12321 Aug 15, 2022
699472c
rather than stop exporting data, added a special message telling user…
jackyshang12321 Aug 15, 2022
72a9f5c
Merge pull request #5 from fidelity/Fix-Issue-1848
jackyshang12321 Aug 15, 2022
14e2ff8
Merge branch 'open-telemetry:main' into main
brianwarner Aug 25, 2022
a0e25ba
1. Record the callstack when the ConsoleExporter is disposed.
jackyshang12321 Aug 29, 2022
f2c5b49
Merge pull request #6 from fidelity/Fix-Issue-1848
jackyshang12321 Aug 29, 2022
d455131
Double-checking locking
jackyshang12321 Aug 30, 2022
5b3e2bf
update changelog
jackyshang12321 Aug 30, 2022
3690c47
Merge pull request #7 from fidelity/Fix-Issue-1848
jackyshang12321 Aug 30, 2022
0b7aea7
remove the SendDisposedMessage method
jackyshang12321 Aug 31, 2022
41ce82d
Merge pull request #8 from fidelity/Fix-Issue-1848
jackyshang12321 Aug 31, 2022
407b85a
remove lock and update changelog
jackyshang12321 Aug 31, 2022
505921d
Merge pull request #9 from fidelity/Fix-Issue-1848
jackyshang12321 Aug 31, 2022
eb4c64e
fix code bugs and update changelog
jackyshang12321 Sep 1, 2022
2033c64
Merge pull request #10 from fidelity/Fix-Issue-1848
jackyshang12321 Sep 1, 2022
1d17a21
Update src/OpenTelemetry.Exporter.Console/CHANGELOG.md
jackyshang12321 Sep 1, 2022
96f94e8
Merge branch 'open-telemetry:main' into main
jackyshang12321 Sep 2, 2022
8a1038f
Merge branch 'main' into main
jackyshang12321 Sep 2, 2022
eaadf27
Merge branch 'main' into main
jackyshang12321 Sep 2, 2022
915bce2
make it more clear who is at fault
jackyshang12321 Sep 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
override OpenTelemetry.Exporter.ConsoleLogRecordExporter.Dispose(bool disposing) -> void
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
override OpenTelemetry.Exporter.ConsoleLogRecordExporter.Dispose(bool disposing) -> void
5 changes: 5 additions & 0 deletions src/OpenTelemetry.Exporter.Console/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

* Changed error handling, `ConsoleExporter` will output error messages,
tell user where dispose happened and drop the data
if `Export` is invoked after the exporter is disposed.
([#1848](https://github.com/open-telemetry/opentelemetry-dotnet/issues/1848))
reyang marked this conversation as resolved.
Show resolved Hide resolved
jackyshang12321 marked this conversation as resolved.
Show resolved Hide resolved

## 1.4.0-alpha.2

Released 2022-Aug-18
Expand Down
29 changes: 29 additions & 0 deletions src/OpenTelemetry.Exporter.Console/ConsoleLogRecordExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.
// </copyright>

using System;
using System.Collections.Generic;
using OpenTelemetry.Logs;
using OpenTelemetry.Resources;
Expand All @@ -23,6 +24,9 @@ namespace OpenTelemetry.Exporter
public class ConsoleLogRecordExporter : ConsoleExporter<LogRecord>
{
private const int RightPaddingLength = 35;
private bool disposed;
private string disposedStackTrace;
private bool isDisposeMessageSent;

public ConsoleLogRecordExporter(ConsoleExporterOptions options)
: base(options)
Expand All @@ -31,6 +35,20 @@ public ConsoleLogRecordExporter(ConsoleExporterOptions options)

public override ExportResult Export(in Batch<LogRecord> batch)
{
if (this.disposed)
{
if (!this.isDisposeMessageSent)
{
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.");
Copy link
Contributor

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.

Suggested change
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.");

Copy link
Contributor Author

@jackyshang12321 jackyshang12321 Sep 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @utpilla , updated, thanks

this.WriteLine(Environment.StackTrace);
this.WriteLine(Environment.NewLine + "Dispose was called on the following stack trace:");
this.WriteLine(this.disposedStackTrace);
}

return ExportResult.Failure;
}
reyang marked this conversation as resolved.
Show resolved Hide resolved

foreach (var logRecord in batch)
{
this.WriteLine($"{"LogRecord.Timestamp:",-RightPaddingLength}{logRecord.Timestamp:yyyy-MM-ddTHH:mm:ss.fffffffZ}");
Expand Down Expand Up @@ -129,5 +147,16 @@ void ProcessScope(LogRecordScope scope, ConsoleLogRecordExporter exporter)

return ExportResult.Success;
}

protected override void Dispose(bool disposing)
{
if (!this.disposed)
reyang marked this conversation as resolved.
Show resolved Hide resolved
{
this.disposed = true;
this.disposedStackTrace = Environment.StackTrace;
}

base.Dispose(disposing);
}
}
}