Esempio n. 1
0
        public void WhenRequestIsSent_Async_TelemetryIsWritten_ExceptionOnEnd()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = this.GetChannel(innerChannel, typeof(ISimpleService));

            innerChannel.FailEndRequest = true;

            var result = channel.BeginRequest(BuildMessage(TwoWayOp1), null, null);
            var failed = false;

            try
            {
                var response = channel.EndRequest(result);
            }
            catch
            {
                failed = true;
            }

            Assert.IsTrue(failed, "EndRequest did not throw an exception");

            CheckOpDependencyWritten(DependencyConstants.WcfClientCall, typeof(ISimpleService), TwoWayOp1, "GetSimpleData", false);
        }
        public void ErrorTelemetryEventsAreGeneratedOnAsyncExceptionAndIEDIF_False()
        {
            TestTelemetryChannel.Clear();
            var host = new HostingContext <AsyncService, IAsyncService>()
                       .ShouldWaitForCompletion();

            using (host)
            {
                host.Open();
                IAsyncService client = host.GetChannel();
                try
                {
                    client.FailWithExceptionAsync().Wait();
                }
                catch
                {
                }
            }

            var errors = from item in TestTelemetryChannel.CollectedData()
                         where item is ExceptionTelemetry
                         select item;

            Assert.IsTrue(errors.Count() > 0);
        }
Esempio n. 3
0
        public void SendFollowedWithReceiveTimeout_WritesTelemetry()
        {
            TestTelemetryChannel.Clear();
            var innerChannel = new MockClientChannel(SvcUrl);
            var channel      = GetChannel(innerChannel, typeof(ISimpleService));

            var request = BuildMessage(TwoWayOp1);

            request.Headers.MessageId     = new UniqueId();
            innerChannel.MessageToReceive = null;

            channel.Send(request, TimeSpan.FromMilliseconds(50));
            bool failed = false;

            try
            {
                channel.Receive();
            } catch (TimeoutException)
            {
                failed = true;
            }

            Assert.IsTrue(failed, "Receive did not fail with TimeoutException");
            // there's potentially some additional delay between our timeout firing internally,
            // and the callback firing so that telemetry can be written
            Thread.Sleep(200);

            var telemetry = TestTelemetryChannel.CollectedData()
                            .OfType <DependencyTelemetry>()
                            .FirstOrDefault();

            Assert.IsNotNull(telemetry, "No telemetry event written");
            Assert.IsFalse(telemetry.Success.Value, "Dependency call succeeded");
        }
        public void RequestReply_TelemetryIsWritten()
        {
            TestTelemetryChannel.Clear();
            using (var host = new HostingContext <SimpleService, ISimpleService>())
            {
                host.Open();

                var            binding       = new NetTcpBinding();
                var            configuration = new TelemetryConfiguration();
                var            factory       = new ChannelFactory <ISimpleService>(binding, host.GetServiceAddress());
                ISimpleService channel       = null;
                try
                {
                    var behavior = new ClientTelemetryEndpointBehavior(configuration);
                    factory.Endpoint.EndpointBehaviors.Add(behavior);

                    channel = factory.CreateChannel();
                    channel.GetSimpleData();
                    ((IClientChannel)channel).Close();
                    factory.Close();

                    Assert.IsTrue(TestTelemetryChannel.CollectedData().Count > 0, "No telemetry events written");
                }
                catch
                {
                    if (channel != null)
                    {
                        ((IClientChannel)channel).Abort();
                    }

                    factory.Abort();
                    throw;
                }
            }
        }
Esempio n. 5
0
        public void ResponseIsTraced()
        {
            TraceTelemetryModule.Enable();
            try
            {
                TestTelemetryChannel.Clear();
                using (var host = new HostingContext <SimpleService, ISimpleService>())
                {
                    host.Open();
                    ISimpleService client = host.GetChannel();
                    client.GetSimpleData();
                }

                var trace = TestTelemetryChannel.CollectedData()
                            .OfType <EventTelemetry>()
                            .FirstOrDefault(x => x.Name == "WcfResponse");
                Assert.IsNotNull(trace, "No WcfResponse trace found");
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(trace.Properties["Body"]);
            }
            finally
            {
                TraceTelemetryModule.Disable();
            }
        }
