BFF Diagnostics Endpoint Extensibility
The BFF diagnostics endpoint can be customized by implementing the IDiagnosticsEndpoint.
Request Processing
Section titled “Request Processing”You can customize the behavior of the diagnostics endpoint by implementing the ProcessRequestAsync method of the
IDiagnosticsEndpoint interface. The default implementation
can serve as a starting point for your own implementation.
If you want to extend the default behavior of the diagnostics endpoint, you can instead add a custom endpoint and call the original endpoint implementation:
var bffOptions = app.Services.GetRequiredService<IOptions<BffOptions>>().Value;
app.MapGet(bffOptions.DiagnosticsPath, async (HttpContext context, CancellationToken ct) =>{ // Custom logic before calling the original endpoint implementation var endpointProcessor = context.RequestServices.GetRequiredService<IDiagnosticsEndpoint>(); await endpointProcessor.ProcessRequestAsync(context, ct); // Custom logic after calling the original endpoint implementation});ProcessRequestAsync is the top-level function called in the endpoint service DefaultDiagnosticsService,
and can be used to add arbitrary logic to the endpoint.
For example, you could take whatever actions you need before normal processing of the request like this:
public override Task ProcessRequestAsync(HttpContext context, CancellationToken ct){ // Custom logic here
return base.ProcessRequestAsync(context);}