Skip to content

Commit 9d4ede2

Browse files
authored
Merge pull request #597 from WideSpectrumComputing/master
resolve #585, refactoring and codebase cleanup
2 parents 8117a15 + c735413 commit 9d4ede2

File tree

58 files changed

+974
-257
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+974
-257
lines changed

Benchmarker.Common/Benchmarker.Common.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77

88
<PropertyGroup>
99
<!--TargetFramework>netstandard2.0</TargetFramework-->
10-
<TargetFrameworks>netcoreapp3.0;netcoreapp2.2;netcoreapp2.1;netcoreapp2.0;net48;net472;net471;net47;net462;net461;netstandard2.1;netstandard2.0</TargetFrameworks>
10+
<TargetFrameworks>netstandard2.0</TargetFrameworks>
1111
<PlatformTarget>AnyCPU</PlatformTarget>
12+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
1213
</PropertyGroup>
1314

1415
<ItemGroup>
15-
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
16+
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
1617
<PackageReference Include="coverlet.collector" Version="3.1.0">
1718
<PrivateAssets>all</PrivateAssets>
1819
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

Benchmarker.Common/BenchmarksConfig.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
{
33
using BenchmarkDotNet.Configs;
44
using BenchmarkDotNet.Environments;
5-
using BenchmarkDotNet.Horology;
5+
//using BenchmarkDotNet.Horology;
66
using BenchmarkDotNet.Jobs;
77

8+
using Perfolizer.Horology;
9+
810
public class BenchmarksConfig : ManualConfig
911
{
1012
public BenchmarksConfig()

Rollbar.AppSettings.Json/Rollbar.AppSettings.Json.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
<Project ToolsVersion="Current">
1+
<Project ToolsVersion="Current">
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<!--TargetFrameworks>netcoreapp3.0;netcoreapp2.2;netcoreapp2.1;netcoreapp2.0;net48;net472;net471;net47;net462;net461;net46;net452;net451;netstandard2.1;netstandard2.0</TargetFrameworks-->
66
<AssemblyName>Rollbar.AppSettings.Json</AssemblyName>
77
<RootNamespace>Rollbar.AppSettings.Json</RootNamespace>
8+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
89
</PropertyGroup>
910

1011
<Import Project="..\SdkCommon.csproj" />

Rollbar.Deploys/Rollbar.Deploys.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<Project ToolsVersion="Current">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
4+
<TargetFramework>netstandard2.0</TargetFramework>
55
<AssemblyName>Rollbar.Deploys</AssemblyName>
66
<RootNamespace>Rollbar.Deploys</RootNamespace>
7+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
78
</PropertyGroup>
89

910
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.1|AnyCPU'">

Rollbar.Net.AspNet.Mvc/Rollbar.Net.AspNet.Mvc.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<Project ToolsVersion="Current">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net48;net472;net471;net47;net462;net461;net46;net452;net451</TargetFrameworks>
4+
<TargetFrameworks>net48;net472;net471;net47;net462;net461;net46;net452</TargetFrameworks>
55
<!--TargetFrameworks>net48;net472;net471;net47;net462;net461</TargetFrameworks-->
66
<AssemblyName>Rollbar.Net.AspNet.Mvc</AssemblyName>
77
<RootNamespace>Rollbar.Net.AspNet.Mvc</RootNamespace>
8+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
89
</PropertyGroup>
910

1011
<Import Project="..\SdkCommon.csproj" />

Rollbar.Net.AspNet.WebApi/Rollbar.Net.AspNet.WebApi.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<Project ToolsVersion="Current">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net48;net472;net471;net47;net462;net461;net46;net452;net451</TargetFrameworks>
4+
<TargetFrameworks>net48;net472;net471;net47;net462;net461;net46;net452</TargetFrameworks>
55
<AssemblyName>Rollbar.Net.AspNet.WebApi</AssemblyName>
66
<RootNamespace>Rollbar.Net.AspNet.WebApi</RootNamespace>
7+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
78
</PropertyGroup>
89

910
<Import Project="..\SdkCommon.csproj" />

Rollbar.Net.AspNet/Rollbar.Net.AspNet.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<Project ToolsVersion="Current">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net48;net472;net471;net47;net462;net461;net46;net452;net451</TargetFrameworks>
4+
<TargetFrameworks>net48;net472;net471;net47;net462;net461;net46;net452</TargetFrameworks>
55
<!--TargetFrameworks>net48;net472;net471;net47;net462;net461</TargetFrameworks-->
66
<AssemblyName>Rollbar.Net.AspNet</AssemblyName>
77
<RootNamespace>Rollbar.Net.AspNet</RootNamespace>
8+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
89
</PropertyGroup>
910

1011
<Import Project="..\SdkCommon.csproj" />

Rollbar.NetCore.AspNet/ApplicationBuilderExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using Microsoft.Extensions.DependencyInjection;
44
using Microsoft.Extensions.Logging;
5+
56
using Rollbar.NetCore.AspNet;
67

78
/// <summary>

Rollbar.NetCore.AspNet/HttpRequestPackageDecorator.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
using System.Linq;
2-
3-
namespace Rollbar.NetCore.AspNet
1+
namespace Rollbar.NetCore.AspNet
42
{
53
using System.Collections.Generic;
4+
65
using Microsoft.AspNetCore.Http;
6+
using Microsoft.AspNetCore.Http.Features;
7+
78
using Rollbar.Common;
89
using Rollbar.DTOs;
9-
using Rollbar.Serialization.Json;
1010

1111
/// <summary>
1212
/// Class HttpRequestPackageDecorator.
@@ -64,6 +64,15 @@ protected override void Decorate(Data? rollbarData)
6464
rollbarData.Request = new Request();
6565
}
6666

67+
68+
rollbarData.Request["httpRequestID"] =
69+
this._httpRequest.HttpContext
70+
.Features?
71+
.Get<IHttpRequestIdentifierFeature>()?
72+
.TraceIdentifier;
73+
rollbarData.Request["scheme"] = this._httpRequest.Scheme;
74+
rollbarData.Request["protocol"] = this._httpRequest.Protocol;
75+
6776
rollbarData.Request.Url = this._httpRequest.Host.Value + this._httpRequest.Path;
6877
rollbarData.Request.QueryString = this._httpRequest.QueryString.Value;
6978
if (!string.IsNullOrWhiteSpace(this._httpRequest.Path))
@@ -116,18 +125,12 @@ private void AssignRequestBody(Request request)
116125
return; // nothing to do...
117126
}
118127

119-
string? jsonString = StreamUtil.ConvertToString(this._httpRequest.Body);
120-
if (string.IsNullOrWhiteSpace(jsonString))
128+
string? jsonString = StreamUtil.CaptureAsStringAsync(this._httpRequest.Body).Result;
129+
if(string.IsNullOrWhiteSpace(jsonString))
121130
{
122131
return;
123132
}
124133
request.PostBody = jsonString;
125-
126-
object? requesBodyObject = JsonUtil.InterpretAsJsonObject(jsonString);
127-
if (requesBodyObject != null)
128-
{
129-
request.PostBody = requesBodyObject;
130-
}
131134
}
132135
}
133136
}

