Add verbose Enova diagnostics and reliable Sentry reporting

This commit is contained in:
2026-08-31 21:13:46 +00:00
parent ee62a6253d
commit af6466e2dc
20 changed files with 276 additions and 37 deletions

View File

@@ -1,6 +1,6 @@
using Newtonsoft.Json;
using Sentry;
using SmartB2B.Enova.Contracts;
using SmartB2B.Enova.Service.Diagnostics;
using SmartB2B.Enova.Service.Rpc;
namespace SmartB2B.Enova.Service.Orders;
@@ -60,6 +60,10 @@ public sealed class PlaceOrderHandler
new Dictionary<string, object?> { ["errors"] = errors });
}
ConsoleLogger.Verbose(
$"ZO: żądanie zweryfikowane; definicja={request.DocumentDefinition}, " +
$"magazyn={request.WarehouseCode ?? "(standardowy)"}, tryb={request.SaveMode}.");
ConsoleLogger.Verbose("ZO: oczekiwanie na wyłączną sekcję operacji Enovy.");
await _orderLock.WaitAsync(cancellationToken).ConfigureAwait(false);
try
{
@@ -69,20 +73,28 @@ public sealed class PlaceOrderHandler
OrderResult result;
try
{
ConsoleLogger.Verbose("ZO: przekazanie żądania do adaptera Enovy.");
result = await Task.Run(() => _adapter.CreateOrder(request), cancellationToken)
.ConfigureAwait(false);
}
catch (EnovaOperationException exception)
{
SentrySdk.CaptureException(exception, scope =>
{
scope.SetTag("rpc.procedure", "eu.smartb2b.place_order");
scope.SetTag("wamp.error_uri", exception.ErrorUri);
});
ConsoleLogger.Error(
$"Błąd tworzenia ZO [{exception.ErrorUri}]: {exception.Message}",
exception);
await SentryReporter.CaptureAsync(exception, scope =>
{
scope.SetTag("rpc.procedure", "eu.smartb2b.place_order");
scope.SetTag("wamp.error_uri", exception.ErrorUri);
})
.ConfigureAwait(false);
throw WampErrorFactory.FromEnova(exception);
}
Console.WriteLine($"Utworzono ZO {result.Number} (ID: {result.Id}).");
ConsoleLogger.Verbose(
$"ZO: zapis zakończony; stan={result.SaveMode}, magazyn={result.WarehouseCode}, " +
$"netto={result.Net}, VAT={result.Vat}, brutto={result.Gross}.");
return new KeywordResult(new Dictionary<string, object?>
{
["order_erp_id"] = result.Id,
@@ -95,6 +107,7 @@ public sealed class PlaceOrderHandler
finally
{
_orderLock.Release();
ConsoleLogger.Verbose("ZO: zwolniono wyłączną sekcję operacji Enovy.");
}
}
}