Skip to content

Commit

Permalink
Merge pull request #3 from lucas-zimerman/staging
Browse files Browse the repository at this point in the history
Transaction Sdk v2.0.0 and Session Sdk 1.0.0
  • Loading branch information
lucas-zimerman committed Sep 3, 2020
2 parents 1681643 + d84656c commit 472986f
Show file tree
Hide file tree
Showing 57 changed files with 2,090 additions and 109 deletions.
Binary file added .assets/nugget-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 3 additions & 24 deletions README.md
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
13 changes: 13 additions & 0 deletions SessionSdk.Test/Helpers/DsnHelper.cs
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";
}
}
23 changes: 23 additions & 0 deletions SessionSdk.Test/Initializer.cs
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) });
}
}
}
}
21 changes: 21 additions & 0 deletions SessionSdk.Test/SessionSdk.Test.csproj
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>
80 changes: 80 additions & 0 deletions SessionSdk.Test/SessionTest.cs
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);
}
}
}
13 changes: 13 additions & 0 deletions Testing/Helpers/DsnHelper.cs
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://[email protected]:65535/2147483647";
}
}
19 changes: 19 additions & 0 deletions Testing/Initializer.cs
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));
}
}
}
}
Loading

0 comments on commit 472986f

Please sign in to comment.