Reporting API in ASP.NET Core - Network Error Logging

14 kwi 2020 | Blog | asp.net core | http | network error logging | reporting api | IT

Some time ago I've written a post about general aspects of Reporting API and how to use it in the context of ASP.NET Core. In this post, I want to focus on one specific aspect - reporting network errors.

Network Error Logging provides a mechanism that allows your application to declare a reporting policy that can be used by the browser to report network errors. In order to achieve that, you first need to configure a group of Reporting API endpoints and then point to it with the policy. I've described configuring reporting endpoints in the previous post, so I'll go ahead to declaring a policy.

Declaring a Policy

Network Error Logging policy tells the browser how to use previously defined Reporting API endpoint group to report network errors. The policy is delivered by a dedicated response header called NEL. This header follows a currently popular pattern, where header value is a JSON object. That object must have two members: report_to and max_age. The report_to member specifies previously defined Reporting API endpoints group to be used, while max_age defines the lifetime of the policy. This is enough to make the browser report all network errors to defined endpoints. The full policy can be represented by the following class.

public class NetworkErrorLoggingHeaderValue
{
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions { IgnoreNullValues = true };

private decimal? _successFration;
private decimal? _failureFration;

[JsonPropertyName("report_to")]
public string ReportTo { get; }

[JsonPropertyName("max_age")]

POSTY TEGO AUTORA

Monitoring C# Azure Functions in the Isolated Worker Model - Infrastructure & Configuration Deep Dive26 lis 2024

Blog | programowanie | .net | c# | azure functions | IT

ASP.NET Core 9 and IAsyncEnumerable - Async Streaming JSON and NDJSON From Blazor WebAssembly24 wrz 2024

Blog | programowanie | .net | c# | asp.net core | blazor | IT

Azure Functions Extensibility - Extensions and Isolated Worker Model5 mar 2024

Blog | programowanie | .net | c# | azure functions | azure | IT

Azure Functions Extensibility - Runtime Scaling22 lut 2024

Blog | programowanie | .net | c# | azure | IT

Yet Another Developer Blog

noreply@blogger.com (Tomasz Pęczek)