From 4d29d27c9f28f5b8940813cc668b1df2a965cf75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Kr=C3=A4mer?= Date: Thu, 25 Feb 2021 17:23:27 +0100 Subject: [PATCH] Fix gRPC sender's parent span reference (#203) * Fix gRPC sender's parent span reference Signed-off-by: Kraemer, Benjamin * Fix unit test Signed-off-by: Kraemer, Benjamin --- .../Protocols/JaegerGrpcSpanConverter.cs | 3 +-- .../Protocols/JaegerGrpcSpanConverterTests.cs | 13 ++++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Senders/Jaeger.Senders.Grpc/Protocols/JaegerGrpcSpanConverter.cs b/src/Senders/Jaeger.Senders.Grpc/Protocols/JaegerGrpcSpanConverter.cs index 7766cd73f..052226fe0 100644 --- a/src/Senders/Jaeger.Senders.Grpc/Protocols/JaegerGrpcSpanConverter.cs +++ b/src/Senders/Jaeger.Senders.Grpc/Protocols/JaegerGrpcSpanConverter.cs @@ -22,7 +22,6 @@ public static GrpcSpan ConvertSpan(Span span) var duration = (span.FinishTimestampUtc ?? startTime) - startTime; var references = span.GetReferences(); - var oneChildOfParent = references.Count == 1 && string.Equals(References.ChildOf, references[0].Type, StringComparison.Ordinal); var grpcSpan = new GrpcSpan { @@ -32,7 +31,7 @@ public static GrpcSpan ConvertSpan(Span span) Flags = (uint)context.Flags, StartTime = Timestamp.FromDateTime(startTime), Duration = Duration.FromTimeSpan(duration), - References = { oneChildOfParent ? new List() : BuildReferences(references) }, + References = { BuildReferences(references) }, Tags = { BuildTags(span.GetTags()) }, Logs = { BuildLogs(span.GetLogs()) } }; diff --git a/test/Senders/Jaeger.Senders.Grpc.Tests/Reporters/Protocols/JaegerGrpcSpanConverterTests.cs b/test/Senders/Jaeger.Senders.Grpc.Tests/Reporters/Protocols/JaegerGrpcSpanConverterTests.cs index ec7cfcd5d..8c16f8f24 100644 --- a/test/Senders/Jaeger.Senders.Grpc.Tests/Reporters/Protocols/JaegerGrpcSpanConverterTests.cs +++ b/test/Senders/Jaeger.Senders.Grpc.Tests/Reporters/Protocols/JaegerGrpcSpanConverterTests.cs @@ -1,8 +1,12 @@ using System; using System.Collections.Generic; +using System.Linq; +using Google.Protobuf; +using Jaeger.ApiV2; using Jaeger.Reporters; using Jaeger.Samplers; using Jaeger.Senders.Grpc.Protocols; +using Jaeger.Util; using OpenTracing; using Xunit; using GrpcSpan = Jaeger.ApiV2.Span; @@ -125,9 +129,8 @@ public void TestConvertSpanOneReferenceChildOf() GrpcSpan span = JaegerGrpcSpanConverter.ConvertSpan(child); - // TODO: Check ParentSpanID - //Assert.Equal((long)child.Context.ParentId, span.ParentSpanId); - Assert.Empty(span.References); + Assert.Single(span.References); + Assert.Equal(BuildReference(parent.Context, References.ChildOf), span.References[0]); } [Fact] @@ -143,8 +146,6 @@ public void TestConvertSpanTwoReferencesChildOf() GrpcSpan span = JaegerGrpcSpanConverter.ConvertSpan(child); - // TODO: Check ParentSpanID - //Assert.Equal(0, span.ParentSpanId); Assert.Equal(2, span.References.Count); Assert.Equal(BuildReference(parent.Context, References.ChildOf), span.References[0]); Assert.Equal(BuildReference(parent2.Context, References.ChildOf), span.References[1]); @@ -163,8 +164,6 @@ public void TestConvertSpanMixedReferences() GrpcSpan span = JaegerGrpcSpanConverter.ConvertSpan(child); - // TODO: Check ParentSpanID - //Assert.Equal(0, span.ParentSpanId); Assert.Equal(2, span.References.Count); Assert.Equal(BuildReference(parent.Context, References.FollowsFrom), span.References[0]); Assert.Equal(BuildReference(parent2.Context, References.ChildOf), span.References[1]);