Esempio n. 6
0
        public void AsyncSendAndTryReceive_WritesTelemetry()
        {
            TestTelemetryChannel.Clear();
            var innerChannel = new MockClientChannel(SvcUrl);
            var channel      = GetChannel(innerChannel, typeof(ISimpleService));

            var request = BuildMessage(TwoWayOp1);

            request.Headers.MessageId = new UniqueId();
            var expectedReply = BuildMessage(TwoWayOp1);

            expectedReply.Headers.RelatesTo = request.Headers.MessageId;
            innerChannel.MessageToReceive   = expectedReply;

            var result = channel.BeginSend(request, null, null);

            channel.EndSend(result);
            result = channel.BeginTryReceive(TimeSpan.FromMilliseconds(10), null, null);
            Message reply;

            Assert.IsTrue(channel.EndTryReceive(result, out reply), "EndTryReceive failed");

            var telemetry = TestTelemetryChannel.CollectedData()
                            .OfType <DependencyTelemetry>()
                            .FirstOrDefault();

            Assert.IsNotNull(telemetry, "No telemetry event written");
        }
Esempio n. 7
0
        public void WhenMessageIsSent_WithTimeoutException_TelemetryHasResultCode()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = GetChannel(innerChannel, typeof(IOneWayService));

            innerChannel.FailRequest            = true;
            innerChannel.ExceptionToThrowOnSend = new TimeoutException();

            bool failed = false;

            try
            {
                channel.Send(BuildMessage(OneWayOp1));
            } catch (TimeoutException)
            {
                failed = true;
            }
            Assert.IsTrue(failed, "Send did not throw TimeoutException");

            var telemetry = TestTelemetryChannel.CollectedData().OfType <DependencyTelemetry>().First();

            Assert.AreEqual("Timeout", telemetry.ResultCode);
        }
        public void ErrorTelemetryEventsContainDetailedInfoOnTypedFault()
        {
            TestTelemetryChannel.Clear();
            var host = new HostingContext <SimpleService, ISimpleService>()
                       .ShouldWaitForCompletion();

            using (host)
            {
                host.Open();
                ISimpleService client = host.GetChannel();
                try
                {
                    client.CallFailsWithTypedFault();
                }
                catch
                {
                }
            }

            var error = (from item in TestTelemetryChannel.CollectedData()
                         where item is ExceptionTelemetry
                         select item).Cast <ExceptionTelemetry>().First();

            Assert.IsNotNull(error.Exception);
            Assert.IsNotNull(error.Context.Operation.Id);
            Assert.IsNotNull(error.Context.Operation.Name);
        }
        public void ErrorTelemetryEventsAreGeneratedOnExceptionAndIEDIF_True()
        {
            TestTelemetryChannel.Clear();
            var host = new HostingContext <SimpleService, ISimpleService>()
                       .ShouldWaitForCompletion()
                       .IncludeDetailsInFaults();

            using (host)
            {
                host.Open();

                ISimpleService client = host.GetChannel();
                try
                {
                    client.CallFailsWithException();
                }
                catch
                {
                }
            }

            var errors = from item in TestTelemetryChannel.CollectedData()
                         where item is ExceptionTelemetry
                         select item;

            Assert.IsTrue(errors.Count() > 0);
        }
        public void WhenMessageIsSent_Async_TelemetryIsWritten_ExceptionOnEnd()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = this.GetChannel(innerChannel, typeof(IOneWayService));

            innerChannel.FailEndRequest = true;

            var  result = channel.BeginSend(BuildMessage(OneWayOp1), TimeSpan.FromSeconds(10), null, null);
            bool failed = false;

            try
            {
                channel.EndSend(result);
            }
            catch
            {
                failed = true;
            }

            Assert.IsTrue(failed, "EndSend did not throw an exception");

            CheckOpDependencyWritten(DependencyConstants.WcfClientCall, typeof(IOneWayService), OneWayOp1, "SuccessfullOneWayCall", false);
        }
        public void WhenChannelIsOpened_TelemetryIsWritten()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = this.GetChannel(innerChannel, typeof(ISimpleService));

            channel.Open();

            CheckOpenDependencyWritten(typeof(ISimpleService), true);
        }
Esempio n. 12
0
        public void WhenMessageIsSentWithTimeout_TelemetryIsWritten()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = GetChannel(innerChannel, typeof(IOneWayService));

            channel.Send(BuildMessage(OneWayOp1), TimeSpan.FromSeconds(10));

            CheckOpDependencyWritten(DependencyConstants.WcfClientCall, typeof(IOneWayService), OneWayOp1, "SuccessfullOneWayCall", true);
        }
