コード例 #1
0
        private static List <GrpcLog> BuildLogs(IEnumerable <LogData> logs)
        {
            List <GrpcLog> grpcLogs = new List <GrpcLog>();

            if (logs != null)
            {
                foreach (LogData logData in logs)
                {
                    GrpcLog grpcLog = new GrpcLog
                    {
                        Timestamp = Timestamp.FromDateTime(logData.TimestampUtc)
                    };

                    if (logData.Fields != null)
                    {
                        grpcLog.Fields.AddRange(BuildTags(logData.Fields));
                    }
                    else if (logData.Message != null)
                    {
                        grpcLog.Fields.Add(BuildTag(LogFields.Event, logData.Message));
                    }

                    grpcLogs.Add(grpcLog);
                }
            }
            return(grpcLogs);
        }
コード例 #2
0
        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);
        }