public void InitializeSetsTimestampPropertyOfGivenTelemetry()
 {
     var initializer = new TimestampPropertyInitializer();
     var telemetry = new StubTelemetry();
     initializer.Initialize(telemetry);
     Assert.True(DateTimeOffset.Now.Subtract(telemetry.Timestamp) < TimeSpan.FromMinutes(1));
 }
示例#2
0
        public void InitializeDoesNotIncludeBase64PaddingInSequenceToReduceDataSize()
        {
            var telemetry = new StubTelemetry();

            new SequencePropertyInitializer().Initialize(telemetry);
            AssertEx.DoesNotContain("=", telemetry.Sequence, StringComparison.Ordinal);
        }
示例#3
0
            public void SendWillBeMarkedAsInternalOperation()
            {
                bool wasCalled = false;
                var  channel   = new ServerTelemetryChannel();

                channel.TelemetrySerializer = new TelemetrySerializerStub(channel.Transmitter)
                {
                    WasCalled = (called) => { wasCalled = called; }
                };
#if NETCOREAPP
                channel.TelemetryBuffer = new TelemetryChannel.Implementation.TelemetryBuffer(channel.TelemetrySerializer, null);
#else
                channel.TelemetryBuffer = new TelemetryChannel.Implementation.TelemetryBuffer(channel.TelemetrySerializer, new WebApplicationLifecycle());
#endif
                channel.TelemetryProcessor         = channel.TelemetryBuffer;
                channel.MaxTelemetryBufferCapacity = 1;
                channel.Initialize(TelemetryConfiguration.CreateDefault());

                var telemetry = new StubTelemetry();
                telemetry.Context.InstrumentationKey = Guid.NewGuid().ToString();
                channel.Send(telemetry);
                Thread.Sleep(TimeSpan.FromSeconds(1));

                Assert.IsTrue(wasCalled);
            }
示例#4
0
        public void InitializeSeparatesStableIdAndNumberWithColonToConformWithVortexSpecification()
        {
            var telemetry = new StubTelemetry();

            new SequencePropertyInitializer().Initialize(telemetry);
            AssertEx.Contains(":", telemetry.Sequence, StringComparison.Ordinal);
        }
示例#5
0
            public void DropsTelemetryWithNoInstrumentationKey()
            {
                ITelemetry sentTelemetry = null;
                var        channel       = new ServerTelemetryChannel();

                channel.Initialize(TelemetryConfiguration.CreateDefault());
                channel.TelemetryProcessor = new StubTelemetryProcessor(null)
                {
                    OnProcess = (t) => sentTelemetry = t
                };

                var telemetry = new StubTelemetry();

                // No instrumentation key

                using (TestEventListener listener = new TestEventListener())
                {
                    listener.EnableEvents(TelemetryChannelEventSource.Log, EventLevel.Verbose);

                    channel.Send(telemetry);

                    Assert.IsNull(sentTelemetry);
                    var expectedMessage = listener.Messages.First();
                    Assert.AreEqual(67, expectedMessage.EventId);
                }
            }
        public void TrackRespectsInstrumentaitonKeySetByTelemetryInitializer()
        {
            var sentTelemetry = new List <ITelemetry>();
            var channel       = new StubTelemetryChannel {
                OnSend = t => sentTelemetry.Add(t)
            };

            // No instrumentation key set here.
            var configuration = new TelemetryConfiguration(string.Empty, channel);

            var initializedTelemetry = new List <ITelemetry>();
            var telemetryInitializer = new StubTelemetryInitializer();

            telemetryInitializer.OnInitialize = item =>
            {
                item.Context.InstrumentationKey = "Foo";
                initializedTelemetry.Add(item);
            };

            configuration.TelemetryInitializers.Add(telemetryInitializer);

            var client = new TelemetryClient(configuration);

            var telemetry = new StubTelemetry();

            client.Track(telemetry);

            Assert.Equal(1, sentTelemetry.Count);
            Assert.Equal(1, initializedTelemetry.Count);
        }
 public void InitializePreservesExistingSequencePropertyValue()
 {
     string originalValue = Guid.NewGuid().ToString();
     var telemetry = new StubTelemetry { Sequence = originalValue };
     new SequencePropertyInitializer().Initialize(telemetry);
     Assert.Equal(originalValue, telemetry.Sequence);
 }
