static Lwaay.Tracing.Model.SpanTag ConvertKeyValue(Jaeger.ApiV2.KeyValue key) { Lwaay.Tracing.Model.SpanTag spanTag = new Model.SpanTag(); spanTag.Key = key.Key; spanTag.Type = key.VType.ToString().ToLower(); switch (key.VType) { case Jaeger.ApiV2.ValueType.String: spanTag.Value = key.VStr; break; case Jaeger.ApiV2.ValueType.Bool: spanTag.Value = key.VBool; break; case Jaeger.ApiV2.ValueType.Int64: spanTag.Value = key.VInt64; break; case Jaeger.ApiV2.ValueType.Float64: spanTag.Value = key.VFloat64; break; case Jaeger.ApiV2.ValueType.Binary: spanTag.Value = ByteStringToString(key.VBinary); break; default: break; } return(spanTag); }
public void TestBuildTag(object tagValue, GrpcTagType tagType, object expected) { GrpcTag tag = JaegerGrpcSpanConverter.BuildTag("key", tagValue); Assert.Equal(tagType, tag.VType); Assert.Equal("key", tag.Key); switch (tagType) { case GrpcTagType.Bool: Assert.Equal(expected, tag.VBool); break; case GrpcTagType.Int64: Assert.Equal(expected, tag.VInt64); break; case GrpcTagType.Float64: Assert.Equal(expected, tag.VFloat64); break; case GrpcTagType.Binary: break; case GrpcTagType.String: default: Assert.Equal(expected, tag.VStr); break; } }
static Jaeger.ApiV2.KeyValue ConvertSpanTag(Lwaay.Tracing.Model.SpanTag spanTag) { var kv = new Jaeger.ApiV2.KeyValue() { Key = spanTag.Key, }; switch (spanTag.Type) { case "bool": kv.VBool = Convert.ToBoolean(spanTag.Value); kv.VType = Jaeger.ApiV2.ValueType.Bool; break; case "String": kv.VStr = spanTag.Value.ToString(); kv.VType = Jaeger.ApiV2.ValueType.String; break; case "int64": kv.VInt64 = Convert.ToInt64(spanTag.Value); kv.VType = Jaeger.ApiV2.ValueType.Int64; break; case "float64": kv.VFloat64 = Convert.ToDouble(spanTag.Value); kv.VType = Jaeger.ApiV2.ValueType.Float64; break; case "binary": kv.VBinary = ByteString.CopyFrom(Encoding.Unicode.GetBytes(spanTag.Value.ToString())); kv.VType = Jaeger.ApiV2.ValueType.Binary; break; default: break; } return(kv); }
public void TestConvertSpan() { var logTimestamp = new DateTimeOffset(2018, 4, 13, 10, 30, 0, TimeSpan.Zero); var fields = new Dictionary <string, object> { { "k", "v" } }; Span span = (Span)_tracer.BuildSpan("operation-name").Start(); span.Log(logTimestamp, fields); span.SetBaggageItem("foo", "bar"); GrpcSpan grpcSpan = JaegerGrpcSpanConverter.ConvertSpan(span); Assert.Equal("operation-name", grpcSpan.OperationName); Assert.Equal(2, grpcSpan.Logs.Count); GrpcLog grpcLog = grpcSpan.Logs[0]; Assert.Equal(logTimestamp, grpcLog.Timestamp.ToDateTimeOffset()); Assert.Single(grpcLog.Fields); GrpcTag grpcTag = grpcLog.Fields[0]; Assert.Equal("k", grpcTag.Key); Assert.Equal("v", grpcTag.VStr); // NOTE: In Java, the order is different (event, value, key) because the HashMap algorithm is different. grpcLog = grpcSpan.Logs[1]; Assert.Equal(3, grpcLog.Fields.Count); grpcTag = grpcLog.Fields[0]; Assert.Equal("event", grpcTag.Key); Assert.Equal("baggage", grpcTag.VStr); grpcTag = grpcLog.Fields[1]; Assert.Equal("key", grpcTag.Key); Assert.Equal("foo", grpcTag.VStr); grpcTag = grpcLog.Fields[2]; Assert.Equal("value", grpcTag.Key); Assert.Equal("bar", grpcTag.VStr); }