Esempio n. 13
0
        public void WhenRequestIsSentWithTimeout_TelemetryIsWritten()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = this.GetChannel(innerChannel, typeof(ISimpleService));

            var response = channel.Request(BuildMessage(TwoWayOp1), TimeSpan.FromSeconds(10));

            CheckOpDependencyWritten(DependencyConstants.WcfClientCall, typeof(ISimpleService), TwoWayOp1, "GetSimpleData", true);
        }
 public void TelemetryEventsAreGeneratedOnServiceCall()
 {
     TestTelemetryChannel.Clear();
     using (var host = new HostingContext <SimpleService, ISimpleService>())
     {
         host.Open();
         ISimpleService client = host.GetChannel();
         client.GetSimpleData();
         Assert.IsTrue(TestTelemetryChannel.CollectedData().Count > 0);
     }
 }
 public void TelemetryEventsAreGeneratedOnAsyncCall()
 {
     TestTelemetryChannel.Clear();
     using (var host = new HostingContext <AsyncService, IAsyncService>())
     {
         host.Open();
         IAsyncService client = host.GetChannel();
         client.GetDataAsync().Wait();
         Assert.IsTrue(TestTelemetryChannel.CollectedData().Count > 0);
     }
 }
        private void CheckOpenDependencyWritten(Type contract, bool success)
        {
            var dependency = TestTelemetryChannel.CollectedData().OfType <DependencyTelemetry>().FirstOrDefault();

            Assert.IsNotNull(dependency, "Did not write dependency event");
            Assert.AreEqual(SvcUrl, dependency.Data);
            Assert.AreEqual(HostName, dependency.Target);
            Assert.AreEqual(DependencyConstants.WcfChannelOpen, dependency.Type);
            Assert.AreEqual(contract.Name, dependency.Name);
            Assert.AreEqual(success, dependency.Success.Value);
        }
        public void WhenChannelIsOpenedWithTimeout_TelemetryIsWritten()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = GetChannel(innerChannel, typeof(ISimpleService));

            channel.Open(TimeSpan.FromSeconds(10));

            CheckOpenDependencyWritten(typeof(ISimpleService), true);
        }
        public void WhenChannelIsOpenedAsyncWithTimeout_TelemetryIsWritten()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = this.GetChannel(innerChannel, typeof(ISimpleService));
            var result  = channel.BeginOpen(TimeSpan.FromSeconds(10), null, null);

            channel.EndOpen(result);

            CheckOpenDependencyWritten(typeof(ISimpleService), true);
        }
        public void WhenChannelIsCreated_InnerChannelRemoteAddressIsReturned()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = GetChannel(innerChannel, typeof(ISimpleService));
            // IChannel does not define RemoteAddress, so cheat

            var prop = channel.GetType().GetProperty("RemoteAddress", BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty);

            Assert.AreEqual(innerChannel.RemoteAddress, prop.GetValue(channel, null));
        }
        public void WhenChannelIsOpenedAsync_TelemetryIsWritten()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = GetChannel(innerChannel, typeof(ISimpleService));
            var result  = channel.BeginOpen(null, null);

            channel.EndOpen(result);

            CheckOpenDependencyWritten(typeof(ISimpleService), true);
        }
Esempio n. 21
0
        public void WhenRequestIsSent_Async_TelemetryIsWritten()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = this.GetChannel(innerChannel, typeof(ISimpleService));

            var result   = channel.BeginRequest(BuildMessage(TwoWayOp1), null, null);
            var response = channel.EndRequest(result);

            CheckOpDependencyWritten(DependencyConstants.WcfClientCall, typeof(ISimpleService), TwoWayOp1, "GetSimpleData", true);
        }
Esempio n. 22
0
        private void CheckOpDependencyWritten(String type, Type contract, String action, String method, bool success)
        {
            var dependency = TestTelemetryChannel.CollectedData().OfType <DependencyTelemetry>().FirstOrDefault();

            Assert.IsNotNull(dependency, "Did not write dependency event");
            Assert.AreEqual(SvcUrl, dependency.Data);
            Assert.AreEqual("localhost", dependency.Target);
            Assert.AreEqual(type, dependency.Type);
            Assert.AreEqual(contract.Name + "." + method, dependency.Name);
            Assert.AreEqual(action, dependency.Properties["soapAction"]);
            Assert.AreEqual("True", dependency.Properties["isOneWay"]);
            Assert.AreEqual(success, dependency.Success.Value);
        }
