private void Context_Error(object sender, EventArgs e) { if (sender is not HttpApplication httpApplication || httpApplication.Context == null || httpApplication.Context.AllErrors == null || httpApplication.Context.AllErrors.Length == 0 ) { return; } AggregateException exception = new("RollbarHttpModule's context error(s)", httpApplication.Context.AllErrors); IRollbarPackage package = new ExceptionPackage(exception, "HttpApplication.Context.AllErrors", true); // The HttpContext decorator already takes care of the HttpRequest and HttpResponse internally: package = new HttpContextPackageDecorator(package, httpApplication.Context); if (httpApplication.User?.Identity != null && !string.IsNullOrWhiteSpace(httpApplication.User.Identity.Name)) { package = new PersonPackageDecorator(package, httpApplication.User.Identity.Name, httpApplication.User.Identity.Name, null); } this._rollbar.Error(package); }
private void Context_Error(object sender, EventArgs e) { HttpApplication httpApplication = sender as HttpApplication; if (httpApplication == null || httpApplication.Context == null || httpApplication.Context.AllErrors == null || httpApplication.Context.AllErrors.Length == 0 ) { return; } // potential objects to snap as a Rollbar payload: //************************************************ //httpApplication.Context.AllErrors; //httpApplication.Context; //httpApplication.Request; //httpApplication.Response; //httpApplication.Session; //httpApplication.User; //httpApplication.Server; //httpApplication.Application; //httpApplication.Modules; AggregateException exception = new AggregateException("RollbarHttpModule's context error(s)", httpApplication.Context.AllErrors); IRollbarPackage package = new ExceptionPackage(exception, "HttpApplication.Context.AllErrors", true); // The HttpContext decorator already takes care of the HttpRequest and HttpResponse internally: package = new HttpContextPackageDecorator(package, httpApplication.Context); if (httpApplication.User?.Identity != null && !string.IsNullOrWhiteSpace(httpApplication.User.Identity.Name)) { package = new PersonPackageDecorator(package, httpApplication.User.Identity.Name, httpApplication.User.Identity.Name, null); } this._rollbar.Error(package); }
public void PersonPackageDecoratorTest() { const string rollbarDataTitle = "Let's test some strategy decoration..."; const string exceptionMessage = "Someone forgot null-test!"; System.Exception exception = new NullReferenceException(exceptionMessage); IRollbarPackage packagingStrategy = new ExceptionPackage(exception, rollbarDataTitle); Assert.IsFalse(packagingStrategy.MustApplySynchronously, "Expected to be an async strategy!"); Data rollbarData = packagingStrategy.PackageAsRollbarData(); Assert.AreEqual(rollbarDataTitle, rollbarData.Title, "Data title is properly set!"); Assert.IsNotNull(rollbarData.Body); Assert.IsNotNull(rollbarData.Body.Trace); Assert.IsNull(rollbarData.Body.Message); Assert.IsNull(rollbarData.Body.TraceChain); Assert.IsNull(rollbarData.Body.CrashReport); Assert.IsNotNull(rollbarData.Body.Trace.Exception); Assert.AreEqual(exceptionMessage, rollbarData.Body.Trace.Exception.Message); Assert.AreEqual(exception.GetType().FullName, rollbarData.Body.Trace.Exception.Class); Assert.IsTrue(rollbarData.Timestamp.HasValue); long initialTimestamp = rollbarData.Timestamp.Value; const string personID = "007"; const string personUsername = "******"; const string personEmail = "*****@*****.**"; packagingStrategy = new PersonPackageDecorator(packagingStrategy, personID, personUsername, personEmail); // All the asserts prior to the decoration should be good again: Assert.IsFalse(packagingStrategy.MustApplySynchronously, "Expected to be an async strategy!"); rollbarData = packagingStrategy.PackageAsRollbarData(); Assert.AreEqual(rollbarDataTitle, rollbarData.Title, "Data title is properly set!"); Assert.IsNotNull(rollbarData.Body); Assert.IsNotNull(rollbarData.Body.Trace); Assert.IsNull(rollbarData.Body.Message); Assert.IsNull(rollbarData.Body.TraceChain); Assert.IsNull(rollbarData.Body.CrashReport); Assert.IsNotNull(rollbarData.Body.Trace.Exception); Assert.AreEqual(exceptionMessage, rollbarData.Body.Trace.Exception.Message); Assert.AreEqual(exception.GetType().FullName, rollbarData.Body.Trace.Exception.Class); // Person decoration specific asserts: Assert.IsNotNull(rollbarData.Person); Assert.AreEqual(personID, rollbarData.Person.Id); Assert.AreEqual(personUsername, rollbarData.Person.UserName); Assert.AreEqual(personEmail, rollbarData.Person.Email); // Make sure the Data.Timestamp was not overwritten: Assert.IsTrue(rollbarData.Timestamp.HasValue); Assert.AreEqual(initialTimestamp, rollbarData.Timestamp.Value); System.Diagnostics.Debug.WriteLine($"Initial timestamp: {initialTimestamp}"); System.Diagnostics.Debug.WriteLine($"Decorated timestamp: {rollbarData.Timestamp.Value}"); }