diff --git a/src/OpenTelemetry.Exporter.Zipkin/Implementation/ZipkinActivityConversionExtensions.cs b/src/OpenTelemetry.Exporter.Zipkin/Implementation/ZipkinActivityConversionExtensions.cs index ccabc07021..6204747792 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/Implementation/ZipkinActivityConversionExtensions.cs +++ b/src/OpenTelemetry.Exporter.Zipkin/Implementation/ZipkinActivityConversionExtensions.cs @@ -208,17 +208,16 @@ internal static bool ProcessTags(ref AttributeEnumerationState state, KeyValuePa { state.ServiceNamespace = strVal; } - else - { - PooledList>.Add(ref state.Tags, new KeyValuePair(key, strVal)); - } - } - else if (attribute.Value is int intVal && attribute.Key == SemanticConventions.AttributeNetPeerPort) - { - state.Port = intVal; + + PooledList>.Add(ref state.Tags, new KeyValuePair(key, strVal)); } else { + if (attribute.Value is int intVal && attribute.Key == SemanticConventions.AttributeNetPeerPort) + { + state.Port = intVal; + } + PooledList>.Add(ref state.Tags, attribute); } diff --git a/test/OpenTelemetry.Exporter.Zipkin.Tests/Implementation/ZipkinActivityConversionTest.cs b/test/OpenTelemetry.Exporter.Zipkin.Tests/Implementation/ZipkinActivityConversionTest.cs index 2e3ad3f212..54d145484b 100644 --- a/test/OpenTelemetry.Exporter.Zipkin.Tests/Implementation/ZipkinActivityConversionTest.cs +++ b/test/OpenTelemetry.Exporter.Zipkin.Tests/Implementation/ZipkinActivityConversionTest.cs @@ -26,7 +26,7 @@ public class ZipkinActivityConversionTest private static readonly ZipkinEndpoint DefaultZipkinEndpoint = new ZipkinEndpoint("TestService"); [Fact] - public void ZipkinActivityConversion_ToZipkinSpan_AllPropertiesSet() + public void ToZipkinSpan_AllPropertiesSet() { // Arrange var activity = ZipkinExporterTests.CreateTestActivity(); @@ -45,7 +45,7 @@ public void ZipkinActivityConversion_ToZipkinSpan_AllPropertiesSet() int counter = 0; var tagsArray = zipkinSpan.Tags.Value.ToArray(); - foreach (var tags in activity.Tags) + foreach (var tags in activity.TagObjects) { Assert.Equal(tagsArray[counter].Key, tags.Key); Assert.Equal(tagsArray[counter++].Value, tags.Value); @@ -59,7 +59,7 @@ public void ZipkinActivityConversion_ToZipkinSpan_AllPropertiesSet() } [Fact] - public void ZipkinActivityConversion_ToZipkinSpan_NoEvents() + public void ToZipkinSpan_NoEvents() { // Arrange var activity = ZipkinExporterTests.CreateTestActivity(addEvents: false); @@ -75,7 +75,7 @@ public void ZipkinActivityConversion_ToZipkinSpan_NoEvents() int counter = 0; var tagsArray = zipkinSpan.Tags.Value.ToArray(); - foreach (var tags in activity.Tags) + foreach (var tags in activity.TagObjects) { Assert.Equal(tagsArray[counter].Key, tags.Key); Assert.Equal(tagsArray[counter++].Value, tags.Value); diff --git a/test/OpenTelemetry.Exporter.Zipkin.Tests/Implementation/ZipkinActivityExporterRemoteEndpointTests.cs b/test/OpenTelemetry.Exporter.Zipkin.Tests/Implementation/ZipkinActivityExporterRemoteEndpointTests.cs index 973eb15aa0..d25e7de27f 100644 --- a/test/OpenTelemetry.Exporter.Zipkin.Tests/Implementation/ZipkinActivityExporterRemoteEndpointTests.cs +++ b/test/OpenTelemetry.Exporter.Zipkin.Tests/Implementation/ZipkinActivityExporterRemoteEndpointTests.cs @@ -26,7 +26,7 @@ public class ZipkinActivityExporterRemoteEndpointTests private static readonly ZipkinEndpoint DefaultZipkinEndpoint = new ZipkinEndpoint("TestService"); [Fact] - public void ZipkinSpanConverterTest_GenerateActivity_RemoteEndpointOmittedByDefault() + public void GenerateActivity_RemoteEndpointOmittedByDefault() { // Arrange var activity = ZipkinExporterTests.CreateTestActivity(); @@ -34,11 +34,11 @@ public void ZipkinSpanConverterTest_GenerateActivity_RemoteEndpointOmittedByDefa // Act & Assert var zipkinSpan = ZipkinActivityConversionExtensions.ToZipkinSpan(activity, DefaultZipkinEndpoint); - Assert.Null(zipkinSpan.RemoteEndpoint); + Assert.NotNull(zipkinSpan.RemoteEndpoint); } [Fact] - public void ZipkinSpanConverterTest_GenerateActivity_RemoteEndpointResolution() + public void GenerateActivity_RemoteEndpointResolution() { // Arrange var activity = ZipkinExporterTests.CreateTestActivity( @@ -56,7 +56,7 @@ public void ZipkinSpanConverterTest_GenerateActivity_RemoteEndpointResolution() [Theory] [MemberData(nameof(RemoteEndpointPriorityTestCase.GetTestCases), MemberType = typeof(RemoteEndpointPriorityTestCase))] - public void ZipkinSpanConverterTest_GenerateActivity_RemoteEndpointResolutionPriority(RemoteEndpointPriorityTestCase testCase) + public void GenerateActivity_RemoteEndpointResolutionPriority(RemoteEndpointPriorityTestCase testCase) { // Arrange var activity = ZipkinExporterTests.CreateTestActivity(additionalAttributes: testCase.RemoteEndpointAttributes); diff --git a/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs b/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs index 665d2b54dc..bdd2d97c2f 100644 --- a/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs @@ -84,14 +84,14 @@ public void Dispose() } [Fact] - public void ZipkinExporter_BadArgs() + public void BadArgs() { TracerProviderBuilder builder = null; Assert.Throws(() => builder.AddZipkinExporter()); } [Fact] - public void ZipkinExporter_SuppresssesInstrumentation() + public void SuppresssesInstrumentation() { const string ActivitySourceName = "zipkin.test"; Guid requestId = Guid.NewGuid(); @@ -135,7 +135,7 @@ public void ZipkinExporter_SuppresssesInstrumentation() [Theory] [InlineData(true)] [InlineData(false)] - public void ZipkinExporterIntegrationTest(bool useShortTraceIds) + public void IntegrationTest(bool useShortTraceIds) { Guid requestId = Guid.NewGuid(); @@ -170,7 +170,7 @@ public void ZipkinExporterIntegrationTest(bool useShortTraceIds) var traceId = useShortTraceIds ? TraceId.Substring(TraceId.Length - 16, 16) : TraceId; Assert.Equal( - $@"[{{""traceId"":""{traceId}"",""name"":""Name"",""parentId"":""{ZipkinActivityConversionExtensions.EncodeSpanId(activity.ParentSpanId)}"",""id"":""{ZipkinActivityConversionExtensions.EncodeSpanId(context.SpanId)}"",""kind"":""CLIENT"",""timestamp"":{timestamp},""duration"":60000000,""localEndpoint"":{{""serviceName"":""OpenTelemetry Exporter""{ipInformation}}},""annotations"":[{{""timestamp"":{eventTimestamp},""value"":""Event1""}},{{""timestamp"":{eventTimestamp},""value"":""Event2""}}],""tags"":{{""stringKey"":""value"",""longKey"":""1"",""longKey2"":""1"",""doubleKey"":""1"",""doubleKey2"":""1"",""longArrayKey"":""1,2"",""boolKey"":""True"",""library.name"":""CreateTestActivity""}}}}]", + $@"[{{""traceId"":""{traceId}"",""name"":""Name"",""parentId"":""{ZipkinActivityConversionExtensions.EncodeSpanId(activity.ParentSpanId)}"",""id"":""{ZipkinActivityConversionExtensions.EncodeSpanId(context.SpanId)}"",""kind"":""CLIENT"",""timestamp"":{timestamp},""duration"":60000000,""localEndpoint"":{{""serviceName"":""OpenTelemetry Exporter""{ipInformation}}},""remoteEndpoint"":{{""serviceName"":""http://localhost:44312/""}},""annotations"":[{{""timestamp"":{eventTimestamp},""value"":""Event1""}},{{""timestamp"":{eventTimestamp},""value"":""Event2""}}],""tags"":{{""stringKey"":""value"",""longKey"":""1"",""longKey2"":""1"",""doubleKey"":""1"",""doubleKey2"":""1"",""longArrayKey"":""1,2"",""boolKey"":""True"",""http.host"":""http://localhost:44312/"",""library.name"":""CreateTestActivity""}}}}]", Responses[requestId]); } @@ -198,12 +198,16 @@ internal static Activity CreateTestActivity( { "doubleKey2", 1F }, { "longArrayKey", new long[] { 1, 2 } }, { "boolKey", true }, + { "http.host", "http://localhost:44312/" }, // simulating instrumentation tag adding http.host }; if (additionalAttributes != null) { foreach (var attribute in additionalAttributes) { - attributes.Add(attribute.Key, attribute.Value); + if (!attributes.ContainsKey(attribute.Key)) + { + attributes.Add(attribute.Key, attribute.Value); + } } }