示例#8
0
        public void InitializeSetsSequencePropertyValue()
        {
            var telemetry = new StubTelemetry();

            new SequencePropertyInitializer().Initialize(telemetry);
            Assert.NotEmpty(telemetry.Sequence);
        }
示例#9
0
        public void FlushCanBeAborted()
        {
            var telemetryBuffer = new TelemetryBuffer();
            var channel         = new InMemoryChannel(telemetryBuffer, new InMemoryTransmitter(telemetryBuffer))
            {
                SendingInterval = TimeSpan.FromDays(1),
                EndpointAddress = "http://localhost/bad"
            };

            channel.Send(new StubTelemetry()); // Send telemetry so that it sets next send intreval and does not interfere with Flush
            channel.Flush();

            var transmission = new StubTelemetry();

            channel.Send(transmission);

            using (TestEventListener listener = new TestEventListener())
            {
                listener.EnableEvents(CoreEventSource.Log, EventLevel.Warning);
                channel.Flush(TimeSpan.FromTicks(1));

                var expectedMessage = listener.Messages.First();
                Assert.Equal(24, expectedMessage.EventId);
            }
        }
示例#10
0
        public void InitializeSetsSequencePropertyValue()
        {
            var telemetry = new StubTelemetry();

            new SequencePropertyInitializer().Initialize(telemetry);
            Assert.AreNotEqual(string.Empty, telemetry.Sequence);
        }
示例#11
0
        public void InitializeSetsTimestampPropertyOfGivenTelemetry()
        {
            var initializer = new TimestampPropertyInitializer();
            var telemetry   = new StubTelemetry();

            initializer.Initialize(telemetry);
            Assert.True(DateTimeOffset.Now.Subtract(telemetry.Timestamp) < TimeSpan.FromMinutes(1));
        }
 public void InitializeDoesNotOverrideTimestampSpecifiedExplicitly()
 {
     var initializer = new TimestampPropertyInitializer();
     var expected = new DateTimeOffset(new DateTime(42));
     var telemetry = new StubTelemetry { Timestamp = expected };
     initializer.Initialize(telemetry);
     Assert.Equal(expected, telemetry.Timestamp);
 }
        public void InitializeSetsUserAnonymousIdOfGivenTelemetryContext()
        {
            var initializer = new UserContextInitializer();

            var telemetry = new StubTelemetry();
            initializer.Initialize(telemetry);

            Assert.NotEqual(string.Empty, telemetry.Context.User.Id);
        }
示例#14
0
        public void InitializePreservesExistingSequencePropertyValue()
        {
            string originalValue = Guid.NewGuid().ToString();
            var    telemetry     = new StubTelemetry {
                Sequence = originalValue
            };

            new SequencePropertyInitializer().Initialize(telemetry);
            Assert.AreEqual(originalValue, telemetry.Sequence);
        }
        public void InitializeSetsSameUserAnonymousIdWhenApplicationIsRestarted()
        {
            var telemetry1 = new StubTelemetry();
            new UserContextInitializer().Initialize(telemetry1);

            var telemetry2 = new StubTelemetry();
            new UserContextInitializer().Initialize(telemetry2);

            Assert.Equal(telemetry1.Context.User.Id, telemetry2.Context.User.Id);
        }
