From d2a82cc92ac76ea27eb0ce5ae487736b26de8b8d Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Tue, 21 May 2024 16:35:48 -0700 Subject: [PATCH 1/3] Expose the ctor on Batch which accepts a single item. --- .../.publicApi/Stable/PublicAPI.Unshipped.txt | 1 + src/OpenTelemetry/Batch.cs | 8 ++++++-- src/OpenTelemetry/CHANGELOG.md | 4 ++++ test/OpenTelemetry.Tests/Trace/BatchTest.cs | 2 ++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry/.publicApi/Stable/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/Stable/PublicAPI.Unshipped.txt index a9a6c031d7a..3ad610b842e 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.Exemplar OpenTelemetry.Metrics.Exemplar.DoubleValue.get -> double OpenTelemetry.Metrics.Exemplar.Exemplar() -> void 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 763f3f370a0..7ef3fcd75cf 100644 --- a/src/OpenTelemetry/CHANGELOG.md +++ b/src/OpenTelemetry/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +* Exposed a `public` constructor on `Batch` which accepts a single instance + of `T` to be contained in the batch. + ([#XXXX](https://github.com/open-telemetry/opentelemetry-dotnet/pull/XXXX)) + ## 1.9.0-alpha.1 Released 2024-May-20 diff --git a/test/OpenTelemetry.Tests/Trace/BatchTest.cs b/test/OpenTelemetry.Tests/Trace/BatchTest.cs index b1d5b170d52..d64c697492f 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] From 3383360cc9446480495ffa3dd634df8616da5b54 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Tue, 21 May 2024 16:38:03 -0700 Subject: [PATCH 2/3] CHANGELOG patch. --- src/OpenTelemetry/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry/CHANGELOG.md b/src/OpenTelemetry/CHANGELOG.md index 7ef3fcd75cf..e34a00b7ede 100644 --- a/src/OpenTelemetry/CHANGELOG.md +++ b/src/OpenTelemetry/CHANGELOG.md @@ -4,7 +4,7 @@ * Exposed a `public` constructor on `Batch` which accepts a single instance of `T` to be contained in the batch. - ([#XXXX](https://github.com/open-telemetry/opentelemetry-dotnet/pull/XXXX)) + ([#5642](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5642)) ## 1.9.0-alpha.1 From 8c02916b9847cdf121640b75914c43f4b5c28b66 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Fri, 1 Nov 2024 13:07:57 -0700 Subject: [PATCH 3/3] Test fix. --- test/OpenTelemetry.Tests/Trace/BatchTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/OpenTelemetry.Tests/Trace/BatchTest.cs b/test/OpenTelemetry.Tests/Trace/BatchTest.cs index c5445a3bacd..6f0a31842f3 100644 --- a/test/OpenTelemetry.Tests/Trace/BatchTest.cs +++ b/test/OpenTelemetry.Tests/Trace/BatchTest.cs @@ -15,7 +15,7 @@ public void CheckConstructorExceptions() Assert.Throws(() => new Batch(Array.Empty(), -1)); Assert.Throws(() => new Batch(Array.Empty(), 1)); - Assert.Throws(() => new Batch(null)); + Assert.Throws(() => new Batch(null!)); } [Fact]