Skip to content

Commit 7c0f24c

Browse files
[sdk] Expose the ctor on Batch<T> which accepts a single item (open-telemetry#5642)
Co-authored-by: Cijo Thomas <[email protected]>
1 parent ed1b27f commit 7c0f24c

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

src/OpenTelemetry/.publicApi/Stable/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
OpenTelemetry.Batch<T>.Batch(T! item) -> void
12
OpenTelemetry.Metrics.MetricStreamConfiguration.CardinalityLimit.get -> int?
23
OpenTelemetry.Metrics.MetricStreamConfiguration.CardinalityLimit.set -> void
34
OpenTelemetry.OpenTelemetrySdk

src/OpenTelemetry/Batch.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ public Batch(T[] items, int count)
3535
this.Count = this.targetCount = count;
3636
}
3737

38-
internal Batch(T item)
38+
/// <summary>
39+
/// Initializes a new instance of the <see cref="Batch{T}"/> struct.
40+
/// </summary>
41+
/// <param name="item">The item to store in the batch.</param>
42+
public Batch(T item)
3943
{
40-
Debug.Assert(item != null, $"{nameof(item)} was null.");
44+
Guard.ThrowIfNull(item);
4145

4246
this.item = item;
4347
this.Count = this.targetCount = 1;

src/OpenTelemetry/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Notes](../../RELEASENOTES.md).
3636
There is NO ability to revert to old behavior.
3737
([#5909](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5909))
3838

39+
* Exposed a `public` constructor on `Batch<T>` which accepts a single instance
40+
of `T` to be contained in the batch.
41+
([#5642](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5642))
42+
3943
## 1.10.0-beta.1
4044

4145
Released 2024-Sep-30

test/OpenTelemetry.Tests/Trace/BatchTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public void CheckConstructorExceptions()
1414
Assert.Throws<ArgumentNullException>(() => new Batch<string>((string[]?)null!, 0));
1515
Assert.Throws<ArgumentOutOfRangeException>(() => new Batch<string>(Array.Empty<string>(), -1));
1616
Assert.Throws<ArgumentOutOfRangeException>(() => new Batch<string>(Array.Empty<string>(), 1));
17+
18+
Assert.Throws<ArgumentNullException>(() => new Batch<string>(null!));
1719
}
1820

1921
[Fact]

0 commit comments

Comments
 (0)