示例#16
0
            public void InitializeDoesNotSetSessionIdOfGivenTelemetryBeforeApplicationIsStarted()
            {
                SessionTelemetryModule module = this.CreateSessionTelemetryModule();

                var telemetry = new StubTelemetry();

                ((ITelemetryInitializer)module).Initialize(telemetry);

                Assert.Null(telemetry.Context.Session.Id);
            }
            public void InitializeSetsSessionIdOfGivenTelemetryAfterApplicationIsStarted()
            {
                SessionTelemetryModule module = this.CreateSessionTelemetryModule();
                module.Initialize();                

                var telemetry = new StubTelemetry();
                ((ITelemetryInitializer)module).Initialize(telemetry);

                Assert.NotEmpty(telemetry.Context.Session.Id);
            }
        public void InitializeSetsUserAnonymousIdOfGivenTelemetryContext()
        {
            var initializer = new UserContextInitializer();

            var telemetry = new StubTelemetry();

            initializer.Initialize(telemetry);

            Assert.NotEqual(string.Empty, telemetry.Context.User.Id);
        }
        public void InitializeGeneratesUniqueValuesWhenCalledOnMultipleInstances()
        {
            var telemetry1 = new StubTelemetry();
            new SequencePropertyInitializer().Initialize(telemetry1);

            var telemetry2 = new StubTelemetry();
            new SequencePropertyInitializer().Initialize(telemetry2);

            Assert.NotEqual(telemetry1.Sequence, telemetry2.Sequence);
        }
示例#20
0
        public void InitializeDoesNotOverrideTimestampSpecifiedExplicitly()
        {
            var initializer = new TimestampPropertyInitializer();
            var expected    = new DateTimeOffset(new DateTime(42));
            var telemetry   = new StubTelemetry {
                Timestamp = expected
            };

            initializer.Initialize(telemetry);
            Assert.Equal(expected, telemetry.Timestamp);
        }
        public void InitializeGeneratesUniqueSequenceValuesWhenCalledMultipleTimes()
        {
            var initializer = new SequencePropertyInitializer();

            var telemetry1 = new StubTelemetry();
            initializer.Initialize(telemetry1);
            var telemetry2 = new StubTelemetry();
            initializer.Initialize(telemetry2);

            Assert.NotEqual(telemetry1.Sequence, telemetry2.Sequence);
        }
        public async Task FlushAsyncRespectsCancellationToken()
        {
            var telemetryBuffer = new TelemetryBuffer();
            var channel         = new InMemoryChannel(telemetryBuffer, new InMemoryTransmitter(telemetryBuffer));
            var sentTelemetry   = new StubTelemetry();

            sentTelemetry.Context.InstrumentationKey = Guid.NewGuid().ToString();

            channel.Send(sentTelemetry);
            await Assert.ThrowsExceptionAsync <TaskCanceledException>(() => channel.FlushAsync(new CancellationToken(true)));
        }
        public void InitializeSetsSameUserAnonymousIdThroughoutLifetimeOfApplication()
        {
            var initializer = new UserContextInitializer();

            var telemetry1 = new StubTelemetry();
            initializer.Initialize(telemetry1);
            var telemetry2 = new StubTelemetry();
            initializer.Initialize(telemetry2);

            Assert.Equal(telemetry1.Context.User.Id, telemetry2.Context.User.Id);
        }
示例#24
0
            public void InitializeSetsSessionIdOfGivenTelemetryAfterApplicationIsStarted()
            {
                SessionTelemetryModule module = this.CreateSessionTelemetryModule();

                module.Initialize();

                var telemetry = new StubTelemetry();

                ((ITelemetryInitializer)module).Initialize(telemetry);

                Assert.NotEmpty(telemetry.Context.Session.Id);
            }
示例#25
0
            public void PassesTelemetryToMemoryBufferChannel()
            {
                var channel = new PersistenceChannel();

                var telemetry = new StubTelemetry();

                channel.Send(telemetry);

                IEnumerable <ITelemetry> actual = channel.TelemetryBuffer.Dequeue();

                Assert.AreEqual(telemetry, actual.First());
            }
