コード例 #1
0
        public void OperationMarksRequestAsFailedAndIsPropagated()
        {
            TestTelemetryChannel.Clear();
            var host = new HostingContext <SimpleService, ISimpleService>();

            using (host)
            {
                host.Open();

                ISimpleService client = host.GetChannel();
                client.CallMarksRequestAsFailed();
            }

            var request = TestTelemetryChannel.CollectedData().OfType <RequestTelemetry>().First();

            Assert.IsFalse(request.Success.Value);
        }
コード例 #2
0
        public void TelemetryContextIsFlowedAccrossAsyncCalls()
        {
            TestTelemetryChannel.Clear();
            using (var host = new HostingContext <AsyncService, IAsyncService>())
            {
                host.Open();
                IAsyncService client = host.GetChannel();
                client.WriteDependencyEventAsync().Wait();
            }
            var data    = TestTelemetryChannel.CollectedData();
            var request = data
                          .OfType <RequestTelemetry>()
                          .First();
            var dependency = data
                             .OfType <DependencyTelemetry>()
                             .FirstOrDefault();

            Assert.AreEqual(request.Context.Operation.Id, dependency.Context.Operation.Id);
            Assert.AreEqual(request.Context.Operation.Name, dependency.Context.Operation.Name);
        }
コード例 #3
0
        public void CallWithUnknownActionReportsCatchAllOperation()
        {
            TestTelemetryChannel.Clear();
            var host = new HostingContext <SimpleService, ISimpleService>();

            using ( host )
            {
                host.Open();

                ISimpleService client = host.GetChannel();
                using (OperationContextScope scope = new OperationContextScope((IContextChannel)client))
                {
                    OperationContext.Current.OutgoingMessageHeaders.Action = "http://someaction";
                    client.CatchAllOperation();
                }
            }
            var evt = TestTelemetryChannel.CollectedData().First();

            Assert.AreEqual("ISimpleService.CatchAllOperation", evt.Context.Operation.Name);
        }
コード例 #4
0
        public void CallCanFlowRootOperationId()
        {
            TestTelemetryChannel.Clear();
            var host = new HostingContext <SelectiveTelemetryService, ISelectiveTelemetryService>();

            using ( host )
            {
                host.Open();

                ISelectiveTelemetryService client = host.GetChannel();
                using (var scope = new OperationContextScope((IContextChannel)client))
                {
                    var rootId = new RootIdMessageHeader();
                    rootId.RootId = "rootId";
                    OperationContext.Current.OutgoingMessageHeaders.Add(rootId);
                    client.OperationWithTelemetry();
                }
            }
            Assert.AreEqual("rootId", TestTelemetryChannel.CollectedData().First().Context.Operation.Id);
        }
コード例 #5
0
        public void ErrorTelemetryEventsWrittenFromMethodAreLogged()
        {
            TestTelemetryChannel.Clear();
            var host = new HostingContext <SimpleService, ISimpleService>();

            using ( host )
            {
                host.Open();

                ISimpleService client = host.GetChannel();
                client.CallWritesExceptionEvent();
            }
            var request = TestTelemetryChannel.CollectedData().OfType <RequestTelemetry>().First();
            var errors  = from item in TestTelemetryChannel.CollectedData()
                          where item is ExceptionTelemetry
                          select item;

            Assert.IsTrue(errors.Count() > 0);
            Assert.AreEqual(request.Id, errors.First().Context.Operation.Id);
        }
コード例 #6
0
        public void TelemetryEventsEmittedInsideServiceCallContainExpectedContext()
        {
            TestTelemetryChannel.Clear();
            using (var host = new HostingContext <SimpleService, ISimpleService>())
            {
                host.Open();
                ISimpleService client = host.GetChannel();
                client.CallThatEmitsEvent();

                var data    = TestTelemetryChannel.CollectedData();
                var request = data
                              .OfType <RequestTelemetry>()
                              .First();
                var customEvent = data
                                  .OfType <EventTelemetry>()
                                  .FirstOrDefault();
                Assert.IsNotNull(customEvent);
                Assert.AreEqual(request.Context.Operation.Id, customEvent.Context.Operation.Id);
                Assert.AreEqual(request.Context.Operation.Name, customEvent.Context.Operation.Name);
            }
        }
コード例 #7
0
        public void FailedOneWayCallGeneratesExceptionEvent()
        {
            TestTelemetryChannel.Clear();
            var host = new HostingContext <OneWayService, IOneWayService>()
                       .ExpectFailure();

            using ( host )
            {
                host.Open();
                IOneWayService client = host.GetChannel();
                try
                {
                    client.FailureOneWayCall();
                } catch
                {
                }
            }
            var req = TestTelemetryChannel.CollectedData()
                      .FirstOrDefault(x => x is ExceptionTelemetry);

            Assert.IsNotNull(req);
        }
コード例 #8
0
        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);
        }
コード例 #9
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();
     }
 }
コード例 #10
0
        public void ErrorTelemetryEventsAreGeneratedOnFault()
        {
            TestTelemetryChannel.Clear();
            var host = new HostingContext <SimpleService, ISimpleService>()
                       .ShouldWaitForCompletion();

            using ( host )
            {
                host.Open();
                ISimpleService client = host.GetChannel();
                try
                {
                    client.CallFailsWithFault();
                } catch
                {
                }
            }
            var errors = from item in TestTelemetryChannel.CollectedData()
                         where item is ExceptionTelemetry
                         select item;

            Assert.IsTrue(errors.Count() > 0);
        }