Commit dc5a541b authored by Alessio Parma's avatar Alessio Parma

Update HealthCheckFilter.cs

parent 2c11de1d
Pipeline #155400900 passed with stages
in 28 minutes and 21 seconds
......@@ -21,9 +21,10 @@
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using System;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.AspNetCore.Http;
namespace PommaLabs.Thumbnailer.Services.TelemetryProcessors
{
......@@ -32,25 +33,30 @@ namespace PommaLabs.Thumbnailer.Services.TelemetryProcessors
/// </summary>
public sealed class HealthCheckFilter : ITelemetryProcessor
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ITelemetryProcessor _next;
/// <summary>
/// Constructor.
/// </summary>
/// <param name="next">Next processor in the chain.</param>
public HealthCheckFilter(ITelemetryProcessor next)
/// <param name="httpContextAccessor">HTTP context accessor.</param>
public HealthCheckFilter(
ITelemetryProcessor next,
IHttpContextAccessor httpContextAccessor)
{
_next = next;
_httpContextAccessor = httpContextAccessor;
}
/// <inheritdoc/>
public void Process(ITelemetry item)
{
if (item is RequestTelemetry request && request.Url.AbsolutePath == Constants.HealthChecksEndpoint)
var requestPath = _httpContextAccessor.HttpContext?.Request?.Path;
if (!string.Equals(requestPath, Constants.HealthChecksEndpoint, StringComparison.OrdinalIgnoreCase))
{
return;
_next.Process(item);
}
_next.Process(item);
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment