Beispiel #1
0
        /// <summary>
        /// Reload Backtrace database configuration. Reloading configuration is required, when you change
        /// BacktraceDatabase configuration options.
        /// </summary>
        public void Reload()
        {
            // validate configuration
            if (Configuration == null)
            {
                Configuration = GetComponent <BacktraceClient>().Configuration;
            }
            if (Configuration == null || !Configuration.IsValid())
            {
                Debug.LogWarning("Configuration doesn't exists or provided serverurl/token are invalid");
                Enable = false;
                return;
            }


            //setup database object
            DatabaseSettings = new BacktraceDatabaseSettings(Configuration);

            Enable = Configuration.Enabled && BacktraceConfiguration.ValidateDatabasePath(Configuration.DatabasePath);
            if (!Enable)
            {
                Debug.LogWarning("Cannot initialize database - invalid database configuration. Database is disabled");
                return;
            }
            CreateDatabaseDirectory();
            SetupMultisceneSupport();
            _lastConnection = Time.time;

            //Setup database context
            BacktraceDatabaseContext     = new BacktraceDatabaseContext(DatabasePath, DatabaseSettings.RetryLimit, DatabaseSettings.RetryOrder, DatabaseSettings.DeduplicationStrategy);
            BacktraceDatabaseFileContext = new BacktraceDatabaseFileContext(DatabasePath, DatabaseSettings.MaxDatabaseSize, DatabaseSettings.MaxRecordCount);
            BacktraceApi        = new BacktraceApi(Configuration.ToCredentials());
            _reportLimitWatcher = new ReportLimitWatcher(Convert.ToUInt32(Configuration.ReportPerMin));
        }
Beispiel #2
0
        public void Refresh()
        {
            if (Configuration == null || !Configuration.IsValid())
            {
                return;
            }

            if (Instance != null)
            {
                return;
            }

            Enabled = true;

            CaptureUnityMessages();
            _reportLimitWatcher = new ReportLimitWatcher(Convert.ToUInt32(Configuration.ReportPerMin));


            BacktraceApi = new BacktraceApi(
                credentials: new BacktraceCredentials(Configuration.GetValidServerUrl()),

#if UNITY_2018_4_OR_NEWER
                ignoreSslValidation: Configuration.IgnoreSslValidation
#else
                ignoreSslValidation: false
#endif
                );
            BacktraceApi.EnablePerformanceStatistics = Configuration.PerformanceStatistics;

            if (!Configuration.DestroyOnLoad)
            {
                DontDestroyOnLoad(gameObject);
                _instance = this;
            }
            if (Configuration.Enabled)
            {
                Database = GetComponent <BacktraceDatabase>();
                if (Database != null)
                {
                    Database.Reload();
                    Database.SetApi(BacktraceApi);
                    Database.SetReportWatcher(_reportLimitWatcher);
                }
            }

            _nativeClient = NativeClientFactory.GetNativeClient(Configuration, name);
            if (_nativeClient != null)
            {
                foreach (var attribute in _clientAttributes)
                {
                    _nativeClient.SetAttribute(attribute.Key, attribute.Value);
                }
            }
            if (Configuration.SendUnhandledGameCrashesOnGameStartup && isActiveAndEnabled)
            {
                var nativeCrashUplaoder = new NativeCrashUploader();
                nativeCrashUplaoder.SetBacktraceApi(BacktraceApi);
                StartCoroutine(nativeCrashUplaoder.SendUnhandledGameCrashesOnGameStartup());
            }
        }
