internal TwitterStream(IrcClient client) { _ircClient = client; LoadConfig(); if (!_config.StreamEnabled) { // F**k you and the f*****g pile of piss your shitty application came out of. F**k your shitty API for suddenly not working and causing annoying to trace errors // Come over here and suck my c**k @Jack you piece of shit. return; } _twitterClient = Services.Twitter.GetTwitterClient(); _backtraceClient?.Send("Authenticating to Twitter"); IAuthenticatedUser authedUser; try { authedUser = _twitterClient.Users.GetAuthenticatedUserAsync().Result; } catch (TwitterAuthException e) { _log.Error("When attempting to authenticate with Twitter, got exception:"); _log.Error(e); _log.Error("Self destructing the Tweet thread"); _backtraceClient?.Send(e); return; } catch (TwitterException e) { _log.Error("Got TwitterException when testing creds"); _log.Error(e); _backtraceClient?.Send(e); return; } catch (Exception e) { _log.Error("Got an exception when testing creds"); _log.Error(e); _backtraceClient?.Send(e); return; } _log.Info($"Auth'd as {authedUser.Name}"); _thread = new Thread(() => TweetThread()); _thread.Start(); }
public IEnumerator TestSourceCodeAssignment_DisabledLogManagerAndSendExceptionReport_SourceCodeAvailable() { var invoked = false; BacktraceClient.BeforeSend = (BacktraceData lastData) => { invoked = true; Assert.IsNotNull(lastData.SourceCode); var threadName = lastData.ThreadData.MainThread; Assert.AreEqual(BacktraceSourceCode.SOURCE_CODE_PROPERTY, lastData.ThreadData.ThreadInformations[threadName].Stack.First().SourceCode); return(lastData); }; BacktraceClient.Send(new Exception("foo")); yield return(new WaitForEndOfFrame()); Assert.IsTrue(invoked); }
public IEnumerator TestSendingReport_ValidConfiguration_ValidSend() { var trigger = false; BacktraceClient.Configuration = GetValidClientConfiguration(); BacktraceClient.Refresh(); BacktraceClient.RequestHandler = (string url, BacktraceData data) => { Assert.IsNotNull(data); Assert.IsFalse(string.IsNullOrEmpty(data.ToJson())); trigger = true; return(new BacktraceResult()); }; BacktraceClient.Send(new Exception("test exception")); Assert.IsTrue(trigger); yield return(null); }
public IEnumerator TestSourceCodeAssignment_EnabledLogManagerAndSendMessageReport_SourceCodeAvailable() { BacktraceData lastData = null; BacktraceClient.BeforeSend = (BacktraceData data) => { lastData = data; return(data); }; BacktraceClient.Send("foo"); yield return(new WaitForEndOfFrame()); Assert.IsNotNull(lastData.SourceCode); var threadName = lastData.ThreadData.MainThread; Assert.AreEqual(BacktraceSourceCode.SOURCE_CODE_PROPERTY, lastData.ThreadData.ThreadInformations[threadName].Stack.First().SourceCode); }
public IEnumerator TesClientAttributeAccessor_BacktraceDataShouldIncludeClientAttributes_ClientAttributesAreAvailableInDiagnosticData() { var key = "foo"; var value = "bar"; BacktraceClient[key] = value; BacktraceData data = null; BacktraceClient.BeforeSend = (BacktraceData reportData) => { data = reportData; return(null); }; BacktraceClient.Send(new Exception("foo")); yield return(new WaitForEndOfFrame()); Assert.IsNotNull(data); Assert.AreEqual(data.Attributes.Attributes[key], value); yield return(null); }
public IEnumerator TestReportLimit_ValidReportNumber_AddAllReports() { BacktraceClient.SetClientReportLimit(CLIENT_RATE_LIMIT); int maximumNumberOfRetries = 0; BacktraceClient.RequestHandler = (string url, BacktraceData data) => { maximumNumberOfRetries++; return(new BacktraceResult()); }; for (int i = 0; i < 2; i++) { BacktraceClient.Send("test"); } yield return(new WaitForEndOfFrame()); Assert.AreEqual(2, maximumNumberOfRetries); yield return(null); }
public IEnumerator TestReportFilter_ShouldntPreventFromSendingUnhandledException_ClientAllowToSendData() { var eventCalled = false; BacktraceClient.BeforeSend = (BacktraceData data) => { eventCalled = true; return(null); }; // in this situation to learn if we were able to continue processing report // we should check if before send event or reportFilter event was called BacktraceClient.Configuration.ReportFilterType = ReportFilterType.Exception; BacktraceClient.Send(new BacktraceUnhandledException(string.Empty, string.Empty)); yield return(new WaitForEndOfFrame()); Assert.IsTrue(eventCalled); yield return(null); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); BacktraceClient client = new BacktraceClient( new BacktraceCredentials(@"https://myserver.sp.backtrace.io:6097", "4dca18e8769d0f5d10db0d1b665e64b3d716f76bf182fbcdad5d1d8070c12db0") ) { OnServerError = (Exception e) => { System.Diagnostics.Trace.WriteLine(e.Message); }, OnServerResponse = (BacktraceServerResponse res) => { System.Diagnostics.Trace.WriteLine(res.Response); } }; client.Send("Hello from Xamarin"); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); }
public IEnumerator SendReport_ExceptionReport_ValidSend() { var trigger = false; var exception = new Exception("custom exception message"); client.RequestHandler = (string url, BacktraceData data) => { trigger = true; Assert.IsTrue(data.Classifier[0] == exception.GetType().Name); string message = data.Attributes.Attributes["error.message"]; Assert.IsTrue(message == exception.Message); return(new BacktraceResult()); }; client.Send(exception); yield return(new WaitForEndOfFrame()); Assert.IsTrue(trigger); yield return(null); }
public IEnumerator TesClientAttributes_ReprotShouldntExtendClientAttributes_ClientAttributesWontStoreReportAttributes() { var key = "foo"; var value = "bar"; BacktraceClient[key] = value; BacktraceData data = null; BacktraceClient.BeforeSend = (BacktraceData reportData) => { data = reportData; return(null); }; BacktraceClient.Send(new Exception("foo")); yield return(new WaitForEndOfFrame()); Assert.IsNotNull(data); Assert.AreEqual(data.Attributes.Attributes[key], value); Assert.AreEqual(1, BacktraceClient.GetAttributesCount()); BacktraceClient.Send(new Exception("bar")); Assert.AreEqual(1, BacktraceClient.GetAttributesCount()); yield return(null); }
public IEnumerator TestFingerprintBehaviorForNormalizedExceptionMessage_ShouldntGenerateFingerprintForExistingStackTrace_ShouldIgnoreAttributeFingerprint() { BacktraceClient.Configuration = GetValidClientConfiguration(); BacktraceClient.Configuration.UseNormalizedExceptionMessage = true; BacktraceClient.Refresh(); var exception = new BacktraceUnhandledException("Unhandled exception", "foo()"); var report = new BacktraceReport(exception); bool eventFired = false; BacktraceClient.BeforeSend = (BacktraceData data) => { eventFired = true; Assert.IsFalse(report.Attributes.ContainsKey("_mod_fingerprint")); // prevent backtrace data from sending to Backtrace. return(null); }; BacktraceClient.Send(report); yield return(new WaitForEndOfFrame()); Assert.IsTrue(eventFired); }
public IEnumerator TestSourceCodeAssignment_DisabledLogManagerWithMultipleLogMessageAndExceptionReport_SourceCodeAvailable() { BacktraceData lastData = null; BacktraceClient.BeforeSend = (BacktraceData data) => { lastData = data; return(data); }; //fake messages var fakeLogMessage = "log"; BacktraceClient.HandleUnityMessage(fakeLogMessage, string.Empty, UnityEngine.LogType.Log); yield return(new WaitForEndOfFrame()); var fakeWarningMessage = "warning message"; BacktraceClient.HandleUnityMessage(fakeWarningMessage, string.Empty, UnityEngine.LogType.Warning); yield return(new WaitForEndOfFrame()); // real exception var expectedExceptionMessage = "Exception message"; BacktraceClient.Send(new Exception(expectedExceptionMessage)); yield return(new WaitForEndOfFrame()); Assert.IsNotNull(lastData.SourceCode); var generatedText = lastData.SourceCode.Text; Assert.IsTrue(generatedText.Contains(expectedExceptionMessage)); Assert.IsFalse(generatedText.Contains(fakeLogMessage)); Assert.IsFalse(generatedText.Contains(fakeWarningMessage)); }
public IEnumerator TestFingerprintBehaviorForNormalizedExceptionMessage_ShouldGenerateFingerprintAndShouldntRemoveAnyLetter_ShouldIncludeFingerprintInBacktraceReport() { BacktraceClient.Configuration = GetValidClientConfiguration(); BacktraceClient.Configuration.UseNormalizedExceptionMessage = true; BacktraceClient.Refresh(); var normalizedMessage = "Unhandledexception"; var exception = new BacktraceUnhandledException(normalizedMessage, string.Empty); var report = new BacktraceReport(exception); bool eventFired = false; BacktraceClient.BeforeSend = (BacktraceData data) => { eventFired = true; Assert.AreEqual(normalizedMessage.GetSha(), data.Attributes.Attributes["_mod_fingerprint"]); // prevent backtrace data from sending to Backtrace. return(null); }; BacktraceClient.Send(report); yield return(new WaitForEndOfFrame()); Assert.IsTrue(eventFired); }
public void SingleThreadWithoutRateLimiting() { Assert.DoesNotThrow(() => { _backtraceClient.ChangeRateLimiting(0); }); Assert.DoesNotThrow(() => { _backtraceClient.Send($"{DateTime.Now}: Library Initialized for single thread integration test w/o rate limiting"); }); Assert.DoesNotThrow(() => { try { ExceptionMethod(); } catch (DivideByZeroException ex) { Assert.DoesNotThrow(() => { _backtraceClient.Send(ex); }); } }); Assert.DoesNotThrow(() => { _backtraceClient.Send($"{DateTime.Now}: Single thread integration test w/o rate limiting completed successfully."); }); }
static void Main(string[] args) { //initialize new BacktraceClient with custom configuration section readed from file App.config //Client will be initialized with values stored in default section name "BacktraceCredentials" BacktraceClient backtraceClient = new BacktraceClient(); var credentials = new BacktraceCredentials(@"https://myserver.sp.backtrace.io:6097", "4dca18e8769d0f5d10db0d1b665e64b3d716f76bf182fbcdad5d1d8070c12db0"); var backtraceClientWithCredentials = new BacktraceClient(credentials); //Add new scoped attributes backtraceClient.Attributes["ClientAttributeNumber"] = 1; backtraceClient.Attributes["ClientAttributeString"] = "string attribute"; backtraceClient.Attributes["ClientAttributeCustomClass"] = new { Name = "Backtrace", Type = "Library" }; backtraceClient.OnServerResponse = (BacktraceServerResponse response) => { System.Diagnostics.Trace.WriteLine(response.Object); }; backtraceClient.OnServerError = (Exception e) => { System.Diagnostics.Trace.WriteLine(e.Message); }; //Add your own handler to client API backtraceClient.BeforeSend = (BacktraceData <object> model) => { var data = model; data.Attributes.Add("eventAtrtibute", "EventAttributeValue"); return(data); }; //Report a new exception from current application try { try { int.Parse("abc"); } catch (Exception inner) { try { var openLog = File.Open("Not existing path", FileMode.Open); } catch { throw new FileNotFoundException("OutterException", inner); } } } catch (Exception e) { var report = new BacktraceReport( exception: e, attributes: new Dictionary <string, object>() { { "AttributeString", "string" } }, attachmentPaths: new List <string>() { @"path to file attachment", @"patch to another file attachment" } ); backtraceClient.Send(report); } //Report a new message backtraceClient.Send("Client message"); }
private IEnumerator CallBacktraceClientAndWait(BacktraceReport report) { BacktraceClient.Send(report); yield return(new WaitForEndOfFrame()); }
static void Main(string[] args) { //setup tls support for tested server ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | (SecurityProtocolType)0x00000300 | (SecurityProtocolType)0x00000C00; var credentials = new BacktraceCredentials(ApplicationSettings.Host, ApplicationSettings.Token); // create Backtrace library configuration var configuartion = new BacktraceClientConfiguration(credentials) { ReportPerMin = 0 }; //initialize new BacktraceClient with custom configuration section readed from file App.config //Client will be initialized with values stored in default section name "BacktraceCredentials" BacktraceClient backtraceClientWithSectionCredentials = new BacktraceClient(); //create new backtrace database settings BacktraceDatabaseSettings databaseSettings = new BacktraceDatabaseSettings(ApplicationSettings.DatabasePath); //create Backtrace database var database = new BacktraceDatabase(databaseSettings); //setup new client var backtraceClient = new BacktraceClient(credentials, databaseSettings); //Add new scoped attributes backtraceClient.Attributes["ClientAttributeNumber"] = 1; backtraceClient.Attributes["ClientAttributeString"] = "/string attribute"; backtraceClient.Attributes["ClientAttributeCustomClass"] = new { Name = "Backtrace", Type = "Library" }; //Add your own handler to client API backtraceClient.BeforeSend = (BacktraceData model) => { var data = model; data.Attributes.Add("eventAtrtibute", "EventAttributeValue"); return(data); }; //Report a new exception from current application try { try { int.Parse("abc"); } catch (Exception inner) { try { var openLog = File.Open("Not existing path", FileMode.Open); } catch { throw new FileNotFoundException("OutterException", inner); } } } catch (Exception e) { var report = new BacktraceReport( exception: e, attributes: new Dictionary <string, object>() { { "AttributeString", "string" } }, attachmentPaths: new List <string>() { @"path to file attachment", @"patch to another file attachment" } ); var response = backtraceClient.Send(report); } //Report a new message var sendResult = backtraceClient.Send("Client message"); }