Skip to content

Commit

Permalink
rather than stop exporting data, added a special message telling user…
Browse files Browse the repository at this point in the history
…s that something went wrong
  • Loading branch information
jackyshang12321 committed Aug 15, 2022
1 parent d44c7a8 commit 699472c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
override OpenTelemetry.Exporter.ConsoleExporter<T>.Dispose(bool disposing) -> void
override OpenTelemetry.Exporter.ConsoleLogRecordExporter.Dispose(bool disposing) -> void
Original file line number Diff line number Diff line change
@@ -1 +1 @@
override OpenTelemetry.Exporter.ConsoleExporter<T>.Dispose(bool disposing) -> void
override OpenTelemetry.Exporter.ConsoleLogRecordExporter.Dispose(bool disposing) -> void
14 changes: 0 additions & 14 deletions src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public abstract class ConsoleExporter<T> : BaseExporter<T>
where T : class
{
private readonly ConsoleExporterOptions options;
private bool disposed = false;

protected ConsoleExporter(ConsoleExporterOptions options)
{
Expand All @@ -29,11 +28,6 @@ protected ConsoleExporter(ConsoleExporterOptions options)

protected void WriteLine(string message)
{
if (this.disposed)
{
return;
}

if (this.options.Targets.HasFlag(ConsoleExporterOutputTargets.Console))
{
System.Console.WriteLine(message);
Expand All @@ -44,13 +38,5 @@ protected void WriteLine(string message)
System.Diagnostics.Trace.WriteLine(message);
}
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
this.disposed = true;
}
}
}
}
14 changes: 14 additions & 0 deletions src/OpenTelemetry.Exporter.Console/ConsoleLogRecordExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace OpenTelemetry.Exporter
public class ConsoleLogRecordExporter : ConsoleExporter<LogRecord>
{
private const int RightPaddingLength = 35;
private bool disposed = false;

public ConsoleLogRecordExporter(ConsoleExporterOptions options)
: base(options)
Expand All @@ -33,6 +34,11 @@ public override ExportResult Export(in Batch<LogRecord> batch)
{
foreach (var logRecord in batch)
{
if (this.disposed)
{
this.WriteLine("Something is wrong: the ConsoleLogger has been disposed.");
}

this.WriteLine($"{"LogRecord.Timestamp:",-RightPaddingLength}{logRecord.Timestamp:yyyy-MM-ddTHH:mm:ss.fffffffZ}");

if (logRecord.TraceId != default)
Expand Down Expand Up @@ -129,5 +135,13 @@ void ProcessScope(LogRecordScope scope, ConsoleLogRecordExporter exporter)

return ExportResult.Success;
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
this.disposed = true;
}
}
}
}

0 comments on commit 699472c

Please sign in to comment.