public void ShouldSampleRespectsSamplerChoice()
        {
            var m = new Mock <ISampler>();

            m.Setup(x => x.ShouldSample(It.IsAny <ISpanContext>(), It.IsAny <bool>(), It.IsAny <ITraceId>(), It.IsAny <ISpanId>(), It.IsAny <string>(), It.IsAny <IEnumerable <ISpan> >())).Returns(true);
            Assert.True(RedisProfilerEntryToSpanConverter.ShouldSample(SpanContext.Blank, "SET", m.Object, out var context, out var parentId));

            m = new Mock <ISampler>();
            m.Setup(x => x.ShouldSample(It.IsAny <ISpanContext>(), It.IsAny <bool>(), It.IsAny <ITraceId>(), It.IsAny <ISpanId>(), It.IsAny <string>(), It.IsAny <IEnumerable <ISpan> >())).Returns(false);
            Assert.False(RedisProfilerEntryToSpanConverter.ShouldSample(SpanContext.Blank, "SET", m.Object, out context, out parentId));
        }
        public void ShouldSamplePassesArgumentsToSamplerAndReturnsInContext()
        {
            var m             = new Mock <ISampler>();
            var traceId       = ActivityTraceId.CreateRandom();
            var parentContext = SpanContext.Create(traceId, ActivitySpanId.CreateRandom(), ActivityTraceFlags.Recorded, Tracestate.Builder.Set("a", "b").Build());

            RedisProfilerEntryToSpanConverter.ShouldSample(parentContext, "SET", m.Object, out var context, out var parentId);

            m.Verify(x => x.ShouldSample(
                         It.Is <SpanContext>(y => y == parentContext),
                         It.Is <ActivityTraceId>(y => y == traceId && y == context.TraceId),
                         It.Is <ActivitySpanId>(y => y != default && y == context.SpanId),
                         It.Is <string>(y => y == "SET"),
                         It.Is <IEnumerable <ILink> >(y => y == null)));
        }
Exemplo n.º 3
0
        public void ShouldSamplePassesArgumentsToSamplerAndReturnsInContext()
        {
            var m             = new Mock <ISampler>();
            var r             = new RandomGenerator();
            var traceId       = TraceId.GenerateRandomId(r);
            var parentContext = SpanContext.Create(traceId, SpanId.GenerateRandomId(r), TraceOptions.Sampled, Tracestate.Builder.Set("a", "b").Build());

            RedisProfilerEntryToSpanConverter.ShouldSample(parentContext, "SET", m.Object, out var context, out var parentId);

            m.Verify(x => x.ShouldSample(
                         It.Is <SpanContext>(y => y == parentContext),
                         It.Is <TraceId>(y => y == traceId && y == context.TraceId),
                         It.Is <SpanId>(y => y.IsValid && y == context.SpanId),
                         It.Is <string>(y => y == "SET"),
                         It.Is <IEnumerable <ISpan> >(y => y == null)));
        }
        public void ShouldSampleGeneratesNewTraceIdForInvalidContext()
        {
            var m = new Mock <ISampler>();

            m.Setup(x => x.ShouldSample(It.IsAny <ISpanContext>(), It.IsAny <bool>(), It.IsAny <ITraceId>(), It.IsAny <ISpanId>(), It.IsAny <string>(), It.IsAny <IEnumerable <ISpan> >())).Returns((ISpanContext parentContext, bool hasRemoteParent, ITraceId traceId, ISpanId spanId, string name, IEnumerable <ISpan> parentLinks) => parentContext.TraceOptions.IsSampled);

            RedisProfilerEntryToSpanConverter.ShouldSample(SpanContext.Blank, "SET", m.Object, out var context, out var parentId);

            m.Verify(x => x.ShouldSample(
                         It.Is <ISpanContext>(y => y == SpanContext.Blank),
                         It.Is <bool>(y => y == false),
                         It.Is <ITraceId>(y => y.IsValid && y == context.TraceId),
                         It.Is <ISpanId>(y => y.IsValid && y == context.SpanId),
                         It.Is <string>(y => y == "SET"),
                         It.Is <IEnumerable <ISpan> >(y => y == null)));

            Assert.Equal(TraceOptions.Default, context.TraceOptions);
        }
        public void ShouldSampleGeneratesNewTraceIdForInvalidContext()
        {
            var m = new Mock <ISampler>();

            m.Setup(x => x.ShouldSample(
                        It.IsAny <SpanContext>(),
                        It.IsAny <ActivityTraceId>(),
                        It.IsAny <ActivitySpanId>(),
                        It.IsAny <string>(),
                        It.IsAny <IEnumerable <ILink> >())).Returns((SpanContext parentContext, ActivityTraceId traceId, ActivitySpanId spanId, string name, IEnumerable <ISpan> parentLinks) => (parentContext.TraceOptions & ActivityTraceFlags.Recorded) != 0);

            RedisProfilerEntryToSpanConverter.ShouldSample(SpanContext.Blank, "SET", m.Object, out var context, out var parentId);

            m.Verify(x => x.ShouldSample(
                         It.Is <SpanContext>(y => y == SpanContext.Blank),
                         It.Is <ActivityTraceId>(y => y != default && y == context.TraceId),
                         It.Is <ActivitySpanId>(y => y != default && y == context.SpanId),
                         It.Is <string>(y => y == "SET"),
                         It.Is <IEnumerable <ILink> >(y => y == null)));

            Assert.Equal(ActivityTraceFlags.None, context.TraceOptions);
        }
Exemplo n.º 6
0
 public void ShouldSampleDoesntThrowWithoutSampler()
 {
     RedisProfilerEntryToSpanConverter.ShouldSample(SpanContext.Blank, "SET", null, out var context, out var parentId);
 }