示例#26
0
        public void WhenSendIsCalledTheEventIsBeingQueuedInTheBuffer()
        {
            var telemetryBuffer = new TelemetryBuffer();
            var channel         = new InMemoryChannel(telemetryBuffer, new InMemoryTransmitter(telemetryBuffer));
            var sentTelemetry   = new StubTelemetry();

            channel.Send(sentTelemetry);
            IEnumerable <ITelemetry> telemetries = telemetryBuffer.Dequeue();

            Assert.Equal(1, telemetries.Count());
            Assert.Same(sentTelemetry, telemetries.First());
        }
示例#27
0
            public void InitializePreservesExistingSessionIdOfGivenTelemetry()
            {
                SessionTelemetryModule module = this.CreateSessionTelemetryModule();

                string expectedSessionId = "Telemetry Session ID";
                var    telemetry         = new StubTelemetry();

                telemetry.Context.Session.Id = expectedSessionId;
                ((ITelemetryInitializer)module).Initialize(telemetry);

                Assert.Equal(expectedSessionId, telemetry.Context.Session.Id);
            }
        public void InitializeSetsSameUserAnonymousIdWhenApplicationIsRestarted()
        {
            var telemetry1 = new StubTelemetry();

            new UserContextInitializer().Initialize(telemetry1);

            var telemetry2 = new StubTelemetry();

            new UserContextInitializer().Initialize(telemetry2);

            Assert.Equal(telemetry1.Context.User.Id, telemetry2.Context.User.Id);
        }
        public void InitializeSetsSameUserAcquisitionDateWhenApplicationIsRestarted()
        {
            var telemetry1 = new StubTelemetry();

            new UserContextInitializer().Initialize(telemetry1);

            var telemetry2 = new StubTelemetry();

            new UserContextInitializer().Initialize(telemetry2);

            Assert.Equal(telemetry1.Context.User.AcquisitionDate, telemetry2.Context.User.AcquisitionDate);
        }
示例#30
0
        public void InitializeGeneratesUniqueValuesWhenCalledOnMultipleInstances()
        {
            var telemetry1 = new StubTelemetry();

            new SequencePropertyInitializer().Initialize(telemetry1);

            var telemetry2 = new StubTelemetry();

            new SequencePropertyInitializer().Initialize(telemetry2);

            Assert.AreNotEqual(telemetry1.Sequence, telemetry2.Sequence);
        }
        public void InitializeSetsSameUserAnonymousIdThroughoutLifetimeOfApplication()
        {
            var initializer = new UserContextInitializer();

            var telemetry1 = new StubTelemetry();

            initializer.Initialize(telemetry1);
            var telemetry2 = new StubTelemetry();

            initializer.Initialize(telemetry2);

            Assert.Equal(telemetry1.Context.User.Id, telemetry2.Context.User.Id);
        }
        public void InitializeSetsSameUserAcquisitionDateThroughtoutLifetimeOfApplication()
        {
            var initializer = new UserContextInitializer();

            var telemetry1 = new StubTelemetry();

            initializer.Initialize(telemetry1);
            var telemetry2 = new StubTelemetry();

            initializer.Initialize(telemetry2);

            Assert.Equal(telemetry1.Context.User.AcquisitionDate, telemetry2.Context.User.AcquisitionDate);
        }
示例#33
0
        public void InitializeGeneratesUniqueSequenceValuesWhenCalledMultipleTimes()
        {
            var initializer = new SequencePropertyInitializer();

            var telemetry1 = new StubTelemetry();

            initializer.Initialize(telemetry1);
            var telemetry2 = new StubTelemetry();

            initializer.Initialize(telemetry2);

            Assert.NotEqual(telemetry1.Sequence, telemetry2.Sequence);
        }
示例#34
0
            public void InitializePreservesExistingIsFirstSessionOfGivenTelemetry()
            {
                SessionTelemetryModule module = this.CreateSessionTelemetryModule();

                module.Initialize();

                var telemetry = new StubTelemetry();

                telemetry.Context.Session.IsFirst = false;
                ((ITelemetryInitializer)module).Initialize(telemetry);

                Assert.Equal(false, telemetry.Context.Session.IsFirst);
            }