Beispiel #3
0
        public void Refresh()
        {
            if (Configuration == null || !Configuration.IsValid())
            {
                return;
            }

            Enabled = true;
            Annotations.GameObjectDepth = Configuration.GameObjectDepth;
            HandleUnhandledExceptions();
            _reportLimitWatcher = new ReportLimitWatcher(Convert.ToUInt32(Configuration.ReportPerMin));


#if UNITY_2018_4_OR_NEWER
            BacktraceApi = new BacktraceApi(
                credentials: new BacktraceCredentials(Configuration.GetValidServerUrl()),
                ignoreSslValidation: Configuration.IgnoreSslValidation);
#else
            BacktraceApi = new BacktraceApi(new BacktraceCredentials(Configuration.GetValidServerUrl()));
#endif

            if (Configuration.DestroyOnLoad == false)
            {
                DontDestroyOnLoad(gameObject);
                _instance = this;
            }
            Database = GetComponent <BacktraceDatabase>();
            if (Database == null)
            {
                return;
            }
            Database.Reload();
            Database.SetApi(BacktraceApi);
            Database.SetReportWatcher(_reportLimitWatcher);
        }
        public void TestWatcherInitialization()
        {
            //watcher not work
            var  reportWatcher = new ReportLimitWatcher(0);
            uint max           = uint.MaxValue;

            Assert.Throws <OverflowException>(() => new ReportLimitWatcher(max * 2));
            Assert.True(reportWatcher.WatchReport(new BacktraceReport("test")));
        }
        public void TestQueueAddOperations()
        {
            var reportWatcher = new ReportLimitWatcher(2);

            Assert.DoesNotThrow(() => reportWatcher.WatchReport(new BacktraceReport("text information")));
            Thread.Sleep(3000);
            Assert.IsTrue(reportWatcher.WatchReport(new BacktraceReport("last available information")));
            Assert.IsFalse(reportWatcher.WatchReport(new BacktraceReport("invalid message")));
            reportWatcher.Reset();
            Assert.IsTrue(reportWatcher.WatchReport(new BacktraceReport("after clean ")));
            Assert.IsTrue(reportWatcher._reportQue.Count == 1);
        }
        public void TestReportLimit_ShouldDeclineLastReport_ShouldReturnFalseForLastRecord()
        {
            uint reportLimitWatcherSize = 5;
            var  reportLimitWatcher     = new ReportLimitWatcher(reportLimitWatcherSize);
            var  timestamp = new DateTime().Timestamp();

            for (int i = 0; i < reportLimitWatcherSize; i++)
            {
                var result = reportLimitWatcher.WatchReport(timestamp);
                Assert.IsTrue(result);
            }
            var shouldFail = reportLimitWatcher.WatchReport(timestamp);

            Assert.IsFalse(shouldFail);
        }
        public void TestReportLimitWarningMessage_ShouldPrintWarningMessage_ShouldDisplayMessageMethodShouldReturnTrue()
        {
            uint reportLimitWatcherSize = 5;
            var  reportLimitWatcher     = new ReportLimitWatcher(reportLimitWatcherSize);
            var  timestamp = new DateTime().Timestamp();

            for (int i = 0; i < reportLimitWatcherSize; i++)
            {
                var result = reportLimitWatcher.WatchReport(timestamp);
                Assert.IsTrue(result);
            }

            var shouldFail = reportLimitWatcher.WatchReport(timestamp, false);

            Assert.IsFalse(shouldFail);
            Assert.IsTrue(reportLimitWatcher.ShouldDisplayMessage());
        }
        public void TestReportLimitFromMultipleThreads_ShouldDeclineReportAfterLimitHit_ShouldReturnFalseWhenLimitHit()
        {
            uint reportLimitWatcherSize = 5;
            var  numberOfThreads        = 3;

            var acceptedReports    = 0;
            var declinedReports    = 0;
            var reportLimitWatcher = new ReportLimitWatcher(reportLimitWatcherSize);

            // create and start multiple threads that will use report limit watcher
            // simulate multiple update methods that generate reports
            var threads = new List <Thread>();

            for (int threadIndex = 0; threadIndex < numberOfThreads; threadIndex++)
            {
                threads.Add(new Thread(() =>
                {
                    for (int i = 0; i < reportLimitWatcherSize; i++)
                    {
                        var result = reportLimitWatcher.WatchReport(new DateTime().Timestamp());
                        if (result)
                        {
                            UnityEngine.Debug.Log($"Thread {i} - added report");
                            acceptedReports++;
                        }
                        else
                        {
                            declinedReports++;
                        }
                    }
                }));
            }

            threads.ForEach(t => t.Start());
            threads.ForEach(t => t.Join());

            var numberOfTries = numberOfThreads * reportLimitWatcherSize;

            // validate how many reports we tried to store
            Assert.AreEqual(numberOfTries, acceptedReports + declinedReports);
            // validate how many reports we stored in limit queue
            Assert.AreEqual(reportLimitWatcherSize, acceptedReports);
            // validate how many reports we declined
            Assert.AreEqual(numberOfTries - reportLimitWatcherSize, declinedReports);
        }
        /// <summary>
        /// Reload Backtrace database configuration. Reloading configuration is required, when you change
        /// BacktraceDatabase configuration options.
        /// </summary>
        public void Reload()
        {
            // validate configuration
            if (Configuration == null)
            {
                Configuration = GetComponent <BacktraceClient>().Configuration;
            }
            if (Instance != null)
            {
                return;
            }
            if (Configuration == null || !Configuration.IsValid())
            {
                Enable = false;
                return;
            }

#if UNITY_SWITCH
            Enable = false;
#else
            Enable = Configuration.Enabled && InitializeDatabasePaths();
#endif
            if (!Enable)
            {
                if (Configuration.Enabled)
                {
                    Debug.LogWarning("Cannot initialize database - invalid path to database. Database is disabled");
                }
                return;
            }


            //setup database object
            DatabaseSettings = new BacktraceDatabaseSettings(DatabasePath, Configuration);
            SetupMultisceneSupport();
            _lastConnection = Time.time;
            LastFrameTime   = Time.time;
            //Setup database context
            BacktraceDatabaseContext     = new BacktraceDatabaseContext(DatabaseSettings);
            BacktraceDatabaseFileContext = new BacktraceDatabaseFileContext(DatabaseSettings.DatabasePath, DatabaseSettings.MaxDatabaseSize, DatabaseSettings.MaxRecordCount);
            BacktraceApi        = new BacktraceApi(Configuration.ToCredentials());
            _reportLimitWatcher = new ReportLimitWatcher(Convert.ToUInt32(Configuration.ReportPerMin));
        }
 public void SetReportWatcher(ReportLimitWatcher reportLimitWatcher)
 {
     _reportLimitWatcher = reportLimitWatcher;
 }
