Created
August 22, 2023 04:33
-
-
Save lucas-zimerman/b6f4333c274f48a6b6b70b23cca000e9 to your computer and use it in GitHub Desktop.
Quality of Life Sentry dotnet extensions.
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
using System; | |
using Sentry; | |
// requires constant __MOBILE__ else SentrySdk isnt partial | |
public static class SentrySdkExtensions | |
{ | |
// Requires SentrySdk to be partial. Otherwise can be called with SentrySdkExtensions.StartTransactionOrChild | |
public static ISpan StartTransactionOrChild(string name, string operation, string description = null) | |
{ | |
var span = Sentry.SentrySdk.GetSpan(); | |
if (span == null) | |
{ | |
return Sentry.SentrySdk.StartTransaction(name, operation); | |
} | |
return span.StartChild(name, description); | |
} | |
/// <summary> | |
/// Finishes a transaction, linking an exception and also captures the exception if desired. | |
/// </summary> | |
/// <param name="span">The selected Span.</param> | |
/// <param name="ex">The exception to be linked to the span</param> | |
/// <param name="captureException">Flag to </param> | |
public static void Finish(Sentry.ISpan span, Exception ex, bool captureException) | |
{ | |
span.Finish(ex); | |
if (captureException) | |
{ | |
SentrySdk.CaptureException(ex); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment