Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lucas-zimerman/b6f4333c274f48a6b6b70b23cca000e9 to your computer and use it in GitHub Desktop.
Save lucas-zimerman/b6f4333c274f48a6b6b70b23cca000e9 to your computer and use it in GitHub Desktop.
Quality of Life Sentry dotnet extensions.
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