示例#35
0
        public void WhenSendIsCalledTheEventIsBeingQueuedInTheBuffer()
        {
            var telemetryBuffer = new TelemetryBuffer();
            var channel         = new InMemoryChannel(telemetryBuffer, new InMemoryTransmitter(telemetryBuffer));
            var sentTelemetry   = new StubTelemetry();

            sentTelemetry.Context.InstrumentationKey = Guid.NewGuid().ToString();

            channel.Send(sentTelemetry);
            IEnumerable <ITelemetry> telemetries = telemetryBuffer.Dequeue();

            Assert.AreEqual(1, telemetries.Count());
            Assert.AreSame(sentTelemetry, telemetries.First());
        }
        public void TrackCopiesPropertiesFromClientToTelemetry()
        {
            var configuration = new TelemetryConfiguration(string.Empty, new StubTelemetryChannel());
            var client        = new TelemetryClient(configuration);

            client.Context.Properties["TestProperty"] = "TestValue";
            client.Context.InstrumentationKey         = "Test Key";

            var telemetry = new StubTelemetry();

            client.Track(telemetry);

            Assert.Equal(client.Context.Properties.ToArray(), telemetry.Properties.ToArray());
        }
            public void PassesTelemetryToTelemetryProcessor()
            {
                ITelemetry sentTelemetry = null;
                var        channel       = new ServerTelemetryChannel();

                channel.TelemetryProcessor = new StubTelemetryProcessor(null)
                {
                    OnProcess = (t) => sentTelemetry = t
                };

                var telemetry = new StubTelemetry();

                channel.Send(telemetry);

                Assert.Equal(telemetry, sentTelemetry);
            }
        public void TrackDoesNotOverwriteTelemetryPropertiesWithClientPropertiesBecauseExplicitlySetValuesTakePrecedence()
        {
            var configuration = new TelemetryConfiguration(string.Empty, new StubTelemetryChannel());
            var client        = new TelemetryClient(configuration);

            client.Context.Properties["TestProperty"] = "ClientValue";
            client.Context.InstrumentationKey         = "Test Key";

            var telemetry = new StubTelemetry {
                Properties = { { "TestProperty", "TelemetryValue" } }
            };

            client.Track(telemetry);

            Assert.Equal("TelemetryValue", telemetry.Properties["TestProperty"]);
        }
            public void PassesTelemetryToTelemetryProcessor()
            {
                ITelemetry sentTelemetry = null;
                var        channel       = new ServerTelemetryChannel();

                channel.Initialize(TelemetryConfiguration.CreateDefault());
                channel.TelemetryProcessor = new StubTelemetryProcessor(null)
                {
                    OnProcess = (t) => sentTelemetry = t
                };

                var telemetry = new StubTelemetry();

                channel.Send(telemetry);

                Assert.Equal(telemetry, sentTelemetry);
            }
 public void InitializeSeparatesStableIdAndNumberWithColonToConformWithVortexSpecification()
 {
     var telemetry = new StubTelemetry();
     new SequencePropertyInitializer().Initialize(telemetry);
     Assert.Contains(":", telemetry.Sequence, StringComparison.Ordinal);
 }
            public void InitializePreservesExistingIsFirstSessionOfGivenTelemetry()
            {
                SessionTelemetryModule module = this.CreateSessionTelemetryModule();
                module.Initialize();

                var telemetry = new StubTelemetry();
                telemetry.Context.Session.IsFirst = false;
                ((ITelemetryInitializer)module).Initialize(telemetry);

                Assert.Equal(false, telemetry.Context.Session.IsFirst);
            }
            public void InitializeDoesNotSetSessionIsFirstWhenPreviousSessionTimedOut()
            {
                SessionTelemetryModule module = this.CreateSessionTelemetryModule();
                
                // Application started and suspended 1 day ago
                this.clock.Time = DateTimeOffset.Now - TimeSpan.FromDays(1);
                module.Initialize();
                module.HandleApplicationStoppingEvent(null, null);

                // Application resumes today
                this.clock.Time = DateTimeOffset.Now;
                module.HandleApplicationStartedEvent(null, null);

                var telemetry = new StubTelemetry();
                ((ITelemetryInitializer)module).Initialize(telemetry);

                Assert.Null(telemetry.Context.Session.IsFirst);
            }
 public void InitializeSetsSequencePropertyValue()
 {
     var telemetry = new StubTelemetry();
     new SequencePropertyInitializer().Initialize(telemetry);
     Assert.NotEmpty(telemetry.Sequence);
 }
        public void InitializeSetsSameUserAcquisitionDateThroughtoutLifetimeOfApplication()
        {
            var initializer = new UserContextInitializer();

            var telemetry1 = new StubTelemetry();
            initializer.Initialize(telemetry1);
            var telemetry2 = new StubTelemetry();
            initializer.Initialize(telemetry2);

            Assert.Equal(telemetry1.Context.User.AcquisitionDate, telemetry2.Context.User.AcquisitionDate);
        }
        public void InitializeSetsSameUserAcquisitionDateWhenApplicationIsRestarted()
        {
            var telemetry1 = new StubTelemetry();
            new UserContextInitializer().Initialize(telemetry1);

            var telemetry2 = new StubTelemetry();
            new UserContextInitializer().Initialize(telemetry2);

            Assert.Equal(telemetry1.Context.User.AcquisitionDate, telemetry2.Context.User.AcquisitionDate);
        }
            public void PassesTelemetryToMemoryBufferChannel()
            {
                ServiceLocator.AddService<BaseStorageService>(new StorageService());
                var channel = new PersistenceChannel();

                var telemetry = new StubTelemetry();
                channel.Send(telemetry);

                IEnumerable<ITelemetry> actual = channel.TelemetryBuffer.Dequeue();
                Assert.AreEqual(telemetry, actual.First());
            }
        public void InitializeGeneratesSingleUserIdRegardlessOfNumberOfThreadsAccessingIt()
        {
            const int NumberOfTasks = 16;
            var telemetry = new Task<ITelemetry>[NumberOfTasks];

            for (int i = 0; i < NumberOfTasks; i++)
            {               
                telemetry[i] = TaskEx.Run(() =>
                {
                    ITelemetry t = new StubTelemetry();
                    new UserContextInitializer().Initialize(t);
                    return t;
                });
            }

            Task.WaitAll(telemetry);
            string firstUserId = telemetry[0].Result.Context.User.Id;
            for (int i = 1; i < NumberOfTasks; i++)
            {
                Assert.Equal(firstUserId, telemetry[i].Result.Context.User.Id);
            }
        }
            public void InitializeDoesNotSetSessionIdOfGivenTelemetryBeforeApplicationIsStarted()
            {
                SessionTelemetryModule module = this.CreateSessionTelemetryModule();

                var telemetry = new StubTelemetry();
                ((ITelemetryInitializer)module).Initialize(telemetry);

                Assert.Null(telemetry.Context.Session.Id);
            }
            public void InitializePreservesExistingSessionIdOfGivenTelemetry()
            {
                SessionTelemetryModule module = this.CreateSessionTelemetryModule();
                
                string expectedSessionId = "Telemetry Session ID";
                var telemetry = new StubTelemetry();
                telemetry.Context.Session.Id = expectedSessionId;
                ((ITelemetryInitializer)module).Initialize(telemetry);

                Assert.Equal(expectedSessionId, telemetry.Context.Session.Id);
            }
 public void InitializeDoesNotIncludeBase64PaddingInSequenceToReduceDataSize()
 {
     var telemetry = new StubTelemetry();
     new SequencePropertyInitializer().Initialize(telemetry);
     Assert.DoesNotContain("=", telemetry.Sequence, StringComparison.Ordinal);
 }