< Summary

Information
Class: Elsa.AI.Host.Services.AIAuditSink
Assembly: Elsa.AI.Host
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.AI.Host/Services/AIAuditSink.cs
Line coverage
93%
Covered lines: 14
Uncovered lines: 1
Coverable lines: 15
Total lines: 35
Line coverage: 93.3%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
RecordAsync()100%11100%
RecordManyAsync()75%4491.66%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.AI.Host/Services/AIAuditSink.cs

#LineLine coverage
 1using Elsa.AI.Abstractions.Contracts;
 2using Elsa.AI.Abstractions.Models;
 3using Microsoft.Extensions.Logging;
 4using Microsoft.Extensions.DependencyInjection;
 5
 6namespace Elsa.AI.Host.Services;
 7
 408public class AIAuditSink(IServiceScopeFactory scopeFactory, ILogger<AIAuditSink> logger) : IAIAuditSink
 9{
 10    public async ValueTask RecordAsync(AIAuditEvent auditEvent, CancellationToken cancellationToken = default)
 11    {
 7312        await RecordManyAsync([auditEvent], cancellationToken);
 7213    }
 14
 15    public async ValueTask RecordManyAsync(IReadOnlyCollection<AIAuditEvent> auditEvents, CancellationToken cancellation
 16    {
 9717        if (auditEvents.Count == 0)
 018            return;
 19
 9720        using var scope = scopeFactory.CreateScope();
 9721        var handlers = scope.ServiceProvider.GetServices<IAIAuditEventHandler>();
 22
 20123        foreach (var handler in handlers)
 24        {
 25            try
 26            {
 427                await handler.RecordManyAsync(auditEvents, cancellationToken);
 228            }
 229            catch (Exception e) when (e is not OperationCanceledException)
 30            {
 131                logger.LogWarning(e, "AI audit handler {HandlerType} failed while recording {AuditEventCount} event(s)."
 132            }
 333        }
 9634    }
 35}