Skip to content

Commit

Permalink
Zipking will export all strings (#1197)
Browse files Browse the repository at this point in the history
* Zipking will export all strings

* updating tests

* renaming tests, solving incorrect tests

* net.peer.port will be exported as well
  • Loading branch information
eddynaka authored Aug 28, 2020
1 parent a09e1f8 commit 465fc09
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,16 @@ internal static bool ProcessTags(ref AttributeEnumerationState state, KeyValuePa
{
state.ServiceNamespace = strVal;
}
else
{
PooledList<KeyValuePair<string, object>>.Add(ref state.Tags, new KeyValuePair<string, object>(key, strVal));
}
}
else if (attribute.Value is int intVal && attribute.Key == SemanticConventions.AttributeNetPeerPort)
{
state.Port = intVal;

PooledList<KeyValuePair<string, object>>.Add(ref state.Tags, new KeyValuePair<string, object>(key, strVal));
}
else
{
if (attribute.Value is int intVal && attribute.Key == SemanticConventions.AttributeNetPeerPort)
{
state.Port = intVal;
}

PooledList<KeyValuePair<string, object>>.Add(ref state.Tags, attribute);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ 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();

// 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(
Expand All @@ -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);
Expand Down
14 changes: 9 additions & 5 deletions test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ public void Dispose()
}

[Fact]
public void ZipkinExporter_BadArgs()
public void BadArgs()
{
TracerProviderBuilder builder = null;
Assert.Throws<ArgumentNullException>(() => builder.AddZipkinExporter());
}

[Fact]
public void ZipkinExporter_SuppresssesInstrumentation()
public void SuppresssesInstrumentation()
{
const string ActivitySourceName = "zipkin.test";
Guid requestId = Guid.NewGuid();
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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]);
}

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

Expand Down

0 comments on commit 465fc09

Please sign in to comment.