Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit ef56df9

Browse files
committed
Merge branch 'develop'
* develop: (25 commits) Add back .NET 4.0 compatibility Verified tests Added test for ErrorLevel Skip ExceptionData of InnerException if it is empty Added back Unix guards Log level is not set on JsonPacket #114 Check if httpcontext is available and reuse properties from reflection. Upgraded GitVersionTask from v3.3.0 to v3.4.1 Set the next version to 2.1 Wrap async in !net40 regions Adjusted namespace and removed the RavenClient prefix of the RavenClient test classes Moved RavenClient tests into a RavenClientTests folder Added CaptureException tests Tidied up async tests Added Capture tests Added CaptureAsync() tests Merge tags in Capture(SentryEvent) Fixed InvokesSendAndJsonPacketFactoryOnCreate async test Set LastPacket in async as well Add CaptureMessageAsync tests ...
2 parents 2b94249 + a835694 commit ef56df9

28 files changed

Lines changed: 1463 additions & 245 deletions

GitVersionConfig.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
next-version: 2.0
1+
next-version: 2.1
22
branches:
33
feature[/-]:
44
mode: ContinuousDeployment

src/app/SharpRaven.Nancy/SharpRaven.Nancy.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<FileAlignment>512</FileAlignment>
1414
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
1515
<TargetFrameworkProfile />
16-
<NuGetPackageImportStamp>05c78a3e</NuGetPackageImportStamp>
16+
<NuGetPackageImportStamp>ec5b9b6c</NuGetPackageImportStamp>
1717
</PropertyGroup>
1818
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug 4.0|AnyCPU'">
1919
<DebugSymbols>true</DebugSymbols>
@@ -102,11 +102,11 @@
102102
<None Include="SharpRaven.Nancy.nuspec" />
103103
</ItemGroup>
104104
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
105-
<Import Project="..\..\packages\GitVersionTask.3.3.0\Build\portable-net+sl+win+wpa+wp\GitVersionTask.targets" Condition="Exists('..\..\packages\GitVersionTask.3.3.0\Build\portable-net+sl+win+wpa+wp\GitVersionTask.targets') And '$(OS)' != 'Unix'" />
105+
<Import Project="..\..\packages\GitVersionTask.3.4.1\Build\portable-net+sl+win+wpa+wp\GitVersionTask.targets" Condition="Exists('..\..\packages\GitVersionTask.3.4.1\Build\portable-net+sl+win+wpa+wp\GitVersionTask.targets') And '$(OS)' != 'Unix'" />
106106
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
107107
<PropertyGroup>
108108
<ErrorText>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}.</ErrorText>
109109
</PropertyGroup>
110-
<Error Condition="!Exists('..\..\packages\GitVersionTask.3.3.0\Build\portable-net+sl+win+wpa+wp\GitVersionTask.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\GitVersionTask.3.3.0\Build\portable-net+sl+win+wpa+wp\GitVersionTask.targets'))" />
110+
<Error Condition="!Exists('..\..\packages\GitVersionTask.3.4.1\Build\portable-net+sl+win+wpa+wp\GitVersionTask.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\GitVersionTask.3.4.1\Build\portable-net+sl+win+wpa+wp\GitVersionTask.targets'))" />
111111
</Target>
112112
</Project>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="GitVersionTask" version="3.3.0" targetFramework="net45" developmentDependency="true" />
3+
<package id="GitVersionTask" version="3.4.1" targetFramework="net45" developmentDependency="true" />
44
<package id="Nancy" version="1.4.3" targetFramework="net40" />
55
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net40" />
66
</packages>

src/app/SharpRaven/Data/ExceptionData.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ public ExceptionData(Exception exception)
7070
return;
7171

7272
var exceptionData = new ExceptionData(exception.InnerException);
73+
74+
if (exceptionData.Count == 0)
75+
{
76+
return;
77+
}
78+
7379
exceptionData.AddTo(this);
7480
}
7581

