private static List <ThriftLog> BuildLogs(IEnumerable <LogData> logs) { List <ThriftLog> thriftLogs = new List <ThriftLog>(); if (logs != null) { foreach (LogData logData in logs) { ThriftLog thriftLog = new ThriftLog(); thriftLog.Timestamp = logData.TimestampUtc.ToUnixTimeMicroseconds(); if (logData.Fields != null) { thriftLog.Fields = BuildTags(logData.Fields); } else { List <ThriftTag> thriftTags = new List <ThriftTag>(); if (logData.Message != null) { thriftTags.Add(BuildTag("event", logData.Message)); } thriftLog.Fields = thriftTags; } thriftLogs.Add(thriftLog); } } return(thriftLogs); }
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"); ThriftSpan thriftSpan = JaegerThriftSpanConverter.ConvertSpan(span); Assert.Equal("operation-name", thriftSpan.OperationName); Assert.Equal(2, thriftSpan.Logs.Count); ThriftLog thriftLog = thriftSpan.Logs[0]; Assert.Equal(logTimestamp.ToUnixTimeMilliseconds() * 1000, thriftLog.Timestamp); Assert.Single(thriftLog.Fields); ThriftTag thriftTag = thriftLog.Fields[0]; Assert.Equal("k", thriftTag.Key); Assert.Equal("v", thriftTag.VStr); // NOTE: In Java, the order is different (event, value, key) because the HashMap algorithm is different. thriftLog = thriftSpan.Logs[1]; Assert.Equal(3, thriftLog.Fields.Count); thriftTag = thriftLog.Fields[0]; Assert.Equal("event", thriftTag.Key); Assert.Equal("baggage", thriftTag.VStr); thriftTag = thriftLog.Fields[1]; Assert.Equal("key", thriftTag.Key); Assert.Equal("foo", thriftTag.VStr); thriftTag = thriftLog.Fields[2]; Assert.Equal("value", thriftTag.Key); Assert.Equal("bar", thriftTag.VStr); }