public void Should_remove_AT_from_stacktrace_to_avoid_multi_language_issues() { var exceptionWithAt = new ErrorReportException() { StackTrace = @"at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Coderr.Server.Infrastructure.Configuration.Database.DatabaseStore.Store(IConfigurationSection section) at Coderr.Server.Premise.App.LicenseWrapper.IncreaseReportCount() at Coderr.Server.Web.Controllers.ReportReceiverController.PremiseLicenseCheck() at Coderr.Server.Web.Controllers.ReportReceiverController.Post(String appKey, String sig) at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at System.Threading.Tasks.ValueTask`1.get_Result() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync():55 at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync():33" }; var entityWithAt = new ErrorReportEntity(1, "flldfd", DateTime.UtcNow, exceptionWithAt, new ErrorReportContextCollection[0]); var exceptionWithoutAt = new ErrorReportException() { StackTrace = @"System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName) System.Data.SqlClient.SqlCommand.ExecuteNonQuery() Coderr.Server.Infrastructure.Configuration.Database.DatabaseStore.Store(IConfigurationSection section) Coderr.Server.Premise.App.LicenseWrapper.IncreaseReportCount() Coderr.Server.Web.Controllers.ReportReceiverController.PremiseLicenseCheck() Coderr.Server.Web.Controllers.ReportReceiverController.Post(String appKey, String sig) Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) System.Threading.Tasks.ValueTask`1.get_Result() Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync():55 Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync() Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync() Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync():33" }; var entityWithoutAt = new ErrorReportEntity(1, "flldfd", DateTime.UtcNow, exceptionWithoutAt, new ErrorReportContextCollection[0]); var sut = new HashCodeGenerator(new IHashCodeSubGenerator[0]); var result1 = sut.GenerateHashCode(entityWithAt); var result2 = sut.GenerateHashCode(entityWithAt); result1.HashCode.Should().Be(result2.HashCode); }
public void should_match_line_numbers_and_without_line_numbers_to_reduce_the_number_of_incidents() { var ex1 = new ErrorReportException { StackTrace = @"at System.Web.Compilation.AssemblyBuilder.Compile():line 64 at System.Web.Compilation.BuildProvidersCompiler.PerformBuild():line 65 at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath):line 67" }; var ex2 = new ErrorReportException { StackTrace = @"at System.Web.Compilation.AssemblyBuilder.Compile() at System.Web.Compilation.BuildProvidersCompiler.PerformBuild() at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)" }; var report1 = new ErrorReportEntity(1, "fjkkfjjkf", DateTime.UtcNow, ex1, new List <ErrorReportContextCollection>()); var report2 = new ErrorReportEntity(1, "fjkkfjjkf", DateTime.UtcNow, ex2, new List <ErrorReportContextCollection>()); var sut = new HashCodeGenerator(new IHashCodeSubGenerator[0]); var actual1 = sut.GenerateHashCode(report1); var actual2 = sut.GenerateHashCode(report2); actual1.Should().Be(actual2); }
public void should_strip_line_numbers_to_reduce_the_number_of_incidents() { var locator = Substitute.For <IServiceLocator>(); var ex1 = new ErrorReportException { StackTrace = @" at System.Web.Compilation.AssemblyBuilder.Compile():line 64 at System.Web.Compilation.BuildProvidersCompiler.PerformBuild():line 65 at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath):line 67" }; var ex2 = new ErrorReportException { StackTrace = @" at System.Web.Compilation.AssemblyBuilder.Compile():line 12 at System.Web.Compilation.BuildProvidersCompiler.PerformBuild():line 23 at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath):line 53" }; var report1 = new ErrorReportEntity(1, "fjkkfjjkf", DateTime.UtcNow, ex1, new List <ErrorReportContext>()); var report2 = new ErrorReportEntity(1, "fjkkfjjkf", DateTime.UtcNow, ex2, new List <ErrorReportContext>()); var sut = new HashCodeGenerator(locator); var actual1 = sut.GenerateHashCode(report1); var actual2 = sut.GenerateHashCode(report2); actual1.Should().Be(actual2); }
/// <summary> /// Analyze report /// </summary> /// <param name="report">report</param> /// <exception cref="ArgumentNullException">report</exception> public void Analyze(ErrorReportEntity report) { if (report == null) { throw new ArgumentNullException("report"); } var exists = _repository.ExistsByClientId(report.ClientReportId); if (exists) { _logger.Warn("Report have already been uploaded: " + report.ClientReportId); return; } try { var hashCode = _hashCodeGenerator.GenerateHashCode(report); report.Init(hashCode); } catch (Exception ex) { _logger.Fatal("Failed to store report " + JsonConvert.SerializeObject(report), ex); return; } var isReOpened = false; var firstLine = report.GenerateHashCodeIdentifier(); var incident = _repository.FindIncidentForReport(report.ApplicationId, report.ReportHashCode, firstLine); if (incident == null) { incident = BuildIncident(report); _repository.CreateIncident(incident); } else { if (incident.ReportCount > 10000) { _logger.Debug("Reportcount is more than 10000. Ignoring report for incident " + incident.Id); return; } if (incident.IsIgnored) { _logger.Info("Incident is ignored: " + JsonConvert.SerializeObject(report)); incident.WasJustIgnored(); _repository.UpdateIncident(incident); return; } if (incident.IsSolved) { isReOpened = true; incident.ReOpen(); _eventBus.PublishAsync(new IncidentReOpened(incident.ApplicationId, incident.Id, incident.CreatedAtUtc)); } incident.AddReport(report); _repository.UpdateIncident(incident); } report.IncidentId = incident.Id; _repository.CreateReport(report); _logger.Debug("saving report " + report.Id + " for incident " + incident.Id); var appName = _repository.GetAppName(incident.ApplicationId); var summary = new IncidentSummaryDTO(incident.Id, incident.Description) { ApplicationId = incident.ApplicationId, ApplicationName = appName, CreatedAtUtc = incident.CreatedAtUtc, LastUpdateAtUtc = incident.UpdatedAtUtc, IsReOpened = incident.IsReOpened, Name = incident.Description, ReportCount = incident.ReportCount }; var sw = new Stopwatch(); sw.Start(); _logger.Debug("Publishing now: " + report.ClientReportId); var e = new ReportAddedToIncident(summary, ConvertToCoreReport(report), isReOpened); _eventBus.PublishAsync(e); if (sw.ElapsedMilliseconds > 200) { _logger.Debug("Publish took " + sw.ElapsedMilliseconds); } sw.Stop(); }