/// <summary> /// Sets the current context to the scene name and leaves a breadcrumb with /// the current scene information. /// </summary> /// <param name="scene"></param> /// <param name="loadSceneMode"></param> void SceneLoaded(Scene scene, LoadSceneMode loadSceneMode) { Configuration.Context = scene.name; Breadcrumbs.Leave("Scene Loaded", BreadcrumbType.State, new Dictionary <string, string> { { "sceneName", scene.name } }); }
/// <summary> /// Notify a Unity log message if it the client has been configured to /// notify at the specified level, if not leave a breadcrumb with the log /// message. /// </summary> /// <param name="condition"></param> /// <param name="stackTrace"></param> /// <param name="logType"></param> void Notify(string condition, string stackTrace, LogType logType) { if (Configuration.AutoNotify && logType.IsGreaterThanOrEqualTo(Configuration.NotifyLevel)) { var logMessage = new UnityLogMessage(condition, stackTrace, logType); if (UniqueCounter.ShouldSend(logMessage)) { if (LogTypeCounter.ShouldSend(logMessage)) { var severity = Configuration.LogTypeSeverityMapping.Map(logType); var backupStackFrames = new System.Diagnostics.StackTrace(1, true).GetFrames(); var forceUnhandled = logType == LogType.Exception && !Configuration.ReportUncaughtExceptionsAsHandled; var exception = Exception.FromUnityLogMessage(logMessage, backupStackFrames, severity, forceUnhandled); Notify(new Exception[] { exception }, exception.HandledState, null, logType); } } } else { Breadcrumbs.Leave(logType.ToString(), BreadcrumbType.Log, new Dictionary <string, string> { { "message", condition }, }); } }
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); } }
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); } }