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] Throw ObjectDisposedException if Export happened after disposal #3607

Merged
merged 4 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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
override OpenTelemetry.Exporter.InMemoryExporter<T>.Dispose(bool disposing) -> void
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
override OpenTelemetry.Exporter.InMemoryExporter<T>.Dispose(bool disposing) -> void
5 changes: 5 additions & 0 deletions src/OpenTelemetry.Exporter.InMemory/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

* Changed error handling, `InMemoryExporter` will now throw
`ObjectDisposedException` if `Export` is invoked after the exporter is
disposed.
([#3607](https://github.com/open-telemetry/opentelemetry-dotnet/issues/3607))

## 1.4.0-alpha.2

Released 2022-Aug-18
Expand Down
23 changes: 22 additions & 1 deletion src/OpenTelemetry.Exporter.InMemory/InMemoryExporter.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;

namespace OpenTelemetry.Exporter
Expand All @@ -23,6 +24,7 @@ public class InMemoryExporter<T> : BaseExporter<T>
{
private readonly ICollection<T> exportedItems;
private readonly ExportFunc onExport;
private bool disposed = false;
reyang marked this conversation as resolved.
Show resolved Hide resolved

public InMemoryExporter(ICollection<T> exportedItems)
{
Expand All @@ -37,7 +39,26 @@ internal InMemoryExporter(ExportFunc exportFunc)

internal delegate ExportResult ExportFunc(in Batch<T> batch);

public override ExportResult Export(in Batch<T> batch) => this.onExport(batch);
public override ExportResult Export(in Batch<T> batch)
{
if (this.disposed)
{
throw new ObjectDisposedException(this.GetType().Name);
reyang marked this conversation as resolved.
Show resolved Hide resolved
}

return this.onExport(batch);
}

/// <inheritdoc/>
protected override void Dispose(bool disposing)
{
if (!this.disposed)
{
this.disposed = true;
}

base.Dispose(disposing);
}

private ExportResult DefaultExport(in Batch<T> batch)
{
Expand Down