Ejemplo n.º 1
0
        private bool TrackException(EventData e, IReadOnlyCollection<EventMetadata> metadata)
        {
            Debug.Assert(metadata != null);
            bool tracked = false;

            foreach (EventMetadata exceptionMetadata in metadata)
            {
                var result = ExceptionData.TryGetData(e, exceptionMetadata, out ExceptionData exceptionData);
                if (result.Status != DataRetrievalStatus.Success)
                {
                    this.healthReporter.ReportWarning("ApplicationInsightsOutput: " + result.Message, EventFlowContextIdentifiers.Output);
                    continue;
                }

                var et = new ExceptionTelemetry();
                et.Exception = exceptionData.Exception;

                AddProperties(et, e);

                telemetryClient.TrackException(et);
                tracked = true;
            }

            return tracked;
        }
Ejemplo n.º 2
0
        public void ExceptionDataExpectedReadFailure()
        {
            // exceptionProperty points to non-existent property
            EventData eventData = new EventData();

            EventMetadata exceptionMetadata = new EventMetadata("exception");

            exceptionMetadata.Properties.Add("exceptionProperty", "exception");

            var result = ExceptionData.TryGetData(eventData, exceptionMetadata, out ExceptionData exceptionData);

            Assert.Equal(DataRetrievalStatus.DataMissingOrInvalid, result.Status);
            Assert.Contains("The expected event property 'exception'", result.Message);

            // exceptionProperty does not contain and Exception object
            eventData.Payload.Add("exception", Guid.NewGuid());
            result = ExceptionData.TryGetData(eventData, exceptionMetadata, out exceptionData);
            Assert.Equal(DataRetrievalStatus.DataMissingOrInvalid, result.Status);
            Assert.Contains("The expected event property 'exception'", result.Message);

            // Just make sure that after addressing all the issues you can read all the data successfully
            eventData.Payload["exception"] = new Exception();
            result = ExceptionData.TryGetData(eventData, exceptionMetadata, out exceptionData);
            Assert.Equal(DataRetrievalStatus.Success, result.Status);
        }
Ejemplo n.º 3
0
        private EventDataParsed ParseExceptionEvent(EventData eventData, EventMetadata exceptionMetadata)
        {
            var result = ExceptionData.TryGetData(eventData, exceptionMetadata, out ExceptionData exceptionData);

            if (result.Status != DataRetrievalStatus.Success)
            {
                _healthReporter.ReportProblem($"{nameof(SqlTableOutput)}: {result.Message}", EventFlowContextIdentifiers.Output);
                return(null);
            }

            var exceptionEventData = eventData.DeepClone();

            exceptionEventData.Payload[nameof(ExceptionData.Exception)] = exceptionData.Exception.ToString();
            return(new ExceptionDataParsed(exceptionEventData, ParseEventCustomProperties(eventData)));
        }
        private BulkIndexOperation <EventData> CreateExceptionOperation(EventData eventData, EventMetadata exceptionMetadata, string currentIndexName)
        {
            var result = ExceptionData.TryGetData(eventData, exceptionMetadata, out ExceptionData exceptionData);

            if (result.Status != DataRetrievalStatus.Success)
            {
                this.healthReporter.ReportProblem("ElasticSearchOutput: " + result.Message, EventFlowContextIdentifiers.Output);
                return(null);
            }

            var exceptionEventData = eventData.DeepClone();

            exceptionEventData.Payload[nameof(ExceptionData.Exception)] = exceptionData.Exception.ToString();
            var operation = CreateOperation(exceptionEventData, currentIndexName);

            return(operation);
        }
Ejemplo n.º 5
0
        public void AddsMetadataToExceptionTelemetry()
        {
            UnitTestOutput unitTestOutput = null;
            DateTimeOffset now            = DateTimeOffset.Now;

            using (var pipeline = DiagnosticPipelineFactory.CreatePipeline(diagnosticPipelineConfiguration_.Value))
            {
                unitTestOutput = pipeline.Sinks.First().Output as UnitTestOutput;

                TelemetryConfiguration      telemetryConfiguration = GetAppInsightsTestTelemetryConfiguration();
                EventFlowTelemetryProcessor efTelemetryProcessor   = telemetryConfiguration.DefaultTelemetrySink.TelemetryProcessors.OfType <EventFlowTelemetryProcessor>().First();
                efTelemetryProcessor.Pipeline = pipeline;

                TelemetryClient client = new TelemetryClient(telemetryConfiguration);

                try
                {
                    throw new Exception("Bummer!");
                }
                catch (Exception e)
                {
                    ExceptionTelemetry et = new ExceptionTelemetry(e);
                    et.Timestamp = now;
                    client.TrackException(et);
                }
            }

            Assert.Equal(1, unitTestOutput.EventCount);
            Assert.True(unitTestOutput.CapturedEvents.TryDequeue(out EventData eventData));
            Assert.Equal(now, eventData.Timestamp);

            Assert.True(eventData.TryGetMetadata(ExceptionData.ExceptionMetadataKind, out IReadOnlyCollection <EventMetadata> eventMetadata));
            Assert.Equal(1, eventMetadata.Count);

            EventMetadata exceptionMetadata = eventMetadata.ElementAt(0);

            Assert.Equal(DataRetrievalResult.Success, ExceptionData.TryGetData(eventData, exceptionMetadata, out ExceptionData exceptionData));

            Assert.Equal("Bummer!", exceptionData.Exception.Message);
        }
Ejemplo n.º 6
0
        public void ExceptionDataReadSuccessfully()
        {
            EventData eventData = new EventData();

            try
            {
                throw new Exception("Oops!");
            }
            catch (Exception e)
            {
                eventData.Payload.Add("exception", e);
            }

            EventMetadata exceptionMetadata = new EventMetadata("exception");

            exceptionMetadata.Properties.Add("exceptionProperty", "exception");

            var result = ExceptionData.TryGetData(eventData, exceptionMetadata, out ExceptionData exceptionData);

            Assert.Equal(DataRetrievalStatus.Success, result.Status);
            Assert.Equal("Oops!", exceptionData.Exception.Message);
        }