Clean code, remove warning for future and spot
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
using Sentry;
|
||||
|
||||
namespace Managing.Api.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
@@ -14,14 +12,15 @@ public static class SentryErrorCapture
|
||||
/// <param name="contextName">A descriptive name for where the error occurred</param>
|
||||
/// <param name="extraData">Optional dictionary of additional data to include</param>
|
||||
/// <returns>The Sentry event ID</returns>
|
||||
public static SentryId CaptureException(Exception exception, string contextName, IDictionary<string, object> extraData = null)
|
||||
public static SentryId CaptureException(Exception exception, string contextName,
|
||||
IDictionary<string, object> extraData = null)
|
||||
{
|
||||
return SentrySdk.CaptureException(exception, scope =>
|
||||
{
|
||||
// Add context information
|
||||
scope.SetTag("context", contextName);
|
||||
scope.SetTag("error_type", exception.GetType().Name);
|
||||
|
||||
|
||||
// Add any extra data provided
|
||||
if (extraData != null)
|
||||
{
|
||||
@@ -30,7 +29,7 @@ public static class SentryErrorCapture
|
||||
scope.SetExtra(kvp.Key, kvp.Value?.ToString() ?? "null");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Add extra info from the exception's Data dictionary if available
|
||||
foreach (var key in exception.Data.Keys)
|
||||
{
|
||||
@@ -39,7 +38,7 @@ public static class SentryErrorCapture
|
||||
scope.SetExtra($"exception_data_{keyStr}", exception.Data[key].ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Add a breadcrumb for context
|
||||
scope.AddBreadcrumb(
|
||||
message: $"Exception in {contextName}",
|
||||
@@ -48,7 +47,7 @@ public static class SentryErrorCapture
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Enriches an exception with additional context data before throwing
|
||||
/// </summary>
|
||||
@@ -64,10 +63,10 @@ public static class SentryErrorCapture
|
||||
exception.Data[item.Key] = item.Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return exception;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Captures a message in Sentry with additional context
|
||||
/// </summary>
|
||||
@@ -76,17 +75,18 @@ public static class SentryErrorCapture
|
||||
/// <param name="contextName">A descriptive name for where the message originated</param>
|
||||
/// <param name="extraData">Optional dictionary of additional data to include</param>
|
||||
/// <returns>The Sentry event ID</returns>
|
||||
public static SentryId CaptureMessage(string message, SentryLevel level, string contextName, IDictionary<string, object> extraData = null)
|
||||
public static SentryId CaptureMessage(string message, SentryLevel level, string contextName,
|
||||
IDictionary<string, object> extraData = null)
|
||||
{
|
||||
// First capture the message with the specified level
|
||||
var id = SentrySdk.CaptureMessage(message, level);
|
||||
|
||||
|
||||
// Then add context via a scope
|
||||
SentrySdk.ConfigureScope(scope =>
|
||||
{
|
||||
// Add context information
|
||||
scope.SetTag("context", contextName);
|
||||
|
||||
|
||||
// Add any extra data provided
|
||||
if (extraData != null)
|
||||
{
|
||||
@@ -95,7 +95,7 @@ public static class SentryErrorCapture
|
||||
scope.SetExtra(kvp.Key, kvp.Value?.ToString() ?? "null");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Add a breadcrumb for context
|
||||
scope.AddBreadcrumb(
|
||||
message: $"Message from {contextName}",
|
||||
@@ -103,7 +103,7 @@ public static class SentryErrorCapture
|
||||
level: BreadcrumbLevel.Info
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user