Ejemplo n.º 1
0
        public void Trace_MultipleSpans()
        {
            string rootSpanName = CreateRootSpanName(nameof(Trace_MultipleSpans));
            var    consumer     = CreateGrpcTraceConsumer();
            var    tracer       = CreateSimpleManagedTracer(consumer);

            var annotation = new Dictionary <string, string>
            {
                { "annotation-key", "annotation-value" }
            };

            tracer.StartSpan(rootSpanName);
            BlockUntilClockTick();
            tracer.StartSpan("child-one");
            tracer.SetStackTrace(new StackTrace(CreateException(), true));
            BlockUntilClockTick();
            tracer.EndSpan();
            tracer.StartSpan("child-two");
            BlockUntilClockTick();
            tracer.StartSpan("grandchild-one", StartSpanOptions.Create(SpanKind.RpcClient));
            BlockUntilClockTick();
            tracer.EndSpan();
            tracer.StartSpan("grandchild-two");
            BlockUntilClockTick();
            tracer.AnnotateSpan(annotation);
            tracer.EndSpan();
            tracer.EndSpan();
            tracer.EndSpan();

            TraceProto trace = _polling.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);
            var labels = childOne.Labels;

            Assert.True(labels.ContainsKey(TraceLabels.StackTrace));
            Assert.Contains(nameof(CreateException), labels[TraceLabels.StackTrace]);
            Assert.Contains(nameof(SimpleManagedTracerTest), labels[TraceLabels.StackTrace]);

            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);
            Assert.True(TraceUtils.IsValidAnnotation(grandchildTwo, annotation));
        }
Ejemplo n.º 2
0
        public void Trace_SimpleAnnotation()
        {
            string rootSpanName = CreateRootSpanName(nameof(Trace_SimpleAnnotation));
            var    consumer     = CreateGrpcTraceConsumer();
            var    tracer       = CreateSimpleManagedTracer(consumer);

            var annotation = new Dictionary <string, string>
            {
                { "annotation-key", "annotation-value" },
                { "some-key", "some-value" }
            };

            tracer.StartSpan(rootSpanName);
            BlockUntilClockTick();
            tracer.AnnotateSpan(annotation);
            tracer.EndSpan();

            TraceProto trace = _polling.GetTrace(rootSpanName, _startTime);

            Assert.NotNull(trace);
            Assert.Single(trace.Spans);
            Assert.True(TraceUtils.IsValidAnnotation(trace.Spans[0], annotation));
        }