-
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 #3 from lucas-zimerman/staging
Transaction Sdk v2.0.0 and Session Sdk 1.0.0
- Loading branch information
Showing
57 changed files
with
2,090 additions
and
109 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,25 +1,4 @@ | ||
# sentry dotnet transaction addon | ||
### Unnoficial addon for adding Peformance support to Sentry-dotnet | ||
# SentryContrib | ||
### Unnoficial addons for Sentry.Net SDK | ||
|
||
Official Docs: https://docs.sentry.io/performance-monitoring/getting-started/ | ||
|
||
##### Usage: | ||
|
||
```C# | ||
SentryTracingSDK.Init(dsn, tracesSampleRate); can be called before or after SentrySdk.Init. | ||
|
||
var transaction = SentryTracingSDK.StartTransaction( name );// return a new transaction. | ||
var child = transaction.StartChild( name );// return a new child | ||
child.Finish();// finishes the child | ||
// You can add as many childs as you wish on a transaction | ||
transaction.Finish();// finishes and sends the transaction | ||
``` | ||
|
||
##### You'll need to add an additional code inside of your BeforeSend code | ||
```C# | ||
if (arg is SentryTransaction transaction) | ||
{ | ||
transaction.SendTransaction(); | ||
return null; | ||
} | ||
``` | ||
For more information check the Wiki |
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://d4d82fc1c2c4032a83f3a29aa3a3aff@fake-sentry.io: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 sentry_dotnet_health_addon; | ||
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 (!SentrySessionSdk.IsEnabled) | ||
{ | ||
var integration = new SentrySessionSdkIntegration(new SentrySessionOptions() { GlobalHubMode = true }); | ||
integration.Register(null, new SentryOptions() { Release = TestRelease, Environment = TestEnvironment, Dsn = new Dsn(DsnHelper.ValidDsnWithoutSecret) }); | ||
} | ||
} | ||
} | ||
} |
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="..\sentry-dotnet-health-addon\SentryContrib.SessionSdk.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,80 @@ | ||
using Moq; | ||
using Sentry.Protocol; | ||
using sentry_dotnet_health_addon; | ||
using sentry_dotnet_health_addon.Enums; | ||
using sentry_dotnet_health_addon.Internals; | ||
using System; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace SessionSdk.Test | ||
{ | ||
public class SessionTest | ||
{ | ||
[Fact] | ||
public void Session_Start_Should_Set_Default_Parameters() | ||
{ | ||
var user = new User() | ||
{ | ||
Id = "123", | ||
IpAddress = "127.0.0.1" | ||
}; | ||
var session = CreateSession(user); | ||
Assert.Equal(user.IpAddress,session.Attributes.IpAddress); | ||
Assert.Equal(Initializer.TestRelease, session.Attributes.Release); | ||
Assert.Equal(Initializer.TestEnvironment, session.Attributes.Environment); | ||
Assert.Null(session.DistinctId); | ||
Assert.NotNull(session.Init); | ||
Assert.Equal(SessionState.Ok, session.Status); | ||
Assert.NotNull(session.SessionId); | ||
} | ||
|
||
[Fact] | ||
public async Task Session_End_Status_Is_Exited_And_Timestamp_Higher_Than_Start() | ||
{ | ||
var user = new User() | ||
{ | ||
Id = "123", | ||
IpAddress = "127.0.0.1" | ||
}; | ||
var session = CreateSession(user); | ||
await Task.Delay(10); | ||
session.End(); | ||
Assert.Equal(SessionState.Exited, session.Status); | ||
Assert.True(session.Timestamp > session.Started); | ||
} | ||
|
||
[Fact] | ||
private void Session_Crashed_When_Ended_Has_Status_Crashed() | ||
{ | ||
var user = new User() | ||
{ | ||
Id = "123", | ||
IpAddress = "127.0.0.1" | ||
}; | ||
var session = CreateSession(user); | ||
session.Status = SessionState.Crashed; | ||
session.End(null); | ||
Assert.Equal(SessionState.Crashed, session.Status); | ||
} | ||
|
||
[Fact] | ||
private void Session_End_With_TimeStamp_Has_Timestamp() | ||
{ | ||
var user = new User() | ||
{ | ||
Id = "123", | ||
IpAddress = "127.0.0.1" | ||
}; | ||
var session = CreateSession(user); | ||
var date = DateTime.Now.AddSeconds(5); | ||
session.End(date); | ||
Assert.Equal(date, session.Timestamp); | ||
} | ||
|
||
private Session CreateSession(User user) | ||
{ | ||
return new Session(null, user, Initializer.TestEnvironment, Initializer.TestRelease); | ||
} | ||
} | ||
} |
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 Testing.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://d4d82fc1c2c4032a83f3a29aa3a3aff@fake-sentry.io: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,19 @@ | ||
using Sentry; | ||
using sentry_dotnet_transaction_addon; | ||
using Testing.Helpers; | ||
|
||
namespace Testing | ||
{ | ||
public static class Initializer | ||
{ | ||
public static void Init() | ||
{ | ||
if (!SentryTracingSdk.IsEnabled()) | ||
{ | ||
var integration = new SentryTracingSdkIntegration(); | ||
integration.Register(null, new SentryOptions()); | ||
SentryTracingSdk.SetDsn(new Dsn(DsnHelper.ValidDsnWithoutSecret)); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.