Пример #1
0
        public void ProbabilitySampler_SampleBasedOnTraceId()
        {
            ActivitySampler defaultProbability = new ProbabilityActivitySampler(0.0001);

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

            Assert.False(
                defaultProbability.ShouldSample(new ActivitySamplingParameters(
Пример #2
0
        public void ProbabilitySampler_DifferentProbabilities_SampledParentLink()
        {
            var neverSample = new ProbabilityActivitySampler(0.0);

            AssertSamplerSamplesWithProbability(
                neverSample, this.notSampledActivityContext, new List <ActivityLink>()
            {
                this.sampledLink
            }, 1.0);
            var alwaysSample = new ProbabilityActivitySampler(1.0);

            AssertSamplerSamplesWithProbability(
                alwaysSample, this.notSampledActivityContext, new List <ActivityLink>()
            {
                this.sampledLink
            }, 1.0);
            var fiftyPercentSample = new ProbabilityActivitySampler(0.5);

            AssertSamplerSamplesWithProbability(
                fiftyPercentSample, this.notSampledActivityContext, new List <ActivityLink>()
            {
                this.sampledLink
            }, 1.0);
            var twentyPercentSample = new ProbabilityActivitySampler(0.2);

            AssertSamplerSamplesWithProbability(
                twentyPercentSample, this.notSampledActivityContext, new List <ActivityLink>()
            {
                this.sampledLink
            }, 1.0);
            var twoThirdsSample = new ProbabilityActivitySampler(2.0 / 3.0);

            AssertSamplerSamplesWithProbability(
                twoThirdsSample, this.notSampledActivityContext, new List <ActivityLink>()
            {
                this.sampledLink
            }, 1.0);
        }
Пример #3
0
        public void ProbabilitySampler_DifferentProbabilities_NotSampledParent()
        {
            var neverSample = new ProbabilityActivitySampler(0.0);

            AssertSamplerSamplesWithProbability(
                neverSample, this.notSampledActivityContext, null, 0.0);
            var alwaysSample = new ProbabilityActivitySampler(1.0);

            AssertSamplerSamplesWithProbability(
                alwaysSample, this.notSampledActivityContext, null, 1.0);
            var fiftyPercentSample = new ProbabilityActivitySampler(0.5);

            AssertSamplerSamplesWithProbability(
                fiftyPercentSample, this.notSampledActivityContext, null, 0.5);
            var twentyPercentSample = new ProbabilityActivitySampler(0.2);

            AssertSamplerSamplesWithProbability(
                twentyPercentSample, this.notSampledActivityContext, null, 0.2);
            var twoThirdsSample = new ProbabilityActivitySampler(2.0 / 3.0);

            AssertSamplerSamplesWithProbability(
                twoThirdsSample, this.notSampledActivityContext, null, 2.0 / 3.0);
        }