Skip to content

Diagnostics

Duende Backend for Frontend (BFF) offers several diagnostics possibilities. It uses the standard logging facilities provided by ASP.NET Core, so you don’t need to do any extra configuration to benefit from rich logging functionality, including support for multiple logging providers. See the Microsoft documentation for a good introduction on logging.

BFF follows the standard logging levels defined by the .NET logging framework, and uses the Microsoft guidelines for when certain log levels are used.

For general information on how to configure logging in Duende products, see our Logging Fundamentals guide.

Logs are typically written under the Duende.Bff category, with more concrete categories for specific components.

To get detailed logs from the BFF middleware with the Microsoft.Extensions.Logging framework, you can configure your appsettings.json to enable Debug level logs for the Duende.Bff namespace:

appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Duende.Bff": "Debug"
}
}
}

OpenTelemetry provides a single standard for collecting and exporting telemetry data, such as metrics, logs, and traces.

To start emitting OpenTelemetry data in Duende Backend for Frontend (BFF), you need to:

  • add the OpenTelemetry libraries to your BFF host and client applications
  • start collecting traces and metrics from the various BFF sources (and other sources such as ASP.NET Core, the HttpClient, etc.)

The following configuration adds the OpenTelemetry configuration to your service setup, and exports data to an OTLP exporter:

Program.cs
var openTelemetry = builder.Services.AddOpenTelemetry();
openTelemetry.ConfigureResource(r => r
.AddService(builder.Environment.ApplicationName));
openTelemetry.WithMetrics(metrics =>
{
metrics.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation()
.AddMeter(BffMetrics.MeterName);
});
openTelemetry.WithTracing(tracing =>
{
tracing.AddSource(builder.Environment.ApplicationName)
.AddAspNetCoreInstrumentation()
// Uncomment the following line to enable gRPC instrumentation
// (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
//.AddGrpcClientInstrumentation()
.AddHttpClientInstrumentation();
});
openTelemetry.UseOtlpExporter();

OpenTelemetry metrics are run-time measurements typically used to show graphs on a dashboard, to inspect overall application health, or to set up monitoring rules.

The BFF host emits metrics collected through the Duende.Bff meter (meter name: BffMetrics.MeterName). Add it to your OpenTelemetry configuration with .AddMeter(BffMetrics.MeterName).

Metric NameTypeDescription
session.startedCounterNumber of new sessions started (user logins)
session.endedCounterNumber of sessions ended (logouts, expiry, back-channel logout)

These counters can be used to track login/logout rates and detect unusual session activity (e.g., a spike in session.ended could indicate a back-channel logout sweep).

If you are exporting metrics to Prometheus, the following PromQL queries can be useful:

# Login rate over 5 minutes
rate(session_started_total[5m])
# Logout rate over 5 minutes
rate(session_ended_total[5m])
# Ratio of logouts to logins (high ratio may indicate session problems)
rate(session_ended_total[5m]) / rate(session_started_total[5m])

BFF participates in distributed tracing via ASP.NET Core’s standard ActivitySource integration. When you configure AddAspNetCoreInstrumentation() and AddHttpClientInstrumentation() in your OpenTelemetry setup, the following BFF operations will appear as spans in your traces:

  • Incoming requests to BFF management endpoints (/bff/login, /bff/logout, /bff/user, etc.)
  • Outgoing HTTP requests made by the BFF when proxying to remote APIs
  • Token refresh calls to the identity provider (via Duende.AccessTokenManagement)
Program.cs
var openTelemetry = builder.Services.AddOpenTelemetry();
openTelemetry.ConfigureResource(r => r
.AddService(builder.Environment.ApplicationName));
openTelemetry.WithMetrics(metrics =>
{
metrics
.AddAspNetCoreInstrumentation() // HTTP request metrics
.AddHttpClientInstrumentation() // Outgoing HTTP call metrics
.AddRuntimeInstrumentation() // .NET runtime metrics (GC, threadpool, etc.)
.AddMeter(BffMetrics.MeterName); // BFF-specific session metrics
});
openTelemetry.WithTracing(tracing =>
{
tracing
.AddSource(builder.Environment.ApplicationName)
.AddAspNetCoreInstrumentation() // Trace incoming requests
.AddHttpClientInstrumentation(); // Trace outgoing HTTP calls (token refresh, proxied API calls)
});
// Export to an OTLP-compatible backend (Jaeger, Zipkin, Grafana Tempo, etc.)
openTelemetry.UseOtlpExporter();

When using multiple frontends, log messages and traces include a frontend scope property identifying which frontend the activity belongs to. This allows you to filter traces by frontend in your observability backend.

The BFF also includes a /bff/diagnostics endpoint for development-time troubleshooting. It returns the current user and client access tokens. See Diagnostics Endpoint for details.