Esempio n. 23
0
        private static DependencyTelemetry CheckOpDependencyWritten(string type, Type contract, string action, string method, bool success)
        {
            var dependency = TestTelemetryChannel.CollectedData().OfType <DependencyTelemetry>().FirstOrDefault();

            Assert.IsNotNull(dependency, "Did not write dependency event");
            Assert.AreEqual(ClientTelemetryRequestChannelTests.SvcUrl, dependency.Data);
            Assert.AreEqual("localhost", dependency.Target);
            Assert.AreEqual(type, dependency.Type);
            Assert.AreEqual(contract.Name + "." + method, dependency.Name);
            Assert.AreEqual(action, dependency.Properties["soapAction"]);
            Assert.AreEqual(success, dependency.Success.Value);
            return(dependency);
        }
Esempio n. 24
0
        public void WhenMessageIsSent_Async_TelemetryIsWritten()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = GetChannel(innerChannel, typeof(IOneWayService));

            var result = channel.BeginSend(BuildMessage(OneWayOp1), null, null);

            channel.EndSend(result);

            CheckOpDependencyWritten(DependencyConstants.WcfClientCall, typeof(IOneWayService), OneWayOp1, "SuccessfullOneWayCall", true);
        }
Esempio n. 25
0
        public void CallsToOpWithoutOperationTelemetryGeneratesEvents()
        {
            TestTelemetryChannel.Clear();
            var host = new HostingContext <SelectiveTelemetryService, ISelectiveTelemetryService>();

            using ( host )
            {
                host.Open();

                ISelectiveTelemetryService client = host.GetChannel();
                client.OperationWithoutTelemetry();
            }
            Assert.AreEqual(0, TestTelemetryChannel.CollectedData().Count);
        }
        public void SuccessfulOneWayCallGeneratesRequestEvent()
        {
            TestTelemetryChannel.Clear();
            using (var host = new HostingContext <OneWayService, IOneWayService>())
            {
                host.Open();
                IOneWayService client = host.GetChannel();
                client.SuccessfullOneWayCall();
            }
            var req = TestTelemetryChannel.CollectedData()
                      .FirstOrDefault(x => x is RequestTelemetry);

            Assert.IsNotNull(req);
        }
Esempio n. 27
0
 public void OperationMethodThatCallsAnotherServiceDoesNotLoseOperationContext()
 {
     TestTelemetryChannel.Clear();
     using (var host = new HostingContext <SimpleService, ISimpleService>())
         using (var hostSecond = new HostingContext <SimpleService, ISimpleService>())
         {
             host.IncludeDetailsInFaults();
             host.Open();
             hostSecond.Open();
             ISimpleService client = host.GetChannel();
             client.CallAnotherServiceAndLeakOperationContext(hostSecond.GetServiceAddress());
             Assert.IsTrue(TestTelemetryChannel.CollectedData().Count > 0);
         }
 }
Esempio n. 28
0
        public void CallsToOpMarkedWithOperationTelemetryGeneratesEvents()
        {
            TestTelemetryChannel.Clear();
            var host = new HostingContext <SelectiveTelemetryService, ISelectiveTelemetryService>();

            using ( host )
            {
                host.Open();

                ISelectiveTelemetryService client = host.GetChannel();
                client.OperationWithTelemetry();
            }
            Assert.IsTrue(TestTelemetryChannel.CollectedData().Count > 0);
        }
        public void WhenChannelIsOpenedWithTimeout_InnerChannelEventsAreHooked()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = GetChannel(innerChannel, typeof(ISimpleService));

            channel.Open(TimeSpan.FromSeconds(10));

            Assert.IsTrue(innerChannel.OpeningIsHooked(), "Opening event is not hooked");
            Assert.IsTrue(innerChannel.OpenedIsHooked(), "Opened event is not hooked");
            Assert.IsTrue(innerChannel.ClosingIsHooked(), "Closing event is not hooked");
            Assert.IsTrue(innerChannel.ClosedIsHooked(), "Closed event is not hooked");
            Assert.IsTrue(innerChannel.FaultedIsHooked(), "Faulted event is not hooked");
        }
Esempio n. 30
0
        public TelemetryClient Build(Action <ITelemetry> sendTelemetryAction)
        {
            var channel = new TestTelemetryChannel(sendTelemetryAction);
            var telemetryConfiguration = new TelemetryConfiguration(Guid.NewGuid().ToString(), channel);

            foreach (var initializer in _initializers)
            {
                telemetryConfiguration.TelemetryInitializers.Add(initializer);
            }
            foreach (var module in _telemetryModules)
            {
                module.Initialize(telemetryConfiguration);
            }
            return(new TelemetryClient(telemetryConfiguration));
        }