< Summary - Syki

Information
Class: Syki.Back.Middlewares.MetricsMiddleware
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Middlewares/MetricsMiddleware.cs
Tag: 4_16869239191
Line coverage
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 39
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Invoke()100%11100%

File(s)

/home/runner/work/syki/syki/Back/Middlewares/MetricsMiddleware.cs

#LineLine coverage
 1using Syki.Back.Metrics;
 2using System.Collections.Concurrent;
 3
 4namespace Syki.Back.Middlewares;
 5
 26public class MetricsMiddleware(RequestDelegate next)
 7{
 8    public async Task Invoke(HttpContext context)
 9    {
 788610        context.Response.OnStarting(() =>
 788611        {
 788612            var method = context.Request.Method;
 788613            var endpoint = context.Request.Path.ToString();
 788614            var status = context.Response.StatusCode.ToString();
 788615
 788616            SykiMetricsStore.Requests.AddOrUpdate(
 788617                $"{method} {endpoint}",
 788618                _ =>
 788619                {
 58620                    var dict = new ConcurrentDictionary<string, int>();
 58621                    dict.TryAdd("Total", 1);
 58622                    dict.TryAdd(method, 1);
 58623                    dict.TryAdd(status, 1);
 58624                    return dict;
 788625                },
 788626                (key, currentValue) =>
 788627                {
 1465828                    currentValue.AddOrUpdate("Total", 1, (_, oldValue) => oldValue + 1);
 1465229                    currentValue.AddOrUpdate(method, 1, (_, oldValue) => oldValue + 1);
 1458230                    currentValue.AddOrUpdate(status, 1, (_, oldValue) => oldValue + 1);
 732631                    return currentValue;
 788632                });
 788633
 788634            return Task.CompletedTask;
 788635        });
 36
 788637        await next(context);
 788638    }
 39}