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

[InMemoryExporter] Include original stack trace in ObjectDisposedException #3609

Merged
merged 5 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
6 changes: 5 additions & 1 deletion src/OpenTelemetry.Exporter.InMemory/InMemoryExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class InMemoryExporter<T> : BaseExporter<T>
private readonly ICollection<T> exportedItems;
private readonly ExportFunc onExport;
private bool disposed;
private string disposedStackTrace;

public InMemoryExporter(ICollection<T> exportedItems)
{
Expand All @@ -44,7 +45,9 @@ public override ExportResult Export(in Batch<T> batch)
if (this.disposed)
{
// Note: In-memory exporter is designed for testing purposes so this error is strategic to surface lifecycle management bugs during development.
throw new ObjectDisposedException(this.GetType().Name, "The in-memory exporter is still being invoked after it has been disposed. This could be the result of invalid lifecycle management of the OpenTelemetry .NET SDK.");
throw new ObjectDisposedException(
this.GetType().Name,
$"The in-memory exporter is still being invoked after it has been disposed. This could be the result of invalid lifecycle management of the OpenTelemetry .NET SDK. Dispose was called on the following stack trace:{Environment.NewLine}{this.disposedStackTrace}");
}

return this.onExport(batch);
Expand All @@ -55,6 +58,7 @@ protected override void Dispose(bool disposing)
{
if (!this.disposed)
{
this.disposedStackTrace = Environment.StackTrace;
this.disposed = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public void StateBufferingTest()
logRecord.State = state;

exporter.OnEnd(logRecord);
exporter.Shutdown();
reyang marked this conversation as resolved.
Show resolved Hide resolved

state.Dispose();

Expand Down