Exceptions are now sent to exceptrack

This commit is contained in:
kay.one 2012-04-22 16:14:02 -07:00
parent 2b5776acbf
commit aff17f7767
17 changed files with 58 additions and 159 deletions

View File

@ -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<string, string> GetString()
{
var dic = new Dictionary<string, string>
{
{"ExType", Type.NullSafe()},
{"Logger", Logger.NullSafe()},
{"Message", LogMessage.NullSafe()},
{"Str", String.NullSafe()}
};
return dic;
}
}
}

View File

@ -1,11 +0,0 @@
using System.Linq;
using Newtonsoft.Json;
namespace NzbDrone.Common.Contract
{
public class ExceptionReportResponse
{
[JsonProperty("h")]
public string ExceptionHash { get; set; }
}
}

View File

@ -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<string, string> GetString()
{
var dic = new Dictionary<string, string>
{
{"Message", LogMessage.NullSafe()}
};
return dic;
}
}
}

View File

@ -57,13 +57,10 @@
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="Contract\ExceptionReportResponse.cs" />
<Compile Include="Contract\ExistingExceptionReport.cs" />
<Compile Include="StringExtention.cs" />
<Compile Include="HttpProvider.cs" />
<Compile Include="ConfigFileProvider.cs" />
<Compile Include="ConsoleProvider.cs" />
<Compile Include="Contract\ExceptionReport.cs" />
<Compile Include="Contract\ReportBase.cs" />
<Compile Include="Contract\ParseErrorReport.cs" />
<Compile Include="NlogTargets\RemoteTarget.cs" />

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Exceptrack.Driver;
using NLog;
using NzbDrone.Common.Contract;
@ -15,9 +16,11 @@ namespace NzbDrone.Common
private const string EXCEPTION_URL = SERVICE_URL + "/ReportException";
public static RestProvider RestProvider { get; set; }
private static readonly HashSet<string> parserErrorCache = new HashSet<string>();
public static ExceptionClient ExceptrackDriver { get; set; }
private static readonly HashSet<string> parserErrorCache = new HashSet<string>();
public static void ClearCache()
{
lock (parserErrorCache)
@ -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;
VerifyDependencies();
RestProvider.PostData(EXCEPTION_URL, report);
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.");
}
}
}
}
}

View File

@ -12,7 +12,7 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.7.0" newVersion="4.0.7.0" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>

View File

@ -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";

View File

@ -68,6 +68,7 @@ namespace NzbDrone.Core
{
EnvironmentProvider.UGuid = Kernel.Get<ConfigProvider>().UGuid;
ReportingService.RestProvider = Kernel.Get<RestProvider>();
ReportingService.SetupExceptrackDriver();
var appId = AnalyticsProvider.DESKMETRICS_TEST_ID;

View File

@ -128,6 +128,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\EntityFramework.4.3.0\lib\net40\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="Exceptrack.Driver">
<HintPath>..\packages\Exceptrack.Driver.0.1.0.2\lib\net20\Exceptrack.Driver.dll</HintPath>
</Reference>
<Reference Include="Growl.Connector">
<HintPath>..\packages\Growl.0.6\lib\Growl.Connector.dll</HintPath>
</Reference>

View File

@ -3,6 +3,7 @@
<package id="DotNetZip" version="1.9.1.8" />
<package id="EntityFramework" version="4.3.0" />
<package id="EntityFramework.SqlServerCompact" version="4.1.8482.2" />
<package id="Exceptrack.Driver" version="0.1.0.2" />
<package id="Growl" version="0.6" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" />
<package id="MiniProfiler" version="1.9" />

View File

@ -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();
}

View File

@ -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();
}
}
}

View File

@ -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()
{

View File

@ -49,6 +49,8 @@ namespace NzbDrone.Test.Common
MockedRestProvider = new Mock<RestProvider>();
ReportingService.RestProvider = MockedRestProvider.Object;
ReportingService.SetupExceptrackDriver();
if (Directory.Exists(TempFolder))
{

View File

@ -62,6 +62,7 @@ namespace NzbDrone.Update
private static void InitLoggers()
{
ReportingService.RestProvider = _kernel.Get<RestProvider>();
ReportingService.SetupExceptrackDriver();
LogConfiguration.RegisterRemote();

View File

@ -2,10 +2,10 @@
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.0.8.0" newVersion="4.0.6.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -46,6 +46,7 @@ namespace NzbDrone
var environmentProvider = _kernel.Get<EnvironmentProvider>();
ReportingService.RestProvider = _kernel.Get<RestProvider>();
ReportingService.SetupExceptrackDriver();
LogConfiguration.RegisterRollingFileLogger(environmentProvider.GetLogFileName(), LogLevel.Info);
LogConfiguration.RegisterConsoleLogger(LogLevel.Debug);