/
aprogrammer
/
reverse-proxy-ms-yarp
Обзор
Документация
Войти
/
aprogrammer
/
reverse-proxy-ms-yarp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
testassets/ReverseProxy.Code/ForwarderTelemetryConsumer.cs
35 строк
1 KB
Kahbazi
Convert to file-scoped namespace (#1382)
15 ноя 2021, 21:15
Не верифицирован
15 ноя 2021, 21:15
efd2a4c
Код
Авторство
О чём код?
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; using System.Threading; using Microsoft.AspNetCore.Http; using Yarp.Telemetry.Consumption; namespace Yarp.ReverseProxy.Sample; public sealed class ForwarderTelemetryConsumer : IForwarderTelemetryConsumer { private readonly IHttpContextAccessor _httpContextAccessor; private readonly AsyncLocal<DateTime?> _startTime = new(); public ForwarderTelemetryConsumer(IHttpContextAccessor httpContextAccessor) { _httpContextAccessor = httpContextAccessor; } public void OnForwarderStart(DateTime timestamp, string destinationPrefix) { _startTime.Value = timestamp; } public void OnForwarderStop(DateTime timestamp, int statusCode) { if (_startTime.Value is DateTime startTime) { var elapsed = timestamp - startTime; var path = _httpContextAccessor.HttpContext.Request.Path; Console.WriteLine($"Spent {elapsed.TotalMilliseconds:N2} ms proxying {path}"); } } }