|
| 1 | +--- |
| 2 | +title: "Diagnostics" |
| 3 | +description: Overview of Duende Backend for Frontend (BFF) diagnostic capabilities including logging and OpenTelemetry integration to assist with monitoring and troubleshooting |
| 4 | +date: 2025-11-27T08:20:20+02:00 |
| 5 | +sidebar: |
| 6 | + label: Overview |
| 7 | + order: 1 |
| 8 | +--- |
| 9 | + |
| 10 | +## Logging |
| 11 | + |
| 12 | +Duende Backend for Frontend (BFF) offers several diagnostics possibilities. It uses the standard logging facilities |
| 13 | +provided by ASP.NET Core, so you don't need to do any extra configuration to benefit from rich logging functionality, |
| 14 | +including support for multiple logging providers. See the Microsoft [documentation](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging) for a good introduction on logging. |
| 15 | + |
| 16 | +BFF follows the standard logging levels defined by the .NET logging framework, and uses the Microsoft guidelines for |
| 17 | +when certain log levels are used, similar to [how Duende IdentityServer uses log levels](/identityserver/diagnostics/logging.md). |
| 18 | + |
| 19 | +Logs are typically written under the `Duende.Bff` category, with more concrete categories for specific components. |
| 20 | + |
| 21 | +:::note[Multiple frontends] |
| 22 | +When using [multiple frontends and the `FrontendSelectionMiddleware`](/bff/architecture/multi-frontend.md), |
| 23 | +log messages are written in a log scope that contains a `frontend` property with the name of the frontend for which the |
| 24 | +log message was emitted. |
| 25 | +::: |
| 26 | + |
| 27 | +## OpenTelemetry :badge[v4.0] |
| 28 | + |
| 29 | +OpenTelemetry provides a single standard for collecting and exporting telemetry data, such as metrics, logs, and traces. |
| 30 | + |
| 31 | +To start emitting OpenTelemetry data in Duende Backend for Frontend (BFF), you need to: |
| 32 | + |
| 33 | +* add the OpenTelemetry libraries to your BFF host and client applications |
| 34 | +* start collecting traces and metrics from the various BFF sources (and other sources such as ASP.NET Core, the `HttpClient`, etc.) |
| 35 | + |
| 36 | +The following configuration adds the OpenTelemetry configuration to your service setup, and exports data to an [OTLP exporter](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/observability-with-otel): |
| 37 | + |
| 38 | +```cs |
| 39 | +// Program.cs |
| 40 | +var openTelemetry = builder.Services.AddOpenTelemetry(); |
| 41 | + |
| 42 | +openTelemetry.ConfigureResource(r => r |
| 43 | + .AddService(builder.Environment.ApplicationName)); |
| 44 | + |
| 45 | +openTelemetry.WithMetrics(metrics => |
| 46 | + { |
| 47 | + metrics.AddAspNetCoreInstrumentation() |
| 48 | + .AddHttpClientInstrumentation() |
| 49 | + .AddRuntimeInstrumentation() |
| 50 | + .AddMeter(BffMetrics.MeterName); |
| 51 | + }); |
| 52 | + |
| 53 | +openTelemetry.WithTracing(tracing => |
| 54 | + { |
| 55 | + tracing.AddSource(builder.Environment.ApplicationName) |
| 56 | + .AddAspNetCoreInstrumentation() |
| 57 | + // Uncomment the following line to enable gRPC instrumentation |
| 58 | + // (requires the OpenTelemetry.Instrumentation.GrpcNetClient package) |
| 59 | + //.AddGrpcClientInstrumentation() |
| 60 | + .AddHttpClientInstrumentation(); |
| 61 | + }); |
| 62 | + |
| 63 | +openTelemetry.UseOtlpExporter(); |
| 64 | +``` |
| 65 | + |
| 66 | +## Metrics |
| 67 | + |
| 68 | +OpenTelemetry metrics are run-time measurements are typically used to show graphs on a dashboard, to inspect overall |
| 69 | +application health, or to set up monitoring rules. |
| 70 | + |
| 71 | +The BFF host emits metrics from several sources, and collects these through the `Duende.Bff` meter: |
| 72 | + |
| 73 | +* `session.started` - a counter that communicates the number of sessions started |
| 74 | +* `session.ended` - a counter that communicates the number of sessions ended |
0 commit comments