Пример #1
0
 /// <summary>
 /// Create instance of report data
 /// </summary>
 /// <param name="report">Current report</param>
 /// <param name="scopedAttributes">BacktraceClient's attributes</param>
 public BacktraceData(BacktraceReportBase <T> report, Dictionary <string, T> scopedAttributes)
 {
     _report = report;
     _backtraceAttributes = new BacktraceAttributes <T>(_report, scopedAttributes);
     //reading exception stack
     _exceptionStack = _report.GetExceptionStack();
     ThreadData      = new ThreadData(report.CallingAssembly, _exceptionStack);
 }
Пример #2
0
        /// <summary>
        /// Create instance of Backtrace Attribute
        /// </summary>
        /// <param name="report">Received report</param>
        /// <param name="scopedAttributes">Client's attributes (report and client)</param>
        public BacktraceAttributes(BacktraceReportBase <T> report, Dictionary <string, T> scopedAttributes)
        {
            //Environment attributes override user attributes
            ConvertAttributes(report, scopedAttributes);
            //A unique identifier of a machine
            Attributes["guid"] = GenerateMachineId().ToString();
            //Base name of application generating the report
            Attributes["application"] = report.CallingAssembly.GetName().Name;
            Attributes["lang.name"]   = "C#";

            SetMachineAttributes();
            SetProcessAttributes();
            SetExceptionAttributes(report);
        }
Пример #3
0
 /// <summary>
 /// Check if user can send new report to a Backtrace API
 /// </summary>
 /// <param name="report">Current report</param>
 /// <returns>true if user can add a new report</returns>
 public bool WatchReport(BacktraceReportBase <T> report)
 {
     System.Diagnostics.Trace.WriteLine($"{report.Message} : {report.Timestamp}");
     if (!_watcherEnable)
     {
         return(true);
     }
     //clear all reports older than _queReportTime
     Clear();
     if (_reportQue.Count + 1 > _reportPerSec)
     {
         return(false);
     }
     _reportQue.Enqueue(report.Timestamp);
     return(true);
 }
Пример #4
0
        /// <summary>
        /// Convert custom user attributes
        /// </summary>
        /// <param name="report">Received report</param>
        /// <param name="clientAttributes">Client's attributes (report and client)</param>
        /// <returns>Dictionary of custom user attributes </returns>
        private void ConvertAttributes(BacktraceReportBase <T> report, Dictionary <string, T> clientAttributes)
        {
            var attributes = BacktraceReportBase <T> .ConcatAttributes(report, clientAttributes);

            foreach (var attribute in attributes)
            {
                var type = attribute.Value.GetType();
                if (type.IsPrimitive || type == typeof(string))
                {
                    Attributes.Add(attribute.Key, attribute.Value);
                }
                else
                {
                    ComplexAttributes.Add(attribute.Key, attribute.Value);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Set attributes from exception
        /// </summary>
        internal void SetExceptionAttributes(BacktraceReportBase <T> report)
        {
            //there is no information to analyse
            if (report == null)
            {
                return;
            }
            if (!report.ExceptionTypeReport)
            {
                Attributes["error.message"] = report.Message;
                return;
            }
            var exception = report.Exception;

            Attributes["classifier"]    = exception.GetType().FullName;
            Attributes["error.message"] = exception.Message;
        }
Пример #6
0
        public void TestAttributesCreation()
        {
            var report = new BacktraceReportBase <string>("testMessage");

            //test object creation
            Assert.DoesNotThrow(() => new BacktraceAttributes <string>(report, null));

            //test empty exception
            Assert.DoesNotThrow(() =>
            {
                var backtraceAttributes = new BacktraceAttributes <string>(report, new Dictionary <string, string>());
                backtraceAttributes.SetExceptionAttributes(new BacktraceReportBase <string>("message"));
            });
            //test null
            Assert.DoesNotThrow(() =>
            {
                var backtraceAttributes = new BacktraceAttributes <string>(report, new Dictionary <string, string>());
                backtraceAttributes.SetExceptionAttributes(null);
            });
        }
        /// <summary>
        /// Create new minidump file in database directory path. Minidump file name is a random Guid
        /// </summary>
        /// <param name="backtraceReport">Current report</param>
        /// <param name="miniDumpType">Generated minidump type</param>
        /// <returns>Path to minidump file</returns>
        public string GenerateMiniDump(BacktraceReportBase <T> backtraceReport, MiniDumpType miniDumpType)
        {
            if (!_enable)
            {
                return(string.Empty);
            }
            //note that every minidump file generated by app ends with .dmp extension
            //its important information if you want to clear minidump file
            string            minidumpDestinationPath = Path.Combine(_directoryPath, $"{Guid.NewGuid()}.dmp");
            MinidumpException minidumpExceptionType   = backtraceReport.ExceptionTypeReport
                ? MinidumpException.Present
                : MinidumpException.None;

            bool minidumpSaved = MinidumpHelper.Write(
                filePath: minidumpDestinationPath,
                options: miniDumpType,
                exceptionType: minidumpExceptionType);

            if (minidumpSaved)
            {
                return(minidumpDestinationPath);
            }
            return(string.Empty);
        }