diff --git a/GitVersionConfig.yaml b/GitVersionConfig.yaml
index 3156c744..95673f6f 100644
--- a/GitVersionConfig.yaml
+++ b/GitVersionConfig.yaml
@@ -1,4 +1,4 @@
-next-version: 2.0
+next-version: 2.1
branches:
feature[/-]:
mode: ContinuousDeployment
diff --git a/src/app/SharpRaven.Nancy/SharpRaven.Nancy.csproj b/src/app/SharpRaven.Nancy/SharpRaven.Nancy.csproj
index 069242e2..1e965520 100644
--- a/src/app/SharpRaven.Nancy/SharpRaven.Nancy.csproj
+++ b/src/app/SharpRaven.Nancy/SharpRaven.Nancy.csproj
@@ -13,7 +13,7 @@
512
..\
- 05c78a3e
+ ec5b9b6c
true
@@ -102,11 +102,11 @@
-
+
This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
+
\ No newline at end of file
diff --git a/src/app/SharpRaven.Nancy/packages.config b/src/app/SharpRaven.Nancy/packages.config
index adf4268e..9019375f 100644
--- a/src/app/SharpRaven.Nancy/packages.config
+++ b/src/app/SharpRaven.Nancy/packages.config
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/src/app/SharpRaven/Data/ExceptionData.cs b/src/app/SharpRaven/Data/ExceptionData.cs
index 309ee18e..687f8319 100644
--- a/src/app/SharpRaven/Data/ExceptionData.cs
+++ b/src/app/SharpRaven/Data/ExceptionData.cs
@@ -70,6 +70,12 @@ public ExceptionData(Exception exception)
return;
var exceptionData = new ExceptionData(exception.InnerException);
+
+ if (exceptionData.Count == 0)
+ {
+ return;
+ }
+
exceptionData.AddTo(this);
}
diff --git a/src/app/SharpRaven/Data/IJsonPacketFactory.cs b/src/app/SharpRaven/Data/IJsonPacketFactory.cs
index ead5e2a7..647a40c6 100644
--- a/src/app/SharpRaven/Data/IJsonPacketFactory.cs
+++ b/src/app/SharpRaven/Data/IJsonPacketFactory.cs
@@ -53,6 +53,7 @@ public interface IJsonPacketFactory
///
/// A new instance of for the specified .
///
+ [Obsolete("Use Create(string, SentryEvent) instead.")]
JsonPacket Create(string project,
SentryMessage message,
ErrorLevel level = ErrorLevel.Info,
@@ -76,6 +77,7 @@ JsonPacket Create(string project,
/// A new instance of for the specified
/// , with the given .
///
+ [Obsolete("Use Create(string, SentryEvent) instead.")]
JsonPacket Create(string project,
Exception exception,
SentryMessage message = null,
diff --git a/src/app/SharpRaven/Data/JsonPacket.cs b/src/app/SharpRaven/Data/JsonPacket.cs
index 94bbc090..28ca31a7 100644
--- a/src/app/SharpRaven/Data/JsonPacket.cs
+++ b/src/app/SharpRaven/Data/JsonPacket.cs
@@ -30,9 +30,11 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Reflection;
using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
using SharpRaven.Serialization;
using SharpRaven.Utilities;
@@ -72,10 +74,64 @@ public JsonPacket(string project, SentryEvent @event)
Initialize(@event.Exception);
Message = @event.Message != null ? @event.Message.ToString() : null;
+ Level = @event.Level;
+ Extra = Merge(@event);
+ Tags = @event.Tags;
+ Fingerprint = @event.Fingerprint.ToArray();
MessageObject = @event.Message;
}
+ private static object Merge(SentryEvent @event)
+ {
+ var exception = @event.Exception;
+ var extra = @event.Extra;
+
+ if (exception == null && extra == null)
+ return null;
+
+ if (extra != null && exception == null)
+ return extra;
+
+ var exceptionData = new ExceptionData(exception);
+
+ if (extra == null)
+ return exceptionData;
+
+ JObject result;
+
+ if (extra.GetType().IsArray)
+ {
+ result = new JObject();
+ var array = JArray.FromObject(extra);
+
+ foreach (var o in array)
+ {
+ var jo = o as JObject;
+ JProperty[] properties;
+
+ if (jo == null || (properties = jo.Properties().ToArray()).Length != 2 || properties[0].Name != "Key"
+ || properties[1].Name != "Value")
+ {
+ result.Merge(o);
+ continue;
+ }
+
+ var key = properties[0].Value.ToString();
+ var value = properties[1].Value;
+ result.Add(key, value);
+ }
+ }
+ else
+ result = JObject.FromObject(extra);
+
+ var jExceptionData = JObject.FromObject(exceptionData);
+ result.Merge(jExceptionData);
+
+ return result;
+ }
+
+
///
/// Initializes a new instance of the class.
///
diff --git a/src/app/SharpRaven/Data/JsonPacketFactory.cs b/src/app/SharpRaven/Data/JsonPacketFactory.cs
index 95e1e3c0..042457a4 100644
--- a/src/app/SharpRaven/Data/JsonPacketFactory.cs
+++ b/src/app/SharpRaven/Data/JsonPacketFactory.cs
@@ -32,8 +32,6 @@
using System.Collections.Generic;
using System.Linq;
-using Newtonsoft.Json.Linq;
-
namespace SharpRaven.Data
{
///
@@ -56,6 +54,7 @@ public class JsonPacketFactory : IJsonPacketFactory
///
/// A new instance of for the specified .
///
+ [Obsolete("Use Create(string, SentryEvent) instead.")]
public JsonPacket Create(string project,
SentryMessage message,
ErrorLevel level = ErrorLevel.Info,
@@ -63,17 +62,15 @@ public JsonPacket Create(string project,
string[] fingerprint = null,
object extra = null)
{
- var json = new JsonPacket(project)
+ var @event = new SentryEvent(message)
{
- Message = message != null ? message.ToString() : null,
- MessageObject = message,
Level = level,
+ Extra = extra,
Tags = tags,
- Fingerprint = fingerprint,
- Extra = Merge(extra)
+ Fingerprint = fingerprint
};
- return OnCreate(json);
+ return Create(project, @event);
}
@@ -98,6 +95,7 @@ public JsonPacket Create(string project,
/// given
/// .
///
+ [Obsolete("Use Create(string, SentryEvent) instead.")]
public JsonPacket Create(string project,
Exception exception,
SentryMessage message = null,
@@ -106,17 +104,16 @@ public JsonPacket Create(string project,
string[] fingerprint = null,
object extra = null)
{
- var json = new JsonPacket(project, exception)
+ var @event = new SentryEvent(exception)
{
- Message = message != null ? message.ToString() : exception.Message,
- MessageObject = message,
+ Message = message,
Level = level,
+ Extra = extra,
Tags = tags,
Fingerprint = fingerprint,
- Extra = Merge(extra, exception)
};
- return OnCreate(json);
+ return Create(project, @event);
}
@@ -149,52 +146,5 @@ protected virtual JsonPacket OnCreate(JsonPacket jsonPacket)
{
return jsonPacket;
}
-
-
- private static object Merge(object extra, Exception exception = null)
- {
- if (exception == null && extra == null)
- return null;
-
- if (extra != null && exception == null)
- return extra;
-
- var exceptionData = new ExceptionData(exception);
-
- if (extra == null)
- return exceptionData;
-
- JObject result;
-
- if (extra.GetType().IsArray)
- {
- result = new JObject();
- var array = JArray.FromObject(extra);
-
- foreach (var o in array)
- {
- var jo = o as JObject;
- JProperty[] properties;
-
- if (jo == null || (properties = jo.Properties().ToArray()).Length != 2 || properties[0].Name != "Key"
- || properties[1].Name != "Value")
- {
- result.Merge(o);
- continue;
- }
-
- var key = properties[0].Value.ToString();
- var value = properties[1].Value;
- result.Add(key, value);
- }
- }
- else
- result = JObject.FromObject(extra);
-
- var jExceptionData = JObject.FromObject(exceptionData);
- result.Merge(jExceptionData);
-
- return result;
- }
}
}
\ No newline at end of file
diff --git a/src/app/SharpRaven/Data/SentryEvent.cs b/src/app/SharpRaven/Data/SentryEvent.cs
index c63ae4d0..542a593c 100644
--- a/src/app/SharpRaven/Data/SentryEvent.cs
+++ b/src/app/SharpRaven/Data/SentryEvent.cs
@@ -39,8 +39,9 @@ namespace SharpRaven.Data
public class SentryEvent
{
private readonly Exception exception;
- private readonly IList fingerprint;
- private readonly IDictionary tags;
+ private IList fingerprint;
+ private SentryMessage message;
+ private IDictionary tags;
/// Initializes a new instance of the class.
@@ -65,8 +66,8 @@ public SentryEvent(SentryMessage message)
/// Prevents a default instance of the class from being created.
private SentryEvent()
{
- this.tags = new Dictionary();
- this.fingerprint = new List();
+ Tags = new Dictionary();
+ Fingerprint = new List();
}
@@ -92,6 +93,7 @@ public Exception Exception
public IList Fingerprint
{
get { return this.fingerprint; }
+ internal set { this.fingerprint = value ?? new List(); }
}
///
@@ -108,7 +110,11 @@ public IList Fingerprint
///
/// The optional message to capture instead of the default .
///
- public SentryMessage Message { get; set; }
+ public SentryMessage Message
+ {
+ get { return this.message ?? (Exception != null ? Exception.Message : null); }
+ set { this.message = value; }
+ }
/// Gets the tags to annotate the captured or with.
///
@@ -117,6 +123,7 @@ public IList Fingerprint
public IDictionary Tags
{
get { return this.tags; }
+ internal set { this.tags = value ?? new Dictionary(); }
}
}
}
\ No newline at end of file
diff --git a/src/app/SharpRaven/Data/SentryRequestFactory.cs b/src/app/SharpRaven/Data/SentryRequestFactory.cs
index 76ded509..f46fdc04 100644
--- a/src/app/SharpRaven/Data/SentryRequestFactory.cs
+++ b/src/app/SharpRaven/Data/SentryRequestFactory.cs
@@ -31,6 +31,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
+using System.ComponentModel;
using System.Linq;
using System.Reflection;
@@ -50,6 +51,9 @@ internal static bool HasHttpContext
get { return HttpContext != null; }
}
+ [JsonIgnore]
+ internal static bool CheckedForHttpContext { get; set; }
+
///
/// Gets or sets the HTTP context.
///
@@ -59,6 +63,20 @@ internal static bool HasHttpContext
internal static dynamic HttpContext { get; set; }
+ ///
+ /// Gets or sets the CurrentHttpContextProperty
+ ///
+ ///
+ /// The current httpcontext property
+ ///
+ internal static dynamic CurrentHttpContextProperty { get; set; }
+
+ [JsonIgnore]
+ internal static bool HasCurrentHttpContextProperty
+ {
+ get { return CurrentHttpContextProperty != null; }
+ }
+
///
/// Creates a new instance of
/// for the current packet.
@@ -157,7 +175,7 @@ private static IDictionary Convert(Func assembly.FullName.StartsWith("System.Web,"));
- if (HasHttpContext || systemWeb == null)
+ if (systemWeb == null)
return;
var httpContextType = systemWeb.GetExportedTypes()
.FirstOrDefault(type => type.Name == "HttpContext");
- if (HasHttpContext || httpContextType == null)
+ if (httpContextType == null)
return;
var currentHttpContextProperty = httpContextType.GetProperty("Current",
BindingFlags.Static | BindingFlags.Public);
- if (HasHttpContext || currentHttpContextProperty == null)
+ if (currentHttpContextProperty == null)
return;
- HttpContext = currentHttpContextProperty.GetValue(null, null);
+ CurrentHttpContextProperty = currentHttpContextProperty;
+ }
+ catch (Exception exception)
+ {
+ Console.WriteLine("An error occurred while retrieving the HTTP contextproperty: {0}", exception);
+ }
+ }
+
+ private static void GetHttpContext()
+ {
+ // [Meilu] Since reflection is performance heavy, check if we have the httpcontext only once.
+ if (!CheckedForHttpContext)
+ {
+ TryGetHttpContextPropertyFromAppDomain();
+ CheckedForHttpContext = true;
+ }
+
+ // [Meilu] If the currentHttpcontext property is not available we couldnt retrieve it, dont continue
+ if (!HasCurrentHttpContextProperty)
+ return;
+
+ try
+ {
+ HttpContext = CurrentHttpContextProperty.GetValue(null, null);
}
catch (Exception exception)
{
- Console.WriteLine("An error occurred while retrieving the HTTP context: {0}", exception);
+ Console.WriteLine("An error occurred while retrieving the current HTTP context: {0}", exception);
}
}
}
diff --git a/src/app/SharpRaven/RavenClient.Net45.cs b/src/app/SharpRaven/RavenClient.Net45.cs
index c2fa5c71..ae73e3dd 100644
--- a/src/app/SharpRaven/RavenClient.Net45.cs
+++ b/src/app/SharpRaven/RavenClient.Net45.cs
@@ -55,6 +55,7 @@ public partial class RavenClient
///
public async Task CaptureAsync(SentryEvent @event)
{
+ @event.Tags = MergeTags(@event.Tags);
var packet = this.jsonPacketFactory.Create(CurrentDsn.ProjectID, @event);
return await SendAsync(packet);
}
@@ -84,21 +85,11 @@ public async Task CaptureExceptionAsync(Exception exception,
{
Message = message,
Level = level,
- Extra = extra
+ Extra = extra,
+ Tags = tags,
+ Fingerprint = fingerprint
};
- if (tags != null)
- {
- foreach (var tag in tags)
- @event.Tags.Add(tag.Key, tag.Value);
- }
-
- if (fingerprint != null)
- {
- foreach (var f in fingerprint)
- @event.Fingerprint.Add(f);
- }
-
return await CaptureAsync(@event);
}
@@ -124,21 +115,11 @@ public async Task CaptureMessageAsync(SentryMessage message,
var @event = new SentryEvent(message)
{
Level = level,
- Extra = extra
+ Extra = extra,
+ Tags = tags,
+ Fingerprint = fingerprint
};
- if (tags != null)
- {
- foreach (var tag in tags)
- @event.Tags.Add(tag.Key, tag.Value);
- }
-
- if (fingerprint != null)
- {
- foreach (var f in fingerprint)
- @event.Fingerprint.Add(f);
- }
-
return await CaptureAsync(@event);
}
diff --git a/src/app/SharpRaven/RavenClient.cs b/src/app/SharpRaven/RavenClient.cs
index bef4c211..a7a4aa45 100644
--- a/src/app/SharpRaven/RavenClient.cs
+++ b/src/app/SharpRaven/RavenClient.cs
@@ -177,6 +177,10 @@ public IDictionary Tags
///
public string Capture(SentryEvent @event)
{
+ if (@event == null)
+ throw new ArgumentNullException("event");
+
+ @event.Tags = MergeTags(@event.Tags);
var packet = this.jsonPacketFactory.Create(CurrentDsn.ProjectID, @event);
return Send(packet);
}
@@ -227,15 +231,16 @@ public string CaptureException(Exception exception,
string[] fingerprint = null,
object extra = null)
{
- var finalTags = MergeTags(tags);
- var packet = this.jsonPacketFactory.Create(CurrentDsn.ProjectID,
- exception,
- message,
- level,
- finalTags,
- fingerprint,
- extra);
- return Send(packet);
+ var @event = new SentryEvent(exception)
+ {
+ Message = message,
+ Level = level,
+ Extra = extra,
+ Tags = MergeTags(tags),
+ Fingerprint = fingerprint
+ };
+
+ return Capture(@event);
}
@@ -257,14 +262,15 @@ public string CaptureMessage(SentryMessage message,
string[] fingerprint = null,
object extra = null)
{
- var finalTags = MergeTags(tags);
- var packet = this.jsonPacketFactory.Create(CurrentDsn.ProjectID,
- message,
- level,
- finalTags,
- fingerprint,
- extra);
- return Send(packet);
+ var @event = new SentryEvent(message)
+ {
+ Level = level,
+ Extra = extra,
+ Tags = MergeTags(tags),
+ Fingerprint = fingerprint
+ };
+
+ return Capture(@event);
}
diff --git a/src/app/SharpRaven/SharpRaven.csproj b/src/app/SharpRaven/SharpRaven.csproj
index 9c98c455..c6d39ba9 100644
--- a/src/app/SharpRaven/SharpRaven.csproj
+++ b/src/app/SharpRaven/SharpRaven.csproj
@@ -13,7 +13,7 @@
512
..\
- 51b56455
+ 7a5c1353
true
@@ -117,11 +117,11 @@
-
+
This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
+
\ No newline at end of file
diff --git a/src/app/SharpRaven/packages.config b/src/app/SharpRaven/packages.config
index ffddf1af..e7c24c6a 100644
--- a/src/app/SharpRaven/packages.config
+++ b/src/app/SharpRaven/packages.config
@@ -1,5 +1,5 @@
-
+
diff --git a/src/tests/SharpRaven.Nancy.UnitTests/SharpRaven.Nancy.UnitTests.csproj b/src/tests/SharpRaven.Nancy.UnitTests/SharpRaven.Nancy.UnitTests.csproj
index 747be04a..20904037 100644
--- a/src/tests/SharpRaven.Nancy.UnitTests/SharpRaven.Nancy.UnitTests.csproj
+++ b/src/tests/SharpRaven.Nancy.UnitTests/SharpRaven.Nancy.UnitTests.csproj
@@ -13,7 +13,7 @@
512
true
- c36e810a
+ a120c3a0
bin\Release\net40\
@@ -122,12 +122,12 @@
-
+
This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
+
-
+
\ No newline at end of file
diff --git a/src/tests/SharpRaven.UnitTests/packages.config b/src/tests/SharpRaven.UnitTests/packages.config
index 30972413..3f24fbf5 100644
--- a/src/tests/SharpRaven.UnitTests/packages.config
+++ b/src/tests/SharpRaven.UnitTests/packages.config
@@ -1,6 +1,6 @@
-
+
diff --git a/src/tests/SharpRaven.WebTest/SharpRaven.WebTest.csproj b/src/tests/SharpRaven.WebTest/SharpRaven.WebTest.csproj
index 9681dcb9..471cec0c 100644
--- a/src/tests/SharpRaven.WebTest/SharpRaven.WebTest.csproj
+++ b/src/tests/SharpRaven.WebTest/SharpRaven.WebTest.csproj
@@ -20,7 +20,7 @@
- 32ad67ca
+ 22972567
true
@@ -117,12 +117,12 @@
-
+
This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
+