Rollbar.NetCore.AspNet/HttpResponsePackageDecorator.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
namespace Rollbar.NetCore.AspNet
22
{
33
using System.Collections.Generic;
4+
45
using Microsoft.AspNetCore.Http;
6+
57
using Rollbar.Common;
68
using Rollbar.DTOs;
7-
using Rollbar.Serialization.Json;
89

910
/// <summary>
1011
/// Class HttpResponsePackageDecorator.
@@ -88,18 +89,12 @@ private void AssignResponseBody(Response response)
8889
return; // nothing to do...
8990
}
9091

91-
string? jsonString = StreamUtil.ConvertToString(this._httpResponse.Body);
92+
string? jsonString = StreamUtil.CaptureAsStringAsync(this._httpResponse.Body).Result;
9293
if (string.IsNullOrWhiteSpace(jsonString))
9394
{
9495
return;
9596
}
9697
response.Body = jsonString;
97-
98-
object? responseBodyObject = JsonUtil.InterpretAsJsonObject(jsonString);
99-
if (responseBodyObject != null)
100-
{
101-
response.Body = responseBodyObject;
102-
}
10398
}
10499

105100
}

Rollbar.NetCore.AspNet/Rollbar.NetCore.AspNet.csproj

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<Project ToolsVersion="Current">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp3.0;netcoreapp2.2;netcoreapp2.1;netcoreapp2.0;netstandard2.1;netstandard2.0</TargetFrameworks>
4+
<TargetFrameworks>net5.0;netcoreapp3.1</TargetFrameworks>
5+
<!--TargetFrameworks>net5.0;netcoreapp3.1;netcoreapp2.2;netcoreapp2.1;netcoreapp2.0;netstandard2.1;netstandard2.0</TargetFrameworks-->
56
<AssemblyName>Rollbar.NetCore.AspNet</AssemblyName>
67
<RootNamespace>Rollbar.NetCore.AspNet</RootNamespace>
8+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
79
</PropertyGroup>
810

911
<Import Project="..\SdkCommon.csproj" />
@@ -20,11 +22,36 @@
2022
<ProjectReference Include="..\Rollbar\Rollbar.csproj" />
2123
</ItemGroup>
2224

