コード例 #1
0
        public void Trace_MultipleSpans()
        {
            string rootSpanName = EntryData.GetMessage(nameof(Trace_MultipleSpans), _testId);
            var    labels       = new Dictionary <string, string>
            {
                { "annotation-key", "annotation-value" }
            };

            var tracer = CreateSimpleManagedTracer(_grpcConsumer);

            using (tracer.StartSpan(rootSpanName))
            {
                BlockUntilClockTick();
                using (tracer.StartSpan("child-one"))
                {
                    tracer.SetStackTrace(TraceEntryData.CreateStackTrace());
                    BlockUntilClockTick();
                }
                using (tracer.StartSpan("child-two"))
                {
                    BlockUntilClockTick();
                    using (tracer.StartSpan("grandchild-one", StartSpanOptions.Create(SpanKind.RpcClient)))
                    {
                        BlockUntilClockTick();
                    }
                    using (tracer.StartSpan("grandchild-two"))
                    {
                        BlockUntilClockTick();
                        tracer.AnnotateSpan(labels);
                    }
                }
            }

            TraceProto trace = TraceEntryPolling.Default.GetTrace(rootSpanName, _startTime);

            Assert.NotNull(trace);
            Assert.Equal(5, trace.Spans.Count);

            TraceSpan root          = trace.Spans.First(s => s.Name.Equals(rootSpanName));
            TraceSpan childOne      = trace.Spans.First(s => s.Name.Equals("child-one"));
            TraceSpan childTwo      = trace.Spans.First(s => s.Name.Equals("child-two"));
            TraceSpan grandchildOne = trace.Spans.First(s => s.Name.Equals("grandchild-one"));
            TraceSpan grandchildTwo = trace.Spans.First(s => s.Name.Equals("grandchild-two"));

            Assert.Equal(root.SpanId, childOne.ParentSpanId);
            TraceEntryVerifiers.AssertContainsStackTrace(childOne,
                                                         nameof(TraceEntryData.CreateStackTrace), nameof(SimpleManagedTracerTest));

            Assert.Equal(root.SpanId, childTwo.ParentSpanId);

            Assert.Equal(childTwo.SpanId, grandchildOne.ParentSpanId);
            Assert.Equal(TraceSpan.Types.SpanKind.RpcClient, grandchildOne.Kind);

            Assert.Equal(childTwo.SpanId, grandchildTwo.ParentSpanId);
            Assert.Equal(TraceSpan.Types.SpanKind.Unspecified, grandchildTwo.Kind);
            TraceEntryVerifiers.AssertSpanLabelsExact(grandchildTwo, labels);
        }
コード例 #2
0
        public void Trace_SimpleStacktrace()
        {
            string rootSpanName = EntryData.GetMessage(nameof(Trace_SimpleStacktrace), _testId);

            var tracer = CreateSimpleManagedTracer(_grpcConsumer);

            using (tracer.StartSpan(rootSpanName))
            {
                BlockUntilClockTick();
                tracer.SetStackTrace(TraceEntryData.CreateStackTrace());
            }

            TraceProto trace = TraceEntryPolling.Default.GetTrace(rootSpanName, _startTime);

            TraceEntryVerifiers.AssertSingleSpan(trace, rootSpanName);
            TraceEntryVerifiers.AssertContainsStackTrace(trace.Spans[0],
                                                         nameof(TraceEntryData.CreateStackTrace), nameof(SimpleManagedTracerTest));
        }