Fixing NullReferenceException in SpanAttributes (#1304)

Testing null reference

Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
This commit is contained in:
Eddy Nakamura 2020-09-24 15:35:29 -03:00 committed by GitHub
parent f79376d163
commit 2037a45f57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -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)
{

View File

@ -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));
}
}
}