Exemple #1
0
        public void TestMultipleSubsegments()
        {
            var traceId = TraceId.NewId();

            Recorder.BeginSegment(GetType().Name, traceId);

            for (int i = 0; i < 3; i++)
            {
                Recorder.BeginSubsegment("downstream" + i);
                Recorder.EndSubsegment();
            }

            Dictionary <string, string> subsegmentNames = new Dictionary <string, string>();

            TraceContext.GetEntity().Subsegments.ForEach(x => subsegmentNames[x.Id] = x.Name);

            Recorder.EndSegment();
#if NET45
            var response = BatchGetTraces(traceId);
#else
            var response = BatchGetTracesAsync(traceId).Result;
#endif
            Assert.IsTrue(response.Traces.Count > 0);

            var segmentJsonData = JsonMapper.ToObject(response.Traces[0].Segments[0].Document);

            var subsegments = segmentJsonData["subsegments"];
            Assert.IsNotNull(subsegments);
            Assert.AreEqual(3, subsegments.Count);

            for (int i = 0; i < 3; i++)
            {
                Assert.AreEqual((string)subsegments[i]["name"], (string)subsegmentNames[(string)subsegments[i]["id"]]);
                subsegmentNames.Remove((string)subsegments[i]["id"]);
            }

            Assert.AreEqual(0, subsegmentNames.Count);
        }
Exemple #2
0
        public void TestMinimalSegment()
        {
            var traceId = TraceId.NewId();

            Recorder.BeginSegment(GetType().Name, traceId);
            var segment = TraceContext.GetEntity();

            Thread.Sleep(100);
            Recorder.EndSegment();
#if NET45
            var response = BatchGetTraces(traceId);
#else
            var response = BatchGetTracesAsync(traceId).Result;
#endif
            Assert.IsTrue(response.Traces.Count > 0);

            var segmentJsonData = JsonMapper.ToObject(response.Traces[0].Segments[0].Document);
            Assert.AreEqual(traceId, (string)segmentJsonData["trace_id"]);
            Assert.AreEqual(segment.Id, (string)segmentJsonData["id"]);
            Assert.AreEqual(segment.Name, (string)segmentJsonData["name"]);
            Assert.AreEqual(segment.StartTime.ToString("F5"), ((double)segmentJsonData["start_time"]).ToString("F5"));
            Assert.AreEqual(segment.EndTime.ToString("F5"), ((double)segmentJsonData["end_time"]).ToString("F5"));
        }