コード例 #1
0
        public void TestActiveSpanAutoReference()
        {
            InMemoryReporter reporter = new InMemoryReporter();
            Tracer           tracer   = new Tracer.Builder("test")
                                        .WithReporter(reporter)
                                        .WithSampler(new ConstSampler(true))
                                        .Build();

            using (IScope parent = tracer.BuildSpan("parent").StartActive(finishSpanOnDispose: true))
            {
                tracer.BuildSpan("child").StartActive(finishSpanOnDispose: true).Dispose();
            }
            Assert.Equal(2, reporter.GetSpans().Count);

            Span childSpan  = reporter.GetSpans()[0];
            Span parentSpan = reporter.GetSpans()[1];

            Assert.Equal("child", childSpan.OperationName);
            Assert.Single(childSpan.GetReferences());
            Assert.Equal("parent", parentSpan.OperationName);
            Assert.Empty(parentSpan.GetReferences());
            Assert.Equal(References.ChildOf, childSpan.GetReferences()[0].Type);
            Assert.Equal(parentSpan.Context, childSpan.GetReferences()[0].Context);
            Assert.Equal(parentSpan.Context.TraceId, childSpan.Context.TraceId);
            Assert.Equal(parentSpan.Context.SpanId, childSpan.Context.ParentId);
        }
コード例 #2
0
        public void TestNoAutoRefWithExistingRefs()
        {
            InMemoryReporter reporter = new InMemoryReporter();
            Tracer           tracer   = new Tracer.Builder("test")
                                        .WithReporter(reporter)
                                        .WithSampler(new ConstSampler(true))
                                        .Build();

            ISpan initialSpan = tracer.BuildSpan("initial").Start();

            using (IScope parent = tracer.BuildSpan("parent").StartActive(finishSpanOnDispose: true))
            {
                tracer.BuildSpan("child").AsChildOf(initialSpan.Context).StartActive(finishSpanOnDispose: true).Dispose();
            }

            initialSpan.Finish();

            Assert.Equal(3, reporter.GetSpans().Count);

            Span childSpan  = reporter.GetSpans()[0];
            Span parentSpan = reporter.GetSpans()[1];
            Span initSpan   = reporter.GetSpans()[2];

            Assert.Empty(initSpan.GetReferences());
            Assert.Empty(parentSpan.GetReferences());

            Assert.Equal(initSpan.Context.TraceId, childSpan.Context.TraceId);
            Assert.Equal(initSpan.Context.SpanId, childSpan.Context.ParentId);

            Assert.Equal(0L, initSpan.Context.ParentId);
            Assert.Equal(0L, parentSpan.Context.ParentId);
        }
コード例 #3
0
        public void TestActiveSpanNotAutoFinishOnClose()
        {
            InMemoryReporter reporter = new InMemoryReporter();
            Tracer           tracer   = new Tracer.Builder("test")
                                        .WithReporter(reporter)
                                        .WithSampler(new ConstSampler(true))
                                        .Build();

            IScope scope = tracer.BuildSpan("parent").StartActive(finishSpanOnDispose: false);
            Span   span  = (Span)scope.Span;

            scope.Dispose();
            Assert.Empty(reporter.GetSpans());
            span.Finish();
            Assert.Single(reporter.GetSpans());
        }
コード例 #4
0
        public void TestActiveSpanAutoFinishOnClose()
        {
            InMemoryReporter reporter = new InMemoryReporter();
            Tracer           tracer   = new Tracer.Builder("test")
                                        .WithReporter(reporter)
                                        .WithSampler(new ConstSampler(true))
                                        .Build();

            tracer.BuildSpan("parent").StartActive(finishSpanOnDispose: true).Dispose();
            Assert.Single(reporter.GetSpans());
        }
コード例 #5
0
        public void TestIgnoreActiveSpan()
        {
            InMemoryReporter reporter = new InMemoryReporter();
            Tracer           tracer   = new Tracer.Builder("test")
                                        .WithReporter(reporter)
                                        .WithSampler(new ConstSampler(true))
                                        .Build();

            using (IScope parent = tracer.BuildSpan("parent").StartActive(finishSpanOnDispose: true))
            {
                tracer.BuildSpan("child").IgnoreActiveSpan().StartActive(finishSpanOnDispose: true).Dispose();
            }
            Assert.Equal(2, reporter.GetSpans().Count);

            Span childSpan  = reporter.GetSpans()[0];
            Span parentSpan = reporter.GetSpans()[1];

            Assert.Empty(reporter.GetSpans()[0].GetReferences());
            Assert.Empty(reporter.GetSpans()[1].GetReferences());
            Assert.NotEqual(parentSpan.Context.TraceId, childSpan.Context.TraceId);
            Assert.Equal(0L, childSpan.Context.ParentId);
        }
コード例 #6
0
        public void TestWithTimestamp()
        {
            DateTimeOffset start  = new DateTimeOffset(2018, 4, 12, 14, 0, 1, TimeSpan.Zero);
            DateTimeOffset finish = new DateTimeOffset(2018, 4, 12, 14, 0, 3, TimeSpan.Zero);

            clock.UtcNow().Returns(_ => throw new InvalidOperationException("UtcNow() called"));

            Span span = (Span)tracer.BuildSpan("test-service-name").WithStartTimestamp(start).Start();

            span.Finish(finish);

            Assert.Single(reporter.GetSpans());
            Assert.Equal(start.UtcDateTime, span.StartTimestampUtc);
            Assert.Equal(finish.UtcDateTime, span.FinishTimestampUtc);
        }
コード例 #7
0
 public static IEnumerable <Span> GetSpans() => memoryReporter.GetSpans();