From aff17f7767e7d264abcc280d736e331e751d56ea Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 22 Apr 2012 16:14:02 -0700 Subject: [PATCH] Exceptions are now sent to exceptrack --- NzbDrone.Common/Contract/ExceptionReport.cs | 37 ------------ .../Contract/ExceptionReportResponse.cs | 11 ---- .../Contract/ExistingExceptionReport.cs | 26 --------- NzbDrone.Common/NzbDrone.Common.csproj | 3 - NzbDrone.Common/ReportingService.cs | 56 +++++++++++++------ NzbDrone.Core.Test/App.config | 2 +- .../ServiceIntegerationFixture.cs | 2 +- NzbDrone.Core/CentralDispatch.cs | 1 + NzbDrone.Core/NzbDrone.Core.csproj | 3 + NzbDrone.Core/packages.config | 1 + .../Controllers/ExceptionController.cs | 5 +- .../Controllers/ReportingController.cs | 4 +- .../ReportingControllerFixture.cs | 56 ------------------- NzbDrone.Test.Common/TestBase.cs | 2 + NzbDrone.Update/Program.cs | 1 + NzbDrone.Web.UI.Test/app.config | 8 +-- NzbDrone/CentralDispatch.cs | 1 + 17 files changed, 59 insertions(+), 160 deletions(-) delete mode 100644 NzbDrone.Common/Contract/ExceptionReport.cs delete mode 100644 NzbDrone.Common/Contract/ExceptionReportResponse.cs delete mode 100644 NzbDrone.Common/Contract/ExistingExceptionReport.cs diff --git a/NzbDrone.Common/Contract/ExceptionReport.cs b/NzbDrone.Common/Contract/ExceptionReport.cs deleted file mode 100644 index fbc0bc3fe..000000000 --- a/NzbDrone.Common/Contract/ExceptionReport.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json; - -namespace NzbDrone.Common.Contract -{ - public class ExceptionReport : ReportBase - { - [JsonProperty("t")] - public string Type { get; set; } - [JsonProperty("l")] - public string Logger { get; set; } - [JsonProperty("lm")] - public string LogMessage { get; set; } - [JsonProperty("s")] - public string String { get; set; } - - [JsonProperty("xmessage")] - public string ExceptionMessage { get; set; } - - [JsonProperty("stk")] - public string Stack { get; set; } - - protected override Dictionary GetString() - { - var dic = new Dictionary - { - {"ExType", Type.NullSafe()}, - {"Logger", Logger.NullSafe()}, - {"Message", LogMessage.NullSafe()}, - {"Str", String.NullSafe()} - }; - - return dic; - } - } -} diff --git a/NzbDrone.Common/Contract/ExceptionReportResponse.cs b/NzbDrone.Common/Contract/ExceptionReportResponse.cs deleted file mode 100644 index 8aa98e8e8..000000000 --- a/NzbDrone.Common/Contract/ExceptionReportResponse.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Linq; -using Newtonsoft.Json; - -namespace NzbDrone.Common.Contract -{ - public class ExceptionReportResponse - { - [JsonProperty("h")] - public string ExceptionHash { get; set; } - } -} \ No newline at end of file diff --git a/NzbDrone.Common/Contract/ExistingExceptionReport.cs b/NzbDrone.Common/Contract/ExistingExceptionReport.cs deleted file mode 100644 index b66ad1ccb..000000000 --- a/NzbDrone.Common/Contract/ExistingExceptionReport.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json; - -namespace NzbDrone.Common.Contract -{ - public class ExistingExceptionReport : ReportBase - { - - [JsonProperty("h")] - public string Hash { get; set; } - - [JsonProperty("lm")] - public string LogMessage { get; set; } - - protected override Dictionary GetString() - { - var dic = new Dictionary - { - {"Message", LogMessage.NullSafe()} - }; - - return dic; - } - } -} \ No newline at end of file diff --git a/NzbDrone.Common/NzbDrone.Common.csproj b/NzbDrone.Common/NzbDrone.Common.csproj index 8861216d0..3908c07b1 100644 --- a/NzbDrone.Common/NzbDrone.Common.csproj +++ b/NzbDrone.Common/NzbDrone.Common.csproj @@ -57,13 +57,10 @@ - - - diff --git a/NzbDrone.Common/ReportingService.cs b/NzbDrone.Common/ReportingService.cs index 8c1dd5188..19340ab3f 100644 --- a/NzbDrone.Common/ReportingService.cs +++ b/NzbDrone.Common/ReportingService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Exceptrack.Driver; using NLog; using NzbDrone.Common.Contract; @@ -15,8 +16,10 @@ namespace NzbDrone.Common private const string EXCEPTION_URL = SERVICE_URL + "/ReportException"; public static RestProvider RestProvider { get; set; } - private static readonly HashSet parserErrorCache = new HashSet(); + public static ExceptionClient ExceptrackDriver { get; set; } + + private static readonly HashSet parserErrorCache = new HashSet(); public static void ClearCache() { @@ -30,12 +33,12 @@ namespace NzbDrone.Common { try { - VerifyRestProvider(); + VerifyDependencies(); lock (parserErrorCache) { if (parserErrorCache.Contains(title.ToLower())) return; - + parserErrorCache.Add(title.ToLower()); } @@ -58,16 +61,15 @@ namespace NzbDrone.Common { try { - VerifyRestProvider(); - - var report = new ExceptionReport(); - report.LogMessage = logEvent.FormattedMessage; - report.Stack = logEvent.Exception.StackTrace; - report.ExceptionMessage = logEvent.Exception.Message; - report.Logger = logEvent.LoggerName; - report.Type = logEvent.Exception.GetType().FullName; - - RestProvider.PostData(EXCEPTION_URL, report); + VerifyDependencies(); + + var exceptionData = new ExceptionData(); + + exceptionData.Exception = logEvent.Exception; + exceptionData.Location = logEvent.LoggerName; + exceptionData.UserId = EnvironmentProvider.UGuid.ToString().Replace("-", string.Empty); + + ExceptrackDriver.SubmitException(exceptionData); } catch (Exception e) { @@ -81,11 +83,20 @@ namespace NzbDrone.Common } } - private static void VerifyRestProvider() + + public static void SetupExceptrackDriver() { - if(RestProvider == null) + ExceptrackDriver = new ExceptionClient( + "CB230C312E5C4FF38B4FB9644B05E60D", + new EnvironmentProvider().Version.ToString(), + new Uri("http://api.exceptrack.com/")); + } + + private static void VerifyDependencies() + { + if (RestProvider == null) { - if(EnvironmentProvider.IsProduction) + if (EnvironmentProvider.IsProduction) { logger.Warn("Rest provider wasn't provided. creating new one!"); RestProvider = new RestProvider(new EnvironmentProvider()); @@ -95,6 +106,19 @@ namespace NzbDrone.Common throw new InvalidOperationException("REST Provider wasn't configured correctly."); } } + + if (ExceptrackDriver == null) + { + if (EnvironmentProvider.IsProduction) + { + logger.Warn("Exceptrack Driver wasn't provided. creating new one!"); + SetupExceptrackDriver(); + } + else + { + throw new InvalidOperationException("Exceptrack Driver wasn't configured correctly."); + } + } } } } diff --git a/NzbDrone.Core.Test/App.config b/NzbDrone.Core.Test/App.config index 689531e93..d732ced1a 100644 --- a/NzbDrone.Core.Test/App.config +++ b/NzbDrone.Core.Test/App.config @@ -12,7 +12,7 @@ - + diff --git a/NzbDrone.Core.Test/Integeration/ServiceIntegerationFixture.cs b/NzbDrone.Core.Test/Integeration/ServiceIntegerationFixture.cs index 2226082e7..fe8efa30a 100644 --- a/NzbDrone.Core.Test/Integeration/ServiceIntegerationFixture.cs +++ b/NzbDrone.Core.Test/Integeration/ServiceIntegerationFixture.cs @@ -58,7 +58,7 @@ namespace NzbDrone.Core.Test.Integeration [Test] public void should_be_able_to_submit_exceptions() { - ReportingService.RestProvider = new RestProvider(new EnvironmentProvider()); + ReportingService.SetupExceptrackDriver(); var log = new LogEventInfo(); log.LoggerName = "LoggerName.LoggerName.LoggerName.LoggerName"; diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index a2b1c0d47..fd241be8f 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -68,6 +68,7 @@ namespace NzbDrone.Core { EnvironmentProvider.UGuid = Kernel.Get().UGuid; ReportingService.RestProvider = Kernel.Get(); + ReportingService.SetupExceptrackDriver(); var appId = AnalyticsProvider.DESKMETRICS_TEST_ID; diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index a4d858652..088b7f6c0 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -128,6 +128,9 @@ False ..\packages\EntityFramework.4.3.0\lib\net40\EntityFramework.dll + + ..\packages\Exceptrack.Driver.0.1.0.2\lib\net20\Exceptrack.Driver.dll + ..\packages\Growl.0.6\lib\Growl.Connector.dll diff --git a/NzbDrone.Core/packages.config b/NzbDrone.Core/packages.config index d9651c9ed..db54c1a8d 100644 --- a/NzbDrone.Core/packages.config +++ b/NzbDrone.Core/packages.config @@ -3,6 +3,7 @@ + diff --git a/NzbDrone.Services/NzbDrone.Services.Service/Controllers/ExceptionController.cs b/NzbDrone.Services/NzbDrone.Services.Service/Controllers/ExceptionController.cs index abb6c05bd..d7cdd1218 100644 --- a/NzbDrone.Services/NzbDrone.Services.Service/Controllers/ExceptionController.cs +++ b/NzbDrone.Services/NzbDrone.Services.Service/Controllers/ExceptionController.cs @@ -1,6 +1,5 @@ using System.Linq; using System.Web.Mvc; -using NzbDrone.Common.Contract; namespace NzbDrone.Services.Service.Controllers { @@ -8,13 +7,13 @@ namespace NzbDrone.Services.Service.Controllers { [HttpPost] - public EmptyResult ReportExisting(ExistingExceptionReport existingExceptionReport) + public EmptyResult ReportExisting() { return new EmptyResult(); } [HttpPost] - public JsonResult ReportNew(ExceptionReport exceptionReport) + public JsonResult ReportNew() { return new JsonResult(); } diff --git a/NzbDrone.Services/NzbDrone.Services.Service/Controllers/ReportingController.cs b/NzbDrone.Services/NzbDrone.Services.Service/Controllers/ReportingController.cs index f1af9cb37..3de612c9f 100644 --- a/NzbDrone.Services/NzbDrone.Services.Service/Controllers/ReportingController.cs +++ b/NzbDrone.Services/NzbDrone.Services.Service/Controllers/ReportingController.cs @@ -63,9 +63,9 @@ namespace NzbDrone.Services.Service.Controllers } [HttpPost] - public JsonResult ReportException(ExceptionReport exceptionReport) + public JsonResult ReportException() { - return _exceptionController.ReportNew(exceptionReport); + return new JsonResult(); } } } \ No newline at end of file diff --git a/NzbDrone.Services/NzbDrone.Services.Tests/ReportingControllerFixture.cs b/NzbDrone.Services/NzbDrone.Services.Tests/ReportingControllerFixture.cs index 62896b43c..b83dd54f5 100644 --- a/NzbDrone.Services/NzbDrone.Services.Tests/ReportingControllerFixture.cs +++ b/NzbDrone.Services/NzbDrone.Services.Tests/ReportingControllerFixture.cs @@ -39,62 +39,6 @@ namespace NzbDrone.Services.Tests }; } - private static ExceptionReport CreateExceptionReport() - { - return new ExceptionReport - { - IsProduction = true, - Version = "1.1.2.323456", - UGuid = Guid.NewGuid(), - Logger = "NzbDrone.Logger.Name", - LogMessage = @"Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message", - String = @"Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message - Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message", - - Type = typeof(InvalidOperationException).Name - }; - } - - [Test] public void parse_report_should_be_saved() { diff --git a/NzbDrone.Test.Common/TestBase.cs b/NzbDrone.Test.Common/TestBase.cs index abdb4d6c8..8eead930a 100644 --- a/NzbDrone.Test.Common/TestBase.cs +++ b/NzbDrone.Test.Common/TestBase.cs @@ -49,6 +49,8 @@ namespace NzbDrone.Test.Common MockedRestProvider = new Mock(); ReportingService.RestProvider = MockedRestProvider.Object; + ReportingService.SetupExceptrackDriver(); + if (Directory.Exists(TempFolder)) { diff --git a/NzbDrone.Update/Program.cs b/NzbDrone.Update/Program.cs index 798d7b42d..b3030c3ba 100644 --- a/NzbDrone.Update/Program.cs +++ b/NzbDrone.Update/Program.cs @@ -62,6 +62,7 @@ namespace NzbDrone.Update private static void InitLoggers() { ReportingService.RestProvider = _kernel.Get(); + ReportingService.SetupExceptrackDriver(); LogConfiguration.RegisterRemote(); diff --git a/NzbDrone.Web.UI.Test/app.config b/NzbDrone.Web.UI.Test/app.config index 57e575d47..f21d00089 100644 --- a/NzbDrone.Web.UI.Test/app.config +++ b/NzbDrone.Web.UI.Test/app.config @@ -2,10 +2,10 @@ - - - - + + + + diff --git a/NzbDrone/CentralDispatch.cs b/NzbDrone/CentralDispatch.cs index 5fbdfa07d..33e7a92cc 100644 --- a/NzbDrone/CentralDispatch.cs +++ b/NzbDrone/CentralDispatch.cs @@ -46,6 +46,7 @@ namespace NzbDrone var environmentProvider = _kernel.Get(); ReportingService.RestProvider = _kernel.Get(); + ReportingService.SetupExceptrackDriver(); LogConfiguration.RegisterRollingFileLogger(environmentProvider.GetLogFileName(), LogLevel.Info); LogConfiguration.RegisterConsoleLogger(LogLevel.Debug);