public void InProjectTest(string[] projectNamespaces, StackTraceInProjectTestCase[] testCases) { var configuration = new Configuration("123456") { ProjectNamespaces = projectNamespaces }; var report = new Report(configuration, new System.Exception(), HandledState.ForHandledException(), new Breadcrumb[0], new Session()); foreach (var exception in report.Event.Exceptions) { exception["stacktrace"] = testCases .Select(t => new StackTraceLine(null, 0, t.MethodName, false, null)) .ToArray(); } InternalMiddleware.DetectInProjectNamespaces(report); foreach (var exception in report.Event.Exceptions) { foreach (var stackTraceLine in exception.StackTrace) { foreach (var testCase in testCases) { if (stackTraceLine.MethodName == testCase.MethodName) { Assert.Equal(testCase.ShouldBeMarkedAsInProject, stackTraceLine.InProject); } } } } }
/// <summary> /// The default handler to use when we receive unmanaged exceptions /// </summary> /// <param name="exception">The exception to handle</param> /// <param name="runtimeEnding">True if the unmanaged exception handler indicates that the runtime will end</param> protected void HandleDefaultException(Exception exception, bool runtimeEnding) { var handledState = new HandledState(SeverityReason.UnhandledException); var error = new Event(exception, runtimeEnding, handledState); Notify(error); }
public void UnhandledExceptionPayloadIsCorrect() { var handledState = HandledState.ForUnhandledException(); Assert.True((bool)handledState["unhandled"]); Assert.Equal("error", handledState["severity"]); Assert.Equal(Severity.Error, handledState.Severity); }
public void HandledExceptionPayloadIsCorrect() { var handledState = HandledState.ForHandledException(); Assert.False((bool)handledState["unhandled"]); Assert.Equal("warning", handledState["severity"]); Assert.Equal(Severity.Warning, handledState.Severity); }
public void UserSpecifiedSeverityPayloadIsCorrect() { const Severity warning = Severity.Warning; var handledState = HandledState.ForUserSpecifiedSeverity(warning); Assert.False((bool)handledState["unhandled"]); Assert.Equal("warning", handledState["severity"]); Assert.Equal(warning, handledState.Severity); }
public void NonThrownException() { System.Exception exception = new System.Exception("test"); var configuration = new Configuration("123456"); var report = new Report(configuration, exception, HandledState.ForHandledException(), new Breadcrumb[] { new Breadcrumb("test", BreadcrumbType.Manual) }, new Session()); Assert.NotNull(report); }
void Notify(System.Exception exception, HandledState handledState, Middleware callback, int level) { // we need to generate a substitute stacktrace here as if we are not able // to generate one from the exception that we are given then we are not able // to do this inside of the IEnumerator generator code var substitute = new System.Diagnostics.StackTrace(level, true).GetFrames(); Notify(new Exceptions(exception, substitute).ToArray(), handledState, callback, null); }
public void CallbackSpecifiedSeverityPayloadIsCorrect() { var originalHandledState = HandledState.ForUnhandledException(); const Severity info = Severity.Info; var handledState = HandledState.ForCallbackSpecifiedSeverity(info, originalHandledState); Assert.True((bool)handledState["unhandled"]); // same as the original severity Assert.Equal("info", handledState["severity"]); Assert.Equal(info, handledState.Severity); }
public void ContextIsSetByRequest(Request request, string existingContext, string expectedContext) { var configuration = new Configuration("123456"); var report = new Report(configuration, new System.Exception(), HandledState.ForHandledException(), new Breadcrumb[0], new Session()); report.Event.Context = existingContext; report.Event.Request = request; Assert.Equal(expectedContext, report.Event.Context); }
public void IgnoreClassesTest(System.Exception thrownException, Type ignoreClass, bool ignored) { var configuration = new Configuration("123456") { IgnoreClasses = new[] { ignoreClass } }; var report = new Report(configuration, thrownException, HandledState.ForHandledException(), new Breadcrumb[0], new Session()); InternalMiddleware.CheckIgnoreClasses(report); Assert.Equal(ignored, report.Ignored); }
public void DetermineDefaultContextTests(string requestUrl, string expectedContext) { var configuration = new Configuration("123456"); var report = new Report(configuration, new System.Exception(), HandledState.ForHandledException(), new Breadcrumb[0], new Session()); report.Event.Request = new Request { Url = requestUrl }; InternalMiddleware.DetermineDefaultContext(report); Assert.Equal(expectedContext, report.Event.Context); }
public void SeverityCanBeRetrieved(Severity severity) { var app = new App("version", "releaseStage", "type"); var device = new Device("hostname"); var exception = new System.DllNotFoundException(); var breadcrumbs = Enumerable.Empty <Breadcrumb>(); var session = new Session(); var handledState = HandledState.ForUserSpecifiedSeverity(severity); var @event = new Event("1", app, device, exception, handledState, breadcrumbs, session); Assert.Equal(severity, @event.Severity); }
public void ContainsTheRequiredKeys() { var configuration = new Configuration("123456"); var exception = new DllNotFoundException(); var severity = HandledState.ForUnhandledException(); var breadcrumbs = new Breadcrumb[0]; var session = new Session(); var @event = new Report(configuration, exception, severity, breadcrumbs, session); Assert.Equal(configuration.ApiKey, @event["apiKey"]); Assert.NotNull(@event["notifier"]); Assert.NotNull(@event["events"]); }
public void SeverityCanBeUpdated(Severity originalSeverity, Severity updatedSeverity) { var app = new App("version", "releaseStage", "type"); var device = new Device("hostname"); var exception = new System.DllNotFoundException(); var breadcrumbs = Enumerable.Empty <Breadcrumb>(); var session = new Session(); var handledState = HandledState.ForUserSpecifiedSeverity(originalSeverity); var @event = new Event("1", app, device, exception, handledState, breadcrumbs, session); @event.Severity = updatedSeverity; Assert.Equal(updatedSeverity, @event.Severity); Assert.Contains("severityReason", @event.Keys); }
public void BasicTest() { System.Exception exception = null; var configuration = new Configuration("123456"); try { throw new System.Exception("test"); } catch (System.Exception caughtException) { exception = caughtException; } var report = new Report(configuration, exception, HandledState.ForHandledException(), new Breadcrumb[] { new Breadcrumb("test", BreadcrumbType.Manual) }, new Session()); Assert.NotNull(report); }
public void LargePaylaodsDropBreadcrumbsAndMetadata() { var configuration = new Configuration("123456"); var exception = new DllNotFoundException(); var severity = HandledState.ForUnhandledException(); var breadcrumbs = new Breadcrumb[] { new Breadcrumb("wow bread!", BreadcrumbType.Manual) }; var session = new Session(); var report = new Report(configuration, exception, severity, breadcrumbs, session); report.Event.Metadata.Add("small metadat", "so small"); report.Event.Metadata.Add("large metadata", new String('a', (1024 * 1024))); var data = report.Serialize(); Assert.NotNull(data); Assert.Null(report.Event.Breadcrumbs); Assert.Single(report.Event.Metadata); }
public void ProjectRootStrippingTests(string[] projectRoots, string fileName, string expectedFileName) { var configuration = new Configuration("123456") { ProjectRoots = projectRoots }; var report = new Report(configuration, new System.Exception(), HandledState.ForHandledException(), new Breadcrumb[0], new Session()); foreach (var exception in report.Event.Exceptions) { var stacktrace = new StackTraceLine[] { new StackTraceLine(fileName, 1, string.Empty, false, null) }; exception["stacktrace"] = stacktrace; } InternalMiddleware.RemoveProjectRoots(report); foreach (var exception in report.Event.Exceptions) { foreach (var stacktraceline in exception.StackTrace) { Assert.Equal(expectedFileName, stacktraceline.FileName); } } }
internal void Notify(System.Exception exception, Severity severity, Middleware callback, int level) { Notify(exception, HandledState.ForUserSpecifiedSeverity(severity), callback, level); }
internal void Notify(System.Exception exception, int level) { Notify(exception, HandledState.ForHandledException(), null, level); }
internal void Notify(System.Exception exception, Middleware callback, int level) { Notify(exception, HandledState.ForHandledException(), callback, level); }
void Notify(Exception[] exceptions, HandledState handledState, Middleware callback, LogType?logType) { if (!ShouldSendRequests()) { return; // Skip overhead of computing payload to to ultimately not be sent } var user = new User { Id = User.Id, Email = User.Email, Name = User.Name }; var app = new App(Configuration) { InForeground = InForeground, DurationInForeground = ForegroundStopwatch.Elapsed, }; NativeClient.PopulateApp(app); var device = new Device(); NativeClient.PopulateDevice(device); device.AddRuntimeVersions(Configuration); var metadata = new Metadata(); NativeClient.PopulateMetadata(metadata); foreach (var item in Metadata) { metadata.AddToPayload(item.Key, item.Value); } metadata.AddToPayload(UnityMetadataKey, UnityMetadata.WithLogType(logType)); var @event = new Payload.Event( Configuration.Context, metadata, app, device, user, exceptions, handledState, Breadcrumbs.Retrieve(), SessionTracking.CurrentSession); var report = new Report(Configuration, @event); lock (MiddlewareLock) { foreach (var middleware in Middleware) { try { middleware(report); } catch (System.Exception) { } } } try { callback?.Invoke(report); } catch (System.Exception) { } if (!report.Ignored) { Send(report); Breadcrumbs.Leave(Breadcrumb.FromReport(report)); SessionTracking.AddException(report); } }
internal void Notify(System.Exception exception, Severity severity, int level) { Notify(exception, HandledState.ForUserSpecifiedSeverity(severity), null, level); }
void Notify(Exception[] exceptions, HandledState handledState, Middleware callback, LogType?logType) { var user = new User { Id = User.Id, Email = User.Email, Name = User.Name }; var app = new App(Configuration) { InForeground = InForeground, DurationInForeground = Stopwatch.Elapsed, }; NativeClient.PopulateApp(app); var device = new Device(); NativeClient.PopulateDevice(device); var metadata = new Metadata(); NativeClient.PopulateMetadata(metadata); foreach (var item in Metadata) { metadata.AddToPayload(item.Key, item.Value); } metadata.AddToPayload(UnityMetadataKey, UnityMetadata.WithLogType(logType)); var @event = new Payload.Event( Configuration.Context, metadata, app, device, user, exceptions, handledState, Breadcrumbs.Retrieve(), SessionTracking.CurrentSession); var report = new Report(Configuration, @event); if (report.Configuration.ReleaseStage != null && report.Configuration.NotifyReleaseStages != null && !report.Configuration.NotifyReleaseStages.Contains(report.Configuration.ReleaseStage)) { return; } lock (MiddlewareLock) { foreach (var middleware in Middleware) { try { middleware(report); } catch (System.Exception) { } } } try { callback?.Invoke(report); } catch (System.Exception) { } if (!report.Ignored) { Send(report); Breadcrumbs.Leave(Breadcrumb.FromReport(report)); SessionTracking.AddException(report); } }