-
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.
Showing
34 changed files
with
1,092 additions
and
56 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,55 +1,4 @@ | ||
# sentry dotnet transaction addon V2.0.0 | ||
### Unnoficial addon for adding Peformance support to Sentry-dotnet | ||
# SentryContrib | ||
### Unnoficial addons for Sentry.Net SDK | ||
|
||
# Status | ||
Currently in Alpha, not all features were implemented and you may experience errors or lose of Performance events. | ||
|
||
Official Docs: https://docs.sentry.io/performance-monitoring/getting-started/ | ||
|
||
# Configuration | ||
|
||
To initialize the performance addon you'll need add the SentryTracingSdkIntegration to your SentryOptions integration. | ||
```C# | ||
sentryOptions.AddIntegration(new SentryTracingSdkIntegration()); | ||
``` | ||
you'll of course need to initialize SentrySdk giving passing the SentryOptions where you added the Integration. | ||
|
||
# Usage | ||
You can start/finish a Transaction by creating an transaction Object or by 'using' | ||
```C# | ||
var transaction = SentryTracingSDK.StartTransaction( name );// return a new transaction. | ||
var child = transaction.StartChild( name );// return a new child | ||
... code to be measured | ||
child.Finish();// finishes the child | ||
// You can add as many childs as you wish on a transaction | ||
transaction.Finish();// finishes and sends the transaction | ||
``` | ||
```C# | ||
using(var transaction = SentryTracingSDK.StartTransaction( name )) | ||
{ | ||
var child = transaction.StartChild( name );// return a new child | ||
... code to be measured | ||
child.Finish();// finishes the child | ||
// You can add as many childs as you wish on a transaction | ||
} | ||
``` | ||
|
||
You can also start a child anywhere in the code, as long as there's an active Isolated Transaction, else | ||
the child will be discarted | ||
```C# | ||
using(var child = SentryTracingSDK.StartChild( url, Post )) | ||
{ | ||
... your http request here | ||
child.Finish(httpstatuscode);// child finished with the current status code | ||
} | ||
``` | ||
|
||
To isolate a Transaction if you would like to start a child by not referencing the Tracing object you'll need to run the following code | ||
```C# | ||
var transaction = SentryTracingSDK.StartTransaction( name ); | ||
await transaction.IsolateTracking(async ()=>{ | ||
// your code here | ||
}); | ||
transaction.Finish(); | ||
``` | ||
That way, if the code SentryTracingSDK.StartChild is called and the stack trace is inside of an isolated Transaction block, the Span will be attached to the Isolated Transaction. | ||
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://[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 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,11 @@ | ||
namespace sentry_dotnet_health_addon.Enums | ||
{ | ||
public enum ESentryType | ||
{ | ||
Session, | ||
Event, | ||
Attachment, | ||
Transaction, | ||
Unknown | ||
} | ||
} |
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,10 @@ | ||
namespace sentry_dotnet_health_addon.Enums | ||
{ | ||
public enum SessionState | ||
{ | ||
Ok, | ||
Exited, | ||
Crashed, | ||
Abnormal // not currently used in this SDK. | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
sentry-dotnet-health-addon/Extensibility/DisabledSession.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,36 @@ | ||
using sentry_dotnet_health_addon.Enums; | ||
using System; | ||
|
||
namespace sentry_dotnet_health_addon.Extensibility | ||
{ | ||
public class DisabledSession : ISession | ||
{ | ||
public static DisabledSession Instance = new DisabledSession(); | ||
public DateTime? Started { get; private set; } | ||
|
||
public DateTime? Timestamp { get; private set; } | ||
|
||
public int? ErrorCount { get; private set; } | ||
|
||
public string DistinctId { get; private set; } | ||
|
||
public Guid SessionId { get; private set; } | ||
|
||
public bool? Init { get; private set; } | ||
|
||
public SessionState Status { get; set; } | ||
|
||
public long? Sequence { get; private set; } | ||
|
||
public long? Duration { get; private set; } | ||
|
||
public SessionAttributes Attributes { get; private set; } | ||
|
||
public void End(DateTime? timestamp) {} | ||
|
||
public void RegisterError() {} | ||
|
||
public DisabledSession() {} | ||
|
||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
sentry-dotnet-health-addon/Extensions/DateTimeExtensions.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,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace sentry_dotnet_health_addon.Extensions | ||
{ | ||
internal static class DateTimeExtensions | ||
{ | ||
private static readonly DateTime _epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); | ||
|
||
internal static double TotalUtcSeconds(this DateTime date) | ||
{ | ||
return (date - _epoch).TotalSeconds; | ||
} | ||
|
||
internal static double TotalUtcMiliseconds(this DateTime date) | ||
{ | ||
return (date - _epoch).TotalMilliseconds; | ||
} | ||
} | ||
} |
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,12 @@ | ||
using Sentry; | ||
|
||
namespace sentry_dotnet_health_addon.Extensions | ||
{ | ||
internal static class DsnExtensions | ||
{ | ||
internal static string GetTracingUrl(this Dsn dsn) | ||
{ | ||
return $"{dsn.SentryUri.Scheme}://{dsn.SentryUri.Host}/api/{dsn.ProjectId}/envelope/?sentry_key={dsn.PublicKey}&sentry_version=7"; | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
sentry-dotnet-health-addon/Extensions/ESentryTypeExtensions.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,23 @@ | ||
using sentry_dotnet_health_addon.Enums; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace sentry_dotnet_health_addon.Extensions | ||
{ | ||
internal static class ESentryTypeExtensions | ||
{ | ||
public static string ConvertString(this ESentryType type) | ||
{ | ||
if (type == ESentryType.Attachment) | ||
return "attachment"; | ||
if (type == ESentryType.Event) | ||
return "event"; | ||
if (type == ESentryType.Session) | ||
return "session"; | ||
if (type == ESentryType.Transaction) | ||
return "transaction"; | ||
return "unknown"; | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
sentry-dotnet-health-addon/Extensions/SessionStateExtensions.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,20 @@ | ||
using sentry_dotnet_health_addon.Enums; | ||
|
||
namespace sentry_dotnet_health_addon.Extensions | ||
{ | ||
public static class SessionStateExtensions | ||
{ | ||
public static string ConvertString(this SessionState state) | ||
{ | ||
if (state == SessionState.Ok) | ||
return "ok"; | ||
if (state == SessionState.Exited) | ||
return "exited"; | ||
if (state == SessionState.Crashed) | ||
return "crashed"; | ||
if( state == SessionState.Abnormal) | ||
return "abnormal"; | ||
return null; | ||
} | ||
} | ||
} |
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 @@ | ||
using sentry_dotnet_health_addon.Enums; | ||
using System; | ||
|
||
namespace sentry_dotnet_health_addon | ||
{ | ||
public interface ISession | ||
{ | ||
DateTime? Started { get; } | ||
DateTime? Timestamp { get; } | ||
int? ErrorCount { get; } | ||
string DistinctId { get; } | ||
Guid SessionId { get; } | ||
bool? Init { get; } | ||
SessionState Status { get; set; } | ||
long? Sequence { get; } | ||
long? Duration { get; } | ||
SessionAttributes Attributes { get; } | ||
void End(DateTime? timestamp); | ||
void RegisterError(); | ||
} | ||
} |
Oops, something went wrong.