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.");
}
}
}
}
}