diff --git a/src/OpenTelemetry/.publicApi/Stable/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/Stable/PublicAPI.Unshipped.txt index 5f0fd41cd26..e79caee69bb 100644 --- a/src/OpenTelemetry/.publicApi/Stable/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/Stable/PublicAPI.Unshipped.txt @@ -1,3 +1,4 @@ +OpenTelemetry.Batch.Batch(T! item) -> void OpenTelemetry.Metrics.MetricStreamConfiguration.CardinalityLimit.get -> int? OpenTelemetry.Metrics.MetricStreamConfiguration.CardinalityLimit.set -> void OpenTelemetry.OpenTelemetrySdk diff --git a/src/OpenTelemetry/Batch.cs b/src/OpenTelemetry/Batch.cs index b4ddd08cf17..033b6ebb35b 100644 --- a/src/OpenTelemetry/Batch.cs +++ b/src/OpenTelemetry/Batch.cs @@ -35,9 +35,13 @@ public Batch(T[] items, int count) this.Count = this.targetCount = count; } - internal Batch(T item) + /// + /// Initializes a new instance of the struct. + /// + /// The item to store in the batch. + public Batch(T item) { - Debug.Assert(item != null, $"{nameof(item)} was null."); + Guard.ThrowIfNull(item); this.item = item; this.Count = this.targetCount = 1; diff --git a/src/OpenTelemetry/CHANGELOG.md b/src/OpenTelemetry/CHANGELOG.md index 1467ffcaab2..5934a0ea67a 100644 --- a/src/OpenTelemetry/CHANGELOG.md +++ b/src/OpenTelemetry/CHANGELOG.md @@ -36,6 +36,10 @@ Notes](../../RELEASENOTES.md). There is NO ability to revert to old behavior. ([#5909](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5909)) +* Exposed a `public` constructor on `Batch` which accepts a single instance + of `T` to be contained in the batch. + ([#5642](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5642)) + ## 1.10.0-beta.1 Released 2024-Sep-30 diff --git a/test/OpenTelemetry.Tests/Trace/BatchTest.cs b/test/OpenTelemetry.Tests/Trace/BatchTest.cs index 8ecbe02f7ad..6f0a31842f3 100644 --- a/test/OpenTelemetry.Tests/Trace/BatchTest.cs +++ b/test/OpenTelemetry.Tests/Trace/BatchTest.cs @@ -14,6 +14,8 @@ public void CheckConstructorExceptions() Assert.Throws(() => new Batch((string[]?)null!, 0)); Assert.Throws(() => new Batch(Array.Empty(), -1)); Assert.Throws(() => new Batch(Array.Empty(), 1)); + + Assert.Throws(() => new Batch(null!)); } [Fact]