Clean code, remove warning for future and spot
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using Managing.Application.Abstractions;
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Domain.MoneyManagements;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -84,12 +83,12 @@ public class MoneyManagementController : BaseController
|
||||
{
|
||||
var user = await GetUser();
|
||||
var result = await _moneyManagementService.GetMoneyMangement(user, name);
|
||||
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
return NotFound($"Money management strategy '{name}' not found");
|
||||
}
|
||||
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -110,12 +109,12 @@ public class MoneyManagementController : BaseController
|
||||
{
|
||||
var user = await GetUser();
|
||||
var result = await _moneyManagementService.DeleteMoneyManagement(user, name);
|
||||
|
||||
|
||||
if (!result)
|
||||
{
|
||||
return NotFound($"Money management strategy '{name}' not found or could not be deleted");
|
||||
}
|
||||
|
||||
|
||||
return Ok(new { success = true, message = $"Money management strategy '{name}' deleted successfully" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Sentry;
|
||||
using System;
|
||||
|
||||
namespace Managing.Api.Controllers
|
||||
{
|
||||
@@ -26,22 +24,22 @@ namespace Managing.Api.Controllers
|
||||
{
|
||||
// Add breadcrumbs for context
|
||||
SentrySdk.AddBreadcrumb("About to capture test exception", "test");
|
||||
|
||||
|
||||
// Add context to the error
|
||||
SentrySdk.ConfigureScope(scope =>
|
||||
{
|
||||
scope.SetTag("test_type", "manual_exception");
|
||||
scope.SetExtra("timestamp", DateTime.Now);
|
||||
});
|
||||
|
||||
|
||||
// Log to both Serilog and Sentry
|
||||
_logger.LogError(ex, "Test exception captured in SentryTestController");
|
||||
|
||||
|
||||
// Explicitly capture exception
|
||||
SentrySdk.CaptureException(ex);
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
message = "Exception manually captured and sent to Sentry",
|
||||
exceptionMessage = ex.Message,
|
||||
timestamp = DateTime.Now
|
||||
@@ -53,7 +51,7 @@ namespace Managing.Api.Controllers
|
||||
public IActionResult ThrowException()
|
||||
{
|
||||
_logger.LogInformation("About to throw an uncaught exception");
|
||||
|
||||
|
||||
// This should be automatically captured by Sentry middleware
|
||||
throw new InvalidOperationException($"Uncaught exception from ThrowException endpoint - {DateTime.Now}");
|
||||
}
|
||||
@@ -63,12 +61,12 @@ namespace Managing.Api.Controllers
|
||||
{
|
||||
// Send a simple message to Sentry
|
||||
SentrySdk.CaptureMessage("Test message from Managing API", SentryLevel.Info);
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
message = "Test message sent to Sentry",
|
||||
timestamp = DateTime.Now
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
using Sentry;
|
||||
using System.Text;
|
||||
|
||||
namespace Managing.Api.Middleware
|
||||
@@ -37,17 +36,20 @@ namespace Managing.Api.Middleware
|
||||
// Check if Sentry is initialized
|
||||
response.AppendLine("## Sentry SDK Status");
|
||||
response.AppendLine($"Sentry Enabled: {SentrySdk.IsEnabled}");
|
||||
response.AppendLine($"Application Environment: {Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}");
|
||||
response.AppendLine(
|
||||
$"Application Environment: {Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}");
|
||||
response.AppendLine();
|
||||
|
||||
|
||||
// Send a test event
|
||||
response.AppendLine("## Test Event");
|
||||
try
|
||||
{
|
||||
var id = SentrySdk.CaptureMessage($"Diagnostics test from {context.Request.Host} at {DateTime.Now}", SentryLevel.Info);
|
||||
var id = SentrySdk.CaptureMessage($"Diagnostics test from {context.Request.Host} at {DateTime.Now}",
|
||||
SentryLevel.Info);
|
||||
response.AppendLine($"Test Event ID: {id}");
|
||||
response.AppendLine("Test event was sent to Sentry. Check your Sentry dashboard to confirm it was received.");
|
||||
|
||||
response.AppendLine(
|
||||
"Test event was sent to Sentry. Check your Sentry dashboard to confirm it was received.");
|
||||
|
||||
// Try to send an exception too
|
||||
try
|
||||
{
|
||||
@@ -69,10 +71,11 @@ namespace Managing.Api.Middleware
|
||||
response.AppendLine("## Connectivity Check");
|
||||
response.AppendLine("If events are not appearing in Sentry, check the following:");
|
||||
response.AppendLine("1. Verify your DSN is correct in appsettings.json");
|
||||
response.AppendLine("2. Ensure your network allows outbound HTTPS connections to sentry.apps.managing.live");
|
||||
response.AppendLine(
|
||||
"2. Ensure your network allows outbound HTTPS connections to sentry.apps.managing.live");
|
||||
response.AppendLine("3. Check Sentry server logs for any ingestion issues");
|
||||
response.AppendLine("4. Verify your Sentry project is correctly configured to receive events");
|
||||
|
||||
|
||||
// Return the diagnostic information
|
||||
context.Response.ContentType = "text/plain";
|
||||
await context.Response.WriteAsync(response.ToString());
|
||||
@@ -87,4 +90,4 @@ namespace Managing.Api.Middleware
|
||||
return builder.UseMiddleware<SentryDiagnosticsMiddleware>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
using Managing.Common;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Api.Models.Requests;
|
||||
@@ -7,4 +6,4 @@ public class OpenPositionManuallyRequest
|
||||
{
|
||||
public string BotName { get; set; }
|
||||
public TradeDirection Direction { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user