Beispiel #11
0
        public void Refresh()
        {
            if (Configuration == null || !Configuration.IsValid())
            {
                return;
            }

            if (Instance != null)
            {
                return;
            }

            Enabled  = true;
            _current = Thread.CurrentThread;
            CaptureUnityMessages();
            _reportLimitWatcher      = new ReportLimitWatcher(Convert.ToUInt32(Configuration.ReportPerMin));
            _clientReportAttachments = Configuration.GetAttachmentPaths();

            BacktraceApi = new BacktraceApi(
                credentials: new BacktraceCredentials(Configuration.GetValidServerUrl()),

#if UNITY_2018_4_OR_NEWER
                ignoreSslValidation: Configuration.IgnoreSslValidation
#else
                ignoreSslValidation: false
#endif
                );
            BacktraceApi.EnablePerformanceStatistics = Configuration.PerformanceStatistics;

            if (!Configuration.DestroyOnLoad)
            {
                DontDestroyOnLoad(gameObject);
                _instance = this;
            }
            var nativeAttachments = _clientReportAttachments.ToList()
                                    .Where(n => !string.IsNullOrEmpty(n))
                                    .OrderBy(System.IO.Path.GetFileName, StringComparer.InvariantCultureIgnoreCase).ToList();

            if (Configuration.Enabled)
            {
                Database = GetComponent <BacktraceDatabase>();
                if (Database != null)
                {
                    Database.Reload();
                    Database.SetApi(BacktraceApi);
                    Database.SetReportWatcher(_reportLimitWatcher);
                    if (Database.Breadcrumbs != null)
                    {
                        nativeAttachments.Add(Database.Breadcrumbs.GetBreadcrumbLogPath());
                    }
                    _nativeClient = NativeClientFactory.CreateNativeClient(Configuration, name, AttributeProvider.GenerateAttributes(false), nativeAttachments);
                    Database.EnableBreadcrumbsSupport();
                }
            }

            AttributeProvider.AddDynamicAttributeProvider(_nativeClient);

            if (Configuration.SendUnhandledGameCrashesOnGameStartup && isActiveAndEnabled)
            {
                var nativeCrashUplaoder = new NativeCrashUploader();
                nativeCrashUplaoder.SetBacktraceApi(BacktraceApi);
                StartCoroutine(nativeCrashUplaoder.SendUnhandledGameCrashesOnGameStartup());
            }
#if !UNITY_WEBGL
            EnableMetrics(false);
#endif
        }