Skip to content

Commit 79135be

Browse files
committed
Change method trace string to have full namespace, method name and parameters.
1 parent c6d010b commit 79135be

File tree

4 files changed

+45
-20
lines changed

4 files changed

+45
-20
lines changed

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
# 0.6.0
1+
# 0.6.2
2+
<sup>Released: 2017/8/20</sup>
3+
4+
- Change method trace string to have full namespace, method name and parameters.
5+
6+
# 0.6.1
7+
<sup>Released: 2017/8/20</sup>
8+
9+
- Fixed a bug where .NET Core Service extensions were excluded from the library.
10+
11+
# 0.6.0
212

313
## Features
414
<sup>Released: 2017/8/20</sup>
Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
namespace RollbarDotNet.Builder
22
{
3+
using System;
34
using System.Collections.Generic;
45
using System.Diagnostics;
6+
using System.Linq;
57
using Payloads;
6-
using Trace = Payloads.Trace;
8+
using Exception = System.Exception;
79

810
public class ExceptionBuilder : IExceptionBuilder
911
{
10-
public void Execute(Payload payload, System.Exception exception)
12+
public void Execute(Payload payload, Exception exception)
1113
{
12-
if(payload == null)
14+
if (payload == null)
1315
{
14-
throw new System.ArgumentNullException(nameof(payload));
16+
throw new ArgumentNullException(nameof(payload));
1517
}
1618

17-
if(exception == null)
19+
if (exception == null)
1820
{
19-
throw new System.ArgumentNullException(nameof(exception));
21+
throw new ArgumentNullException(nameof(exception));
2022
}
2123

22-
var traceChain = new List<Trace>();
24+
var traceChain = new List<Payloads.Trace>();
2325
this.BuildTraceList(exception, traceChain);
24-
if(traceChain.Count > 0)
26+
if (traceChain.Count > 0)
2527
{
2628
payload.Data.Body.TraceChain = traceChain;
2729
}
2830
}
2931

30-
protected void BuildTraceList(System.Exception exception, List<Trace> traceList)
32+
protected void BuildTraceList(Exception exception, List<Payloads.Trace> traceList)
3133
{
32-
var trace = new Trace();
34+
var trace = new Payloads.Trace();
3335
trace.Exception = this.BuildException(exception);
3436
trace.Frames = this.BuildFrames(exception);
3537
traceList.Add(trace);
@@ -39,18 +41,26 @@ protected void BuildTraceList(System.Exception exception, List<Trace> traceList)
3941
}
4042
}
4143

42-
protected List<Frame> BuildFrames(System.Exception exception)
44+
protected List<Frame> BuildFrames(Exception exception)
4345
{
4446
var frames = new List<Frame>();
4547
var stacktrace = new StackTrace(exception, true);
4648
foreach (var stackTraceFrame in stacktrace.GetFrames())
4749
{
50+
var method = stackTraceFrame.GetMethod();
51+
var methodParameters = method.GetParameters();
52+
var parameters = methodParameters.Length == 0
53+
? string.Empty
54+
: method.GetParameters()
55+
.Select(p => $"{p.ParameterType.FullName} {p.Name}")
56+
.Aggregate((p1, p2) => $"{p1}, {p2}");
57+
var methodName = $"{method.DeclaringType.FullName}.{method.Name}({parameters})";
4858
var frame = new Frame
4959
{
5060
Filename = stackTraceFrame.GetFileName(),
5161
ColumnNumber = stackTraceFrame.GetFileColumnNumber(),
5262
LineNumber = stackTraceFrame.GetFileLineNumber(),
53-
Method = stackTraceFrame.GetMethod()?.ToString()
63+
Method = methodName
5464
};
5565
frames.Add(frame);
5666
}
@@ -63,12 +73,12 @@ protected List<Frame> BuildFrames(System.Exception exception)
6373
return frames;
6474
}
6575

66-
protected Exception BuildException(System.Exception exception)
76+
protected Payloads.Exception BuildException(Exception exception)
6777
{
68-
var payloadException = new Exception();
78+
var payloadException = new Payloads.Exception();
6979
payloadException.Class = exception.GetType().Name;
7080
payloadException.Message = exception.Message;
7181
return payloadException;
7282
}
7383
}
74-
}
84+
}

src/RollbarDotNet/RollbarDotNet.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Description>Rollbar Integration for .NET Core</Description>
55
<Copyright>William Roush 2016-2017</Copyright>
66
<AssemblyTitle>RollbarDotNet</AssemblyTitle>
7-
<VersionPrefix>0.6.1</VersionPrefix>
7+
<VersionPrefix>0.6.2</VersionPrefix>
88
<Authors>William Roush</Authors>
99
<AssemblyName>RollbarDotNet</AssemblyName>
1010
<PackageId>RollbarDotNet</PackageId>

test/RollbarDotNet.Tests/Builder/ExceptionBuilderTests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ public void SetsPayload()
2424
{
2525
try
2626
{
27-
throw new System.Exception("test exception");
27+
this.ThrowException("", 0);
2828
}
2929
catch (System.Exception exception)
3030
{
3131
this.ExceptionBuilder.Execute(this.Payload, exception);
3232
var payload = this.Payload.Data?.Body?.TraceChain?.FirstOrDefault();
3333
Assert.Equal("Exception", payload?.Exception?.Class);
3434
Assert.Equal("test exception", payload?.Exception ?.Message);
35-
Assert.True(payload?.Frames?.Count == 1);
35+
Assert.True(payload?.Frames?.Count == 2);
3636
var frame = payload?.Frames?.FirstOrDefault();
37-
Assert.Equal("Void SetsPayload()", frame?.Method);
37+
Assert.Equal("RollbarDotNet.Tests.Builder.ExceptionBuilderTests.ThrowException(System.String a, System.Int32 b)", frame?.Method);
3838
var stackTrace = new StackTrace(exception, true);
3939
var stackTraceFrame = stackTrace.GetFrames().FirstOrDefault();
4040
Assert.Equal(stackTraceFrame.GetFileColumnNumber(), frame?.ColumnNumber);
@@ -43,6 +43,11 @@ public void SetsPayload()
4343
}
4444
}
4545

46+
protected void ThrowException(string a, int b)
47+
{
48+
throw new System.Exception("test exception");
49+
}
50+
4651
[Fact]
4752
public void PayloadCannotBeNull()
4853
{

0 commit comments

Comments
 (0)