예제 #1
0
        public void StartRemoteSpan_NullParent()
        {
            ISpan span =
                SpanBuilder.CreateWithRemoteParent(SPAN_NAME, null, spanBuilderOptions).StartSpan();

            Assert.True(span.Context.IsValid);
            Assert.True(span.Options.HasFlag(SpanOptions.RECORD_EVENTS));
            Assert.True(span.Context.TraceOptions.IsSampled);
            ISpanData spanData = ((Span)span).ToSpanData();

            Assert.Null(spanData.ParentSpanId);
            Assert.False(spanData.HasRemoteParent);
        }
        public void StartRemoteSpanInvalidParent()
        {
            ISpan span =
                SpanBuilder.CreateWithRemoteParent(SPAN_NAME, SpanKind.Internal, SpanContext.Blank, spanBuilderOptions)
                .StartSpan();

            Assert.True(span.Context.IsValid);
            Assert.True(span.Options.HasFlag(SpanOptions.RecordEvents));
            Assert.True(span.Context.TraceOptions.IsSampled);
            ISpanData spanData = ((Span)span).ToSpanData();

            Assert.Null(spanData.ParentSpanId);
            Assert.False(spanData.HasRemoteParent);
        }
예제 #3
0
        public void StartRemoteChildSpan_WithoutSpecifiedSampler()
        {
            ISpan rootSpan =
                SpanBuilder.CreateWithParent(SPAN_NAME, null, spanBuilderOptions)
                .SetSampler(Samplers.NeverSample)
                .StartSpan();

            Assert.True(rootSpan.Context.IsValid);
            Assert.False(rootSpan.Context.TraceOptions.IsSampled);
            // Apply default sampler (always true in the tests) for spans with remote parent.
            ISpan childSpan =
                SpanBuilder.CreateWithRemoteParent(SPAN_NAME, rootSpan.Context, spanBuilderOptions)
                .StartSpan();

            Assert.True(childSpan.Context.IsValid);
            Assert.Equal(rootSpan.Context.TraceId, childSpan.Context.TraceId);
            Assert.True(childSpan.Context.TraceOptions.IsSampled);
        }
예제 #4
0
        public void StartRemoteSpan()
        {
            ISpanContext spanContext =
                SpanContext.Create(
                    TraceId.GenerateRandomId(randomHandler),
                    SpanId.GenerateRandomId(randomHandler),
                    TraceOptions.DEFAULT);
            ISpan span =
                SpanBuilder.CreateWithRemoteParent(SPAN_NAME, spanContext, spanBuilderOptions)
                .StartSpan();

            Assert.True(span.Context.IsValid);
            Assert.Equal(spanContext.TraceId, span.Context.TraceId);
            Assert.True(span.Context.TraceOptions.IsSampled);
            ISpanData spanData = ((Span)span).ToSpanData();

            Assert.Equal(spanContext.SpanId, spanData.ParentSpanId);
            Assert.True(spanData.HasRemoteParent);
        }
        public void StartRemoteChildSpan_WithSpecifiedSampler()
        {
            ISpan rootSpan =
                SpanBuilder.CreateWithParent(SPAN_NAME, SpanKind.Internal, null, spanBuilderOptions)
                .SetSampler(Samplers.AlwaysSample)
                .StartSpan();

            Assert.True(rootSpan.Context.IsValid);
            Assert.True(rootSpan.Context.TraceOptions.IsSampled);
            // Apply given sampler before default sampler for spans with remote parent.
            ISpan childSpan =
                SpanBuilder.CreateWithRemoteParent(SPAN_NAME, SpanKind.Internal, rootSpan.Context, spanBuilderOptions)
                .SetSampler(Samplers.NeverSample)
                .StartSpan();

            Assert.True(childSpan.Context.IsValid);
            Assert.Equal(rootSpan.Context.TraceId, childSpan.Context.TraceId);
            Assert.False(childSpan.Context.TraceOptions.IsSampled);
        }
예제 #6
0
        public void StartRemoteChildSpan_WithProbabilitySamplerDefaultSampler()
        {
            var configMock = Mock.Get <ITraceConfig>(traceConfig);

            configMock.Setup((c) => c.ActiveTraceParams).Returns(TraceParams.DEFAULT);

            // This traceId will not be sampled by the ProbabilitySampler because the first 8 bytes as long
            // is not less than probability * Long.MAX_VALUE;
            ITraceId traceId =
                TraceId.FromBytes(
                    new byte[]
            {
                (byte)0x8F,
                (byte)0xFF,
                (byte)0xFF,
                (byte)0xFF,
                (byte)0xFF,
                (byte)0xFF,
                (byte)0xFF,
                (byte)0xFF,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0
            });

            // If parent is sampled then the remote child must be sampled.
            ISpan childSpan =
                SpanBuilder.CreateWithRemoteParent(
                    SPAN_NAME,
                    SpanContext.Create(
                        traceId,
                        SpanId.GenerateRandomId(randomHandler),
                        TraceOptions.Builder().SetIsSampled(true).Build()),
                    spanBuilderOptions)
                .StartSpan();

            Assert.True(childSpan.Context.IsValid);
            Assert.Equal(traceId, childSpan.Context.TraceId);
            Assert.True(childSpan.Context.TraceOptions.IsSampled);
            childSpan.End();

            Assert.Equal(TraceParams.DEFAULT, traceConfig.ActiveTraceParams);

            // If parent is not sampled then the remote child must be not sampled.
            childSpan =
                SpanBuilder.CreateWithRemoteParent(
                    SPAN_NAME,
                    SpanContext.Create(
                        traceId,
                        SpanId.GenerateRandomId(randomHandler),
                        TraceOptions.DEFAULT),
                    spanBuilderOptions)
                .StartSpan();
            Assert.True(childSpan.Context.IsValid);
            Assert.Equal(traceId, childSpan.Context.TraceId);
            Assert.False(childSpan.Context.TraceOptions.IsSampled);
            childSpan.End();
        }