-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from lucas-zimerman/staging
v3.0.0 [Breaking Changes] -Merged SessionSdk and TracingSdk into ContribSentrySdk. -Enhanced the support to .NetCore for tracing. -Bugfixes.
- Loading branch information
Showing
99 changed files
with
2,242 additions
and
863 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
ContribSentry.AspNetCore.Tests/ContribSentry.AspNetCore.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.1.1" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.2" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> | ||
<PackageReference Include="Sentry.AspNetCore" Version="2.1.4" /> | ||
<PackageReference Include="xunit" Version="2.4.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /> | ||
<PackageReference Include="coverlet.collector" Version="1.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ContribSentry.AspNetCore\ContribSentry.AspNetCore.csproj" /> | ||
<ProjectReference Include="..\ContribSentry.Testing\ContribSentry.Testing.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
29 changes: 29 additions & 0 deletions
29
ContribSentry.AspNetCore.Tests/ContribSentryNetCoreSdkIntegrationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using ContribSentry.AspNetCore.Internals; | ||
using ContribSentry.Internals; | ||
using Sentry; | ||
using Xunit; | ||
|
||
namespace ContribSentry.AspNetCore.Tests | ||
{ | ||
public class ContribSentryNetCoreSdkIntegrationTests | ||
{ | ||
[Fact] | ||
public void Http_Tracking_Is_Set_On_Register_To_Main_Tracking_Service() | ||
{ | ||
try | ||
{ | ||
var integration = new ContribSentryNetCoreSdkIntegration(); | ||
integration.Register(null,new SentryOptions()); | ||
Assert.True(ContribSentrySdk.IsEnabled); | ||
Assert.True(ContribSentrySdk.IsTracingSdkEnabled); | ||
Assert.Equal(typeof(ContribSentryTracingService), ContribSentrySdk.TracingService.GetType()); | ||
var service = (ContribSentryTracingService)ContribSentrySdk.TracingService; | ||
Assert.Equal(typeof(HttpContextTracking), service.Tracker.GetType()); | ||
} | ||
finally | ||
{ | ||
ContribSentrySdk.Close(); | ||
} | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
ContribSentry.AspNetCore.Tests/Internals/HttpContextTrackingTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using ContribSentry; | ||
using ContribSentry.AspNetCore.Internals; | ||
using ContribSentry.Testing; | ||
using Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
using Sentry.AspNetCore; | ||
using Sentry.Extensibility; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace ContribSentry.AspNetCore.Tests.Internals | ||
{ | ||
public class HttpContextTrackingTests : ContribSentrySdkTestFixture | ||
{ | ||
protected Action<SentryAspNetCoreOptions> Configure; | ||
|
||
public HttpContextTrackingTests() | ||
{ | ||
ConfigureWehHost = builder => | ||
{ | ||
_ = builder.UseSentry(options => | ||
{ | ||
options.Dsn = DsnHelper.ValidDsnWithoutSecret; | ||
}); | ||
}; | ||
} | ||
|
||
private static HttpContextTracking _tracker; | ||
|
||
private static List<KeyValuePair<string, int>> _trackerList; | ||
|
||
private Action<HttpContext> TrackerIdMiddleware = (context) => { | ||
var id = _tracker.ReserveNewId(); | ||
_tracker.AssociateId(id); | ||
_trackerList.Add(_tracker._contextReference.Last(p => p.Value == id)); | ||
}; | ||
|
||
[Fact] | ||
public async Task Tracker_Receives_Unique_KeyPair_ForEach_Request() | ||
{ | ||
_tracker = new HttpContextTracking(); | ||
_trackerList = new List<KeyValuePair<string, int>>(); | ||
Build(TrackerIdMiddleware); | ||
_ = await HttpClient.GetAsync(""); | ||
_ = await HttpClient.GetAsync(""); | ||
_ = await HttpClient.GetAsync(""); | ||
_ = await HttpClient.GetAsync(""); | ||
_ = await HttpClient.GetAsync(""); | ||
foreach(var valuePair in _trackerList) | ||
{ | ||
Assert.Equal(1, _trackerList.Count(p => p.Key == valuePair.Key)); | ||
Assert.Equal(1, _trackerList.Count(p => p.Value == valuePair.Value)); | ||
} | ||
foreach (var valuePair in _trackerList) | ||
{ | ||
Assert.True(_tracker.UnsetId(valuePair.Value)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace ContribSentry.AspNetCore.Tests | ||
{ | ||
public class Startup | ||
{ | ||
public Startup(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public IConfiguration Configuration { get; } | ||
|
||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
} | ||
|
||
public void Configure(IApplicationBuilder app) | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using Xunit; | ||
|
||
namespace ContribSentry.AspNetCore.Tests | ||
{ | ||
public class UnitTest1 | ||
{ | ||
[Fact] | ||
public void Test1() | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"Sentry": { | ||
"Dsn": "https://[email protected]/1", | ||
"IncludeRequestPayload": true, | ||
"SendDefaultPii": true, | ||
"IncludeActivityData": true, | ||
"MinimumBreadcrumbLevel": "Error", | ||
"MinimumEventLevel": "Critical", | ||
"InitializeSdk": "false", | ||
"MaxBreadcrumbs": "999", | ||
"SampleRate": "1", | ||
"Release": "7f5d9a1", | ||
"Environment": "Staging" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<Version>3.0.0</Version> | ||
<Description>.Net Core Addon for ContribSentry</Description> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<PackageProjectUrl>https://github.com/lucas-zimerman/sentry-dotnet-performance-addon</PackageProjectUrl> | ||
<PackageIcon>nugget-logo.png</PackageIcon> | ||
<RepositoryUrl>https://github.com/lucas-zimerman/sentry-dotnet-performance-addon</RepositoryUrl> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ContribSentry\ContribSentry.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\.assets\nugget-logo.png"> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
34 changes: 34 additions & 0 deletions
34
ContribSentry.AspNetCore/ContribSentryNetCoreSdkIntegration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using ContribSentry.AspNetCore.Internals; | ||
using ContribSentry.Extensibility; | ||
using Sentry; | ||
using Sentry.Integrations; | ||
|
||
namespace ContribSentry.AspNetCore | ||
{ | ||
public class ContribSentryNetCoreSdkIntegration : ISdkIntegration | ||
{ | ||
internal ContribSentryOptions _options; | ||
public ContribSentryNetCoreSdkIntegration() | ||
{ | ||
_options = new ContribSentryOptions(sessionEnable:false); | ||
} | ||
|
||
public ContribSentryNetCoreSdkIntegration(ContribSentryOptions options) | ||
{ | ||
_options = new ContribSentryOptions(options.TransactionEnabled, false) | ||
{ | ||
DistinctId = options.DistinctId, | ||
RegisterTracingBreadcrumb = options.RegisterTracingBreadcrumb, | ||
TracesSampleRate = options.TracesSampleRate, | ||
}; | ||
_options.SetTracingService(options.TracingService); | ||
} | ||
|
||
public void Register(IHub hub, SentryOptions options) | ||
{ | ||
_options.TrackingIdMethod = new HttpContextTracking(); | ||
var integration = new ContribSentrySdkIntegration(_options); | ||
integration.Register(hub, options); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using ContribSentry.Interface; | ||
using Sentry; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace ContribSentry.AspNetCore.Internals | ||
{ | ||
internal class HttpContextTracking : ITracingContextTrackingId | ||
{ | ||
private readonly string _requestIdField = "RequestId"; | ||
|
||
internal List<KeyValuePair<string, int>> _contextReference = new List<KeyValuePair<string, int>>(); | ||
|
||
private object _lock = new object(); | ||
private int _value; | ||
private int InternalNewId() | ||
{ | ||
lock (_lock) | ||
{ | ||
int i = _value++; | ||
return i; | ||
} | ||
} | ||
|
||
private string GetrequestId() | ||
{ | ||
string id = null; | ||
SentrySdk.ConfigureScope((scope) => { id = scope.Tags[_requestIdField]; }); | ||
return id; | ||
} | ||
|
||
public int? GetId() | ||
{ | ||
var id = GetrequestId(); | ||
if (id == null) | ||
return null; | ||
return _contextReference.FirstOrDefault(p => p.Key == id).Value; | ||
} | ||
|
||
public bool IdRegistered(int id) | ||
{ | ||
return _contextReference.Any(v => v.Value == id); | ||
} | ||
|
||
/// <summary> | ||
/// Link the integer unique id to the Request Id | ||
/// </summary> | ||
/// <param name="id"></param> | ||
public void AssociateId(int id) | ||
{ | ||
_contextReference.Add(new KeyValuePair<string, int>(GetrequestId(), id)); | ||
} | ||
|
||
public int ReserveNewId() | ||
{ | ||
return InternalNewId(); | ||
} | ||
|
||
public bool UnsetId(int id) | ||
{ | ||
return _contextReference.Remove(_contextReference.First(p => p.Value == id)); | ||
} | ||
|
||
public Task WithIsolatedTracing(Func<Task> test, int id) | ||
{ | ||
return test.Invoke(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("ContribSentry.AspNetCore.Tests")] |
21 changes: 21 additions & 0 deletions
21
ContribSentry.SessionTest/ContribSentry.SessionTest.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> | ||
<PackageReference Include="Moq" Version="4.14.5" /> | ||
<PackageReference Include="xunit" Version="2.4.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /> | ||
<PackageReference Include="coverlet.collector" Version="1.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ContribSentry\ContribSentry.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace SessionSdk.Helpers | ||
{ | ||
/// <summary> | ||
/// Based on DsnSamples from Sentry.Net | ||
/// </summary> | ||
public class DsnHelper | ||
{ | ||
/// <summary> | ||
/// Sentry has dropped the use of secrets | ||
/// </summary> | ||
public const string ValidDsnWithoutSecret = "https://[email protected]:65535/2147483647"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Sentry; | ||
using ContribSentry; | ||
using SessionSdk.Helpers; | ||
|
||
namespace SessionSdk.Test | ||
{ | ||
public static class Initializer | ||
{ | ||
public const string TestRelease = "--1"; | ||
public const string TestEnvironment = "test"; | ||
public static void Init() | ||
{ | ||
if (!ContribSentrySdk.IsEnabled) | ||
{ | ||
var integration = new ContribSentrySdkIntegration(new ContribSentryOptions() { GlobalSessionMode = true }); | ||
integration.Register(null, new SentryOptions() { Release = TestRelease, Environment = TestEnvironment, Dsn = new Dsn(DsnHelper.ValidDsnWithoutSecret) }); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.