src/app/SharpRaven/Data/IJsonPacketFactory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public interface IJsonPacketFactory
5353
/// <returns>
5454
/// A new instance of <see cref="JsonPacket" /> for the specified <paramref name="project" />.
5555
/// </returns>
56+
[Obsolete("Use Create(string, SentryEvent) instead.")]
5657
JsonPacket Create(string project,
5758
SentryMessage message,
5859
ErrorLevel level = ErrorLevel.Info,
@@ -76,6 +77,7 @@ JsonPacket Create(string project,
7677
/// A new instance of <see cref="JsonPacket" /> for the specified
7778
/// <paramref name="project" />, with the given <paramref name="exception" />.
7879
/// </returns>
80+
[Obsolete("Use Create(string, SentryEvent) instead.")]
7981
JsonPacket Create(string project,
8082
Exception exception,
8183
SentryMessage message = null,

src/app/SharpRaven/Data/JsonPacket.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030

3131
using System;
3232
using System.Collections.Generic;
33+
using System.Linq;
3334
using System.Reflection;
3435

3536
using Newtonsoft.Json;
37+
using Newtonsoft.Json.Linq;
3638

3739
using SharpRaven.Serialization;
3840
using SharpRaven.Utilities;
@@ -72,10 +74,64 @@ public JsonPacket(string project, SentryEvent @event)
7274
Initialize(@event.Exception);
7375

7476
Message = @event.Message != null ? @event.Message.ToString() : null;
77+
Level = @event.Level;
78+
Extra = Merge(@event);
79+
Tags = @event.Tags;
80+
Fingerprint = @event.Fingerprint.ToArray();
7581
MessageObject = @event.Message;
7682
}
7783

7884

85+
private static object Merge(SentryEvent @event)
86+
{
87+
var exception = @event.Exception;
88+
var extra = @event.Extra;
89+
90+
if (exception == null && extra == null)
91+
return null;
92+
93+
if (extra != null && exception == null)
94+
return extra;
95+
96+
var exceptionData = new ExceptionData(exception);
97+
98+
if (extra == null)
99+
return exceptionData;
100+
101+
JObject result;
102+
103+
if (extra.GetType().IsArray)
104+
{
105+
result = new JObject();
106+
var array = JArray.FromObject(extra);
107+
108+
foreach (var o in array)
109+
{
110+
var jo = o as JObject;
111+
JProperty[] properties;
112+
113+
if (jo == null || (properties = jo.Properties().ToArray()).Length != 2 || properties[0].Name != "Key"
114+
|| properties[1].Name != "Value")
115+
{
116+
result.Merge(o);
117+
continue;
118+
}
119+
120+
var key = properties[0].Value.ToString();
121+
var value = properties[1].Value;
122+
result.Add(key, value);
123+
}
124+
}
125+
else
126+
result = JObject.FromObject(extra);
127+
128+
var jExceptionData = JObject.FromObject(exceptionData);
129+
result.Merge(jExceptionData);
130+
131+
return result;
132+
}
133+
134+
79135
/// <summary>
80136
/// Initializes a new instance of the <see cref="JsonPacket"/> class.
81137
/// </summary>

src/app/SharpRaven/Data/JsonPacketFactory.cs

Lines changed: 10 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
using System.Collections.Generic;
3333
using System.Linq;
3434

35-
using Newtonsoft.Json.Linq;
36-
3735
namespace SharpRaven.Data
3836
{
3937
/// <summary>
@@ -56,24 +54,23 @@ public class JsonPacketFactory : IJsonPacketFactory
5654
/// <returns>
5755
/// A new instance of <see cref="JsonPacket" /> for the specified <paramref name="project" />.
5856
/// </returns>
57+
[Obsolete("Use Create(string, SentryEvent) instead.")]
5958
public JsonPacket Create(string project,
6059
SentryMessage message,
6160
ErrorLevel level = ErrorLevel.Info,
6261
IDictionary<string, string> tags = null,
6362
string[] fingerprint = null,
6463
object extra = null)
6564
{
66-
var json = new JsonPacket(project)
65+
var @event = new SentryEvent(message)
6766
{
68-
Message = message != null ? message.ToString() : null,
69-
MessageObject = message,
7067
Level = level,
68+
Extra = extra,
7169
Tags = tags,
72-
Fingerprint = fingerprint,
73-
Extra = Merge(extra)
70+
Fingerprint = fingerprint
7471
};
7572

76-
return OnCreate(json);
73+
return Create(project, @event);
7774
}
7875

7976

@@ -98,6 +95,7 @@ public JsonPacket Create(string project,
9895
/// given
9996
/// <paramref name="exception" />.
10097
/// </returns>
98+
[Obsolete("Use Create(string, SentryEvent) instead.")]
10199
public JsonPacket Create(string project,
102100
Exception exception,
103101
SentryMessage message = null,
@@ -106,17 +104,16 @@ public JsonPacket Create(string project,
106104
string[] fingerprint = null,
107105
object extra = null)
108106
{
109-
var json = new JsonPacket(project, exception)
107+
var @event = new SentryEvent(exception)
110108
{
111-
Message = message != null ? message.ToString() : exception.Message,
112-
MessageObject = message,
109+
Message = message,
113110
Level = level,
111+
Extra = extra,
114112
Tags = tags,
115113
Fingerprint = fingerprint,
116-
Extra = Merge(extra, exception)
117114
};
118115

119-
return OnCreate(json);
116+
return Create(project, @event);
120117
}
121118

122119

@@ -149,52 +146,5 @@ protected virtual JsonPacket OnCreate(JsonPacket jsonPacket)
149146
{
150147
return jsonPacket;
151148
}
152-
153-
154-
private static object Merge(object extra, Exception exception = null)
155-
{
156-
if (exception == null && extra == null)
157-
return null;
158-
159-
if (extra != null && exception == null)
160-
return extra;
161-
162-
var exceptionData = new ExceptionData(exception);
163-
164-
if (extra == null)
165-
return exceptionData;
166-
167-
JObject result;
168-
169-
if (extra.GetType().IsArray)
170-
{
171-
result = new JObject();
172-
var array = JArray.FromObject(extra);
173-
174-
foreach (var o in array)
175-
{
176-
var jo = o as JObject;
177-
JProperty[] properties;
178-
179-
if (jo == null || (properties = jo.Properties().ToArray()).Length != 2 || properties[0].Name != "Key"
180-
|| properties[1].Name != "Value")
181-
{
182-
result.Merge(o);
183-
continue;
184-
}
185-
186-
var key = properties[0].Value.ToString();
187-
var value = properties[1].Value;
188-
result.Add(key, value);
189-
}
190-
}
191-
else
192-
result = JObject.FromObject(extra);
193-
194-
var jExceptionData = JObject.FromObject(exceptionData);
195-
result.Merge(jExceptionData);
196-
197-
return result;
198-
}
199149
}
200150
}

src/app/SharpRaven/Data/SentryEvent.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ namespace SharpRaven.Data
3939
public class SentryEvent
4040
{
4141
private readonly Exception exception;
42-
private readonly IList<string> fingerprint;
43-
private readonly IDictionary<string, string> tags;
42+
private IList<string> fingerprint;
43+
private SentryMessage message;
44+
private IDictionary<string, string> tags;
4445

4546

4647
/// <summary>Initializes a new instance of the <see cref="SentryEvent" /> class.</summary>
@@ -65,8 +66,8 @@ public SentryEvent(SentryMessage message)
6566
/// <summary>Prevents a default instance of the <see cref="SentryEvent"/> class from being created.</summary>
6667
private SentryEvent()
6768
{
68-
this.tags = new Dictionary<string, string>();
69-
this.fingerprint = new List<string>();
69+
Tags = new Dictionary<string, string>();
70+
Fingerprint = new List<string>();
7071
}
7172

7273

@@ -92,6 +93,7 @@ public Exception Exception
9293
public IList<string> Fingerprint
9394
{
9495
get { return this.fingerprint; }
96+
internal set { this.fingerprint = value ?? new List<string>(); }
9597
}
9698

9799
/// <summary>
@@ -108,7 +110,11 @@ public IList<string> Fingerprint
108110
/// <value>
109111
/// The optional message to capture instead of the default <see cref="T:Exception.Message" />.
110112
/// </value>
111-
public SentryMessage Message { get; set; }
113+
public SentryMessage Message
114+
{
115+
get { return this.message ?? (Exception != null ? Exception.Message : null); }
116+
set { this.message = value; }
117+
}
112118

113119
/// <summary>Gets the tags to annotate the captured <see name="Exception" /> or <see cref="Message" /> with.</summary>
114120
/// <value>
@@ -117,6 +123,7 @@ public IList<string> Fingerprint
117123
public IDictionary<string, string> Tags
118124
{
119125
get { return this.tags; }
126+
internal set { this.tags = value ?? new Dictionary<string, string>(); }
120127
}
121128
}
122129
}

0 commit comments

Comments
 (0)