Exemplo n.º 1
0
        /// <summary>
        /// End a tracing segment. If all operations of the segments are finished, the segment will be emitted.
        /// </summary>
        /// <exception cref="EntityNotAvailableException">Entity is not available in trace context.</exception>
        public override void EndSegment()
        {
            try
            {
                // If the request is not sampled, a segment will still be available in TraceContext.
                // Need to clean up the segment, but do not emit it.
                Segment segment = (Segment)TraceContext.GetEntity();

                if (!IsTracingDisabled())
                {
                    segment.SetEndTimeToNow(); //sets end time to current time
                    ProcessEndSegment(segment);
                }

                TraceContext.ClearEntity();
            }
            catch (EntityNotAvailableException e)
            {
                HandleEntityNotAvailableException(e, "Failed to end segment because cannot get the segment from trace context.");
            }
            catch (InvalidCastException e)
            {
                HandleEntityNotAvailableException(new EntityNotAvailableException("Failed to cast the entity to Segment.", e), "Failed to cast the entity to Segment.");
            }
        }
Exemplo n.º 2
0
        public void TestSubsegmentStreamingParentSubsegmentDoNotGetRemoved()
        {
            _recorder.BeginSegment(GetType().Name, TraceId);
            var segment = (Segment)TraceContext.GetEntity();

            _recorder.BeginSubsegment("parent");
            for (int i = 0; i < 98; i++)
            {
                _recorder.BeginSubsegment("job" + i);
                _recorder.EndSubsegment();
            }

            _recorder.BeginSubsegment("last job");
            var lastJob = (Subsegment)TraceContext.GetEntity();

            // End parent subsegment, and trigger subsegment stream
            TraceContext.SetEntity(lastJob.Parent);
            _recorder.EndSubsegment();

            Assert.AreEqual(2, segment.Size);
            Assert.AreEqual(1, segment.Subsegments.Count);
            Assert.AreEqual(1, segment.Subsegments[0].Subsegments.Count);

            TraceContext.ClearEntity();
        }
Exemplo n.º 3
0
 public void TestCleanup()
 {
     TraceContext.ClearEntity();
 }