23-
<ItemGroup Label="Unconditional Package References">
24-
</ItemGroup>
25-
2625
<Choose>
27-
<When Condition="$(TargetFramework.StartsWith('netcoreapp3.')) Or '$(TargetFramework)' == 'netstandard2.1'">
26+
<When Condition="'$(TargetFramework)' == 'net5.0'">
27+
<ItemGroup Label="Unconditional Package References">
28+
<PackageReference Include="Microsoft.AspNetCore.App" Version="5.0.*"/>
29+
</ItemGroup>
30+
</When>
31+
<When Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
32+
<ItemGroup Label="Unconditional Package References">
33+
<PackageReference Include="Microsoft.AspNetCore.App" Version="3.1.*"/>
34+
</ItemGroup>
35+
</When>
36+
</Choose>
37+
38+
<!--Choose>
39+
<When Condition="'$(TargetFramework)' == 'netstandard2.0'">
40+
<PropertyGroup Label=".NetStandard 2.0 build">
41+
<NetVariant>NET_STANDARD</NetVariant>
42+
<DefineConstants>$(DefineConstants);NETSTANDARD_2_0</DefineConstants>
43+
</PropertyGroup>
44+
</When>
45+
<When Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
46+
<PropertyGroup Label=".NetCore 2.0 build">
47+
<NetVariant>NET_CORE</NetVariant>
48+
<DefineConstants>$(DefineConstants);NETCORE_2_0</DefineConstants>
49+
</PropertyGroup>
50+
</When>
51+
</Choose-->
52+
53+
<!--Choose>
54+
<When Condition="'$(TargetFramework)' == 'net5.0' Or $(TargetFramework.StartsWith('netcoreapp3.')) Or '$(TargetFramework)' == 'netstandard2.1'">
2855
<ItemGroup Label="Package References">
2956
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
3057
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
@@ -42,6 +69,6 @@
4269
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.0.0" />
4370
</ItemGroup>
4471
</Otherwise>
45-
</Choose>
72+
</Choose-->
4673

4774
</Project>

Rollbar.NetCore.AspNet/RollbarHttpAttributes.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
using Microsoft.AspNetCore.Http;
44
using Microsoft.AspNetCore.Http.Features;
55

6+
using Rollbar.Common;
7+
68
/// <summary>
79
/// Implements a capture bag of HTTP context attributes of interest.
810
/// </summary>
911
public class RollbarHttpAttributes
1012
{
13+
//private readonly HttpResponse _httpResponse;
14+
private readonly HttpContext? _httpContext;
15+
1116
/// <summary>
1217
/// Prevents a default instance of the <see cref="RollbarHttpAttributes" /> class from being created.
1318
/// </summary>
@@ -28,9 +33,12 @@ public RollbarHttpAttributes(HttpContext? context)
2833
return;
2934
}
3035

36+
this._httpContext = context;
37+
3138
this.RequestID = context.Features?
3239
.Get<IHttpRequestIdentifierFeature>()?
3340
.TraceIdentifier;
41+
3442
if (context.Request != null)
3543
{
3644
this.RequestHost = context.Request.Host;
@@ -40,7 +48,9 @@ public RollbarHttpAttributes(HttpContext? context)
4048
this.RequestQuery = context.Request.QueryString;
4149
this.RequestProtocol = context.Request.Protocol;
4250
this.RequestScheme = context.Request.Scheme;
51+
this.RequestBody = RollbarHttpAttributes.CaptureRequestBody(context.Request);
4352
}
53+
4454
if (context.Response != null)
4555
{
4656
this.ResponseStatusCode = context.Response.StatusCode;
@@ -74,6 +84,12 @@ public RollbarHttpAttributes(HttpContext? context)
7484
/// <value>The request method.</value>
7585
public string? RequestMethod { get; }
7686

87+
/// <summary>
88+
/// Gets the request body.
89+
/// </summary>
90+
/// <value>The request body.</value>
91+
public string? RequestBody { get; }
92+
7793
/// <summary>
7894
/// Gets the request headers.
7995
/// </summary>
@@ -109,5 +125,62 @@ public RollbarHttpAttributes(HttpContext? context)
109125
/// </summary>
110126
/// <value>The response headers.</value>
111127
public IHeaderDictionary? ResponseHeaders { get; }
128+
129+
/// <summary>
130+
/// Gets the response body.
131+
/// </summary>
132+
/// <value>The response body.</value>
133+
public string? ResponseBody
134+
{
135+
get
136+
{
137+
return RollbarHttpAttributes.CaptureResponseBody(this._httpContext?.Response);
138+
}
139+
}
140+
141+
/// <summary>
142+
/// Captures the request body.
143+
/// </summary>
144+
/// <param name="request">The request.</param>
145+
/// <returns>System.String.</returns>
146+
public static string? CaptureRequestBody(HttpRequest? request)
147+
{
148+
if(request == null
149+
|| request.ContentLength == null
150+
|| !(request.ContentLength > 0)
151+
|| !request.Body.CanSeek
152+
)
153+
{
154+
return null;
155+
}
156+
157+
string? bodyContent =
158+
StreamUtil.CaptureAsStringAsync(request.BodyReader.AsStream(true)).Result;
159+
160+
return bodyContent;
161+
}
162+
163+
/// <summary>
164+
/// Captures the response body.
165+
/// </summary>
166+
/// <param name="response">The response.</param>
167+
/// <returns>System.String.</returns>
168+
public static string? CaptureResponseBody(HttpResponse? response)
169+
{
170+
171+
if (response == null
172+
|| response.ContentLength == null
173+
|| !(response.ContentLength > 0)
174+
|| !response.Body.CanSeek
175+
)
176+
{
177+
return null;
178+
}
179+
180+
string? bodyContent =
181+
StreamUtil.CaptureAsStringAsync(response.BodyWriter.AsStream(true)).Result;
182+
183+
return bodyContent;
184+
}
112185
}
113186
}

0 commit comments

Comments
 (0)