| | | 1 | | using Microsoft.EntityFrameworkCore; |
| | | 2 | | using Microsoft.Extensions.Logging; |
| | | 3 | | using OzonDomains.Models; |
| | | 4 | | using OzonRepositories.Context; |
| | | 5 | | |
| | | 6 | | namespace Services.SystemMonitoringServices; |
| | | 7 | | |
| | | 8 | | public interface ISystemMonitoringSignalWriter |
| | | 9 | | { |
| | | 10 | | Task RecordAsync(string sourceKey, string outcome, string? scopeKey = null, string? message = null, CancellationToke |
| | | 11 | | } |
| | | 12 | | |
| | | 13 | | /// <summary>Пассивная телеметрия интеграций. Сообщения намеренно ограничены и не предназначены для payload/секретов.</s |
| | 12 | 14 | | public sealed class SystemMonitoringSignalWriter( |
| | 12 | 15 | | ApplicationDbContext context, |
| | 12 | 16 | | ILogger<SystemMonitoringSignalWriter> logger) : ISystemMonitoringSignalWriter |
| | | 17 | | { |
| | | 18 | | public async Task RecordAsync(string sourceKey, string outcome, string? scopeKey = null, string? message = null, Can |
| | | 19 | | { |
| | 14 | 20 | | var signal = new SystemMonitoringSignal |
| | 14 | 21 | | { |
| | 14 | 22 | | SourceKey = sourceKey[..Math.Min(sourceKey.Length, 100)], |
| | 14 | 23 | | Outcome = outcome[..Math.Min(outcome.Length, 16)], |
| | 14 | 24 | | ScopeKey = scopeKey?[..Math.Min(scopeKey.Length, 120)], |
| | 14 | 25 | | Message = message?[..Math.Min(message.Length, 500)] |
| | 14 | 26 | | }; |
| | | 27 | | |
| | | 28 | | try |
| | | 29 | | { |
| | 14 | 30 | | context.SystemMonitoringSignals.Add(signal); |
| | 14 | 31 | | await context.SaveChangesAsync(cancellationToken); |
| | 12 | 32 | | } |
| | 2 | 33 | | catch (Exception ex) when (!cancellationToken.IsCancellationRequested) |
| | | 34 | | { |
| | 1 | 35 | | context.Entry(signal).State = EntityState.Detached; |
| | 1 | 36 | | logger.LogWarning(ex, "Не удалось записать пассивный сигнал {SourceKey}", sourceKey); |
| | 1 | 37 | | } |
| | 13 | 38 | | } |
| | | 39 | | } |