Пример #1
0
        public void SamplingScoreIsntChangedByUserId()
        {
            string opId = GenerateRandomOperaitonId();

            var eventTelemetry = new EventTelemetry();

            eventTelemetry.Context.Operation.Id = opId;
            eventTelemetry.Context.User.Id      = GenerateRandomUserId();

            var requestTelemetry = new RequestTelemetry();

            requestTelemetry.Context.Operation.Id = opId;
            requestTelemetry.Context.User.Id      = GenerateRandomUserId();

            var eventTelemetrySamplingScoreNoUserId   = SamplingScoreGenerator.GetSamplingScore(eventTelemetry);
            var requestTelemetrySamplingScoreNoUserId = SamplingScoreGenerator.GetSamplingScore(requestTelemetry);

            Assert.AreEqual(eventTelemetrySamplingScoreNoUserId, requestTelemetrySamplingScoreNoUserId, 12);

            eventTelemetry.Context.User.Id   = string.Empty;
            requestTelemetry.Context.User.Id = string.Empty;
            var eventTelemetrySamplingScoreWithUserId   = SamplingScoreGenerator.GetSamplingScore(eventTelemetry);
            var requestTelemetrySamplingScoreWithUserId = SamplingScoreGenerator.GetSamplingScore(requestTelemetry);

            Assert.AreEqual(eventTelemetrySamplingScoreNoUserId, eventTelemetrySamplingScoreWithUserId);
            Assert.AreEqual(requestTelemetrySamplingScoreNoUserId, requestTelemetrySamplingScoreWithUserId);
        }
Пример #2
0
        public void SamplingScoreIsCalculatedCorrectlyForStringInput()
        {
            foreach (string input in StringHash.Keys)
            {
                double calculatedHash = SamplingScoreGenerator.GetSamplingScore(input);

                Assert.AreEqual((double)StringHash[input] / int.MaxValue * 100, calculatedHash, delta: 0.01);
            }
        }
Пример #3
0
        public void SamplingScoreIsRandomIfUserIdAndOperationIdAreNotPresent()
        {
            var eventTelemetry = new EventTelemetry();
            var traceTelemetry = new TraceTelemetry();

            var eventTelemetrySamplingScore = SamplingScoreGenerator.GetSamplingScore(eventTelemetry);
            var traceTelemetrySamplingScore = SamplingScoreGenerator.GetSamplingScore(traceTelemetry);

            Assert.NotEqual(eventTelemetrySamplingScore, traceTelemetrySamplingScore);
        }
Пример #4
0
        public void SamplingScoreGeneratedUsingOperationIdIfPresent()
        {
            string operationId = GenerateRandomOperaitonId();

            var eventTelemetry = new EventTelemetry();

            eventTelemetry.Context.Operation.Id = operationId;

            var requestTelemetry = new RequestTelemetry();

            requestTelemetry.Context.Operation.Id = operationId;

            var eventTelemetrySamplingScore   = SamplingScoreGenerator.GetSamplingScore(eventTelemetry);
            var requestTelemetrySamplingScore = SamplingScoreGenerator.GetSamplingScore(requestTelemetry);

            Assert.Equal(eventTelemetrySamplingScore, requestTelemetrySamplingScore, 12);
        }