Add Sentry (#19)

* add sentry

* add sentry

* better log web3proxy

* Add managing and worker on sentry

* better log web3proxy
This commit is contained in:
Oda
2025-04-22 20:49:02 +02:00
committed by GitHub
parent df5f7185c8
commit 42a4cafd8d
40 changed files with 2959 additions and 146 deletions

View File

@@ -0,0 +1,74 @@
using Microsoft.AspNetCore.Mvc;
using Sentry;
using System;
namespace Managing.Api.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class SentryTestController : ControllerBase
{
private readonly ILogger<SentryTestController> _logger;
public SentryTestController(ILogger<SentryTestController> logger)
{
_logger = logger;
}
[HttpGet("test-exception")]
public IActionResult TestException()
{
try
{
throw new Exception($"Test exception from SentryTestController - {DateTime.Now}");
}
catch (Exception ex)
{
// 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
{
message = "Exception manually captured and sent to Sentry",
exceptionMessage = ex.Message,
timestamp = DateTime.Now
});
}
}
[HttpGet("throw-exception")]
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}");
}
[HttpGet("test-message")]
public IActionResult TestMessage()
{
// Send a simple message to Sentry
SentrySdk.CaptureMessage("Test message from Managing API", SentryLevel.Info);
return Ok(new
{
message = "Test message sent to Sentry",
timestamp = DateTime.Now
});
}
}
}