Beispiel #1
0
        public void TelemetryInternalApiSample()
        {
            var reqId = _telemetryManager.GenerateNewRequestId();

            try
            {
                var e1 = new ApiEvent(new MsalLogger(Guid.NewGuid(), null))
                {
                    Authority = new Uri("https://login.microsoftonline.com"), AuthorityType = "Aad"
                };
                _telemetryManager.StartEvent(reqId, e1);
                // do some stuff...
                e1.WasSuccessful = true;
                _telemetryManager.StopEvent(reqId, e1);

                var e2 = new HttpEvent()
                {
                    HttpPath = new Uri("https://contoso.com"), UserAgent = "SomeUserAgent", QueryParams = "?a=1&b=2"
                };
                _telemetryManager.StartEvent(reqId, e2);
                // do some stuff...
                e2.HttpResponseStatus = 200;
                _telemetryManager.StopEvent(reqId, e2);
            }
            finally
            {
                _telemetryManager.Flush(reqId, ClientId);
            }
            Assert.IsTrue(_myReceiver.EventsReceived.Count > 0);
        }
Beispiel #2
0
        public void TelemetrySkipEventsIfApiEventWasSuccessful()
        {
            var myReceiver = new MyReceiver
            {
                OnlySendFailureTelemetry = true
            };

            var telemetryManager = new TelemetryManager(myReceiver);
            var telemetry        = (ITelemetry)telemetryManager;

            var reqId = telemetryManager.GenerateNewRequestId();

            try
            {
                var e1 = new ApiEvent(new MsalLogger(Guid.NewGuid(), null))
                {
                    Authority = new Uri("https://login.microsoftonline.com"), AuthorityType = "Aad"
                };
                telemetry.StartEvent(reqId, e1);
                // do some stuff...
                e1.WasSuccessful = true;
                telemetry.StopEvent(reqId, e1);

                var e2 = new UiEvent()
                {
                    UserCancelled = false
                };
                telemetry.StartEvent(reqId, e2);
                telemetry.StopEvent(reqId, e2);

                var e3 = new UiEvent()
                {
                    AccessDenied = false
                };
                telemetry.StartEvent(reqId, e3);
                telemetry.StopEvent(reqId, e3);
            }
            finally
            {
                telemetry.Flush(reqId, ClientId);
            }
            Assert.AreEqual(0, myReceiver.EventsReceived.Count);

            reqId = telemetryManager.GenerateNewRequestId();
            try
            {
                var e1 = new ApiEvent(new MsalLogger(Guid.NewGuid(), null))
                {
                    Authority = new Uri("https://login.microsoftonline.com"), AuthorityType = "Aad"
                };
                telemetry.StartEvent(reqId, e1);
                // do some stuff...
                e1.WasSuccessful = false;  // mimic an unsuccessful event, so that this batch should be dispatched
                telemetry.StopEvent(reqId, e1);

                var e2 = new UiEvent()
                {
                    UserCancelled = true
                };
                telemetry.StartEvent(reqId, e2);
                telemetry.StopEvent(reqId, e2);

                var e3 = new UiEvent()
                {
                    AccessDenied = true
                };
                telemetry.StartEvent(reqId, e3);
                telemetry.StopEvent(reqId, e3);
            }
            finally
            {
                telemetry.Flush(reqId, ClientId);
            }
            Assert.IsTrue(myReceiver.EventsReceived.Count > 0);
        }