Fixing NullReferenceException in SpanAttributes (#1304)
Testing null reference Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
This commit is contained in:
parent
f79376d163
commit
2037a45f57
|
|
@ -38,6 +38,7 @@ namespace OpenTelemetry.Trace
|
|||
/// </summary>
|
||||
/// <param name="attributes">Initial attributes to store in the collection.</param>
|
||||
public SpanAttributes(IEnumerable<KeyValuePair<string, object>> attributes)
|
||||
: this()
|
||||
{
|
||||
if (attributes == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Trace.Tests
|
||||
|
|
@ -62,5 +63,23 @@ namespace OpenTelemetry.Trace.Tests
|
|||
spanAttribute.Add("key", "value2");
|
||||
Assert.Equal("value2", spanAttribute.Attributes["key"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidateConstructorWithList()
|
||||
{
|
||||
var spanAttributes = new SpanAttributes(
|
||||
new List<KeyValuePair<string, object>>()
|
||||
{
|
||||
new KeyValuePair<string, object>("Span attribute int", 1),
|
||||
new KeyValuePair<string, object>("Span attribute string", "str"),
|
||||
});
|
||||
Assert.Equal(2, spanAttributes.Attributes.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidateConstructorWithNullList()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new SpanAttributes(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue