Beispiel #1
0
        private static void CompareSpans(MockSpan receivedSpan, OpenTracingSpan openTracingSpan)
        {
            var span = (Span)openTracingSpan.Span;

            receivedSpan.Should().BeEquivalentTo(new
            {
                TraceId  = span.TraceId,
                SpanId   = span.SpanId,
                Name     = span.OperationName,
                Resource = span.ResourceName,
                Service  = span.ServiceName,
                Type     = span.Type,
                Tags     = span.Tags,
            });
        }
        public void ScopeManager_ActivatesWithoutFinishOnDispose()
        {
            var ddScopeManager = ((IDatadogTracer)_datadogTracer).ScopeManager;
            OpenTracingScopeManager otScopeManager = new OpenTracingScopeManager(ddScopeManager);

            var tracer = new OpenTracingTracer(_datadogTracer, otScopeManager);

            OpenTracingSpan otParentSpan = null;
            OpenTracingSpan otChildSpan  = null;
            Span            parentSpan   = null;
            Span            childSpan    = null;

            using (IScope parentScope = tracer.BuildSpan("parent").StartActive(finishSpanOnDispose: false))
            {
                otParentSpan = (OpenTracingSpan)parentScope.Span;
                parentSpan   = otParentSpan.Span;

                using (IScope childScope = tracer.BuildSpan("child").StartActive(finishSpanOnDispose: false))
                {
                    otChildSpan = (OpenTracingSpan)childScope.Span;
                    childSpan   = otChildSpan.Span;

                    Assert.True(childSpan.Context.ParentId == parentSpan.SpanId);

                    Assert.False(childSpan.IsFinished);
                }

                Assert.False(childSpan.IsFinished);
                Assert.False(parentSpan.IsFinished);
            }

            Assert.False(parentSpan.IsFinished);

            otChildSpan.Finish();
            otParentSpan.Finish();

            Assert.True(childSpan.IsFinished);
            Assert.True(parentSpan.IsFinished);
        }