microsoft / microsoft/aspire

Improve logging of `ResourceReadyEvent` failures

Open
#7,590 2 comments 0 reactions 0 assignees View on GitHub
area-app-model area-dashboard
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

Take the following app host with a `ResourceReadyEvent` subscription that throws an error
```cs
var builder = DistributedApplication.CreateBuilder(args);

var apiService = builder.AddProject("apiservice");

var web = builder.AddProject("webfrontend")
.WithExternalHttpEndpoints()
.WithReference(apiService)
.WaitFor(apiService);

web.WithHttpHealthCheck();

builder.Eventing.Subscribe(apiService.Resource, async (evt, ct) => {
throw new Exception("FAILURE");
});

builder.Build().Run();
```
I'd expect to see something about the failure of the `ResourceReadyEvent` in the resource logs, but there isn't
![Image](https://github.com/user-attachments/assets/0b844de7-572b-4e83-a163-021cfa44bb16)

An exception does get reported against any dependencies waiting on the original resource, although if multiple failures happen, only one of the errors will ever get reported.
![Image](https://github.com/user-attachments/assets/e78b53e8-d290-4ff3-9bcb-9b059bd96d0e)

In the below scenario, the Web resource will report either `failure 1` or `failure 2`, but never both.
```cs
var builder = DistributedApplication.CreateBuilder(args);

var apiService1 = builder.AddProject("apiservice");
var apiService2 = builder.AddProject("apiservice2");

var web = builder.AddProject("webfrontend")
.WithExternalHttpEndpoints()
.WithReference(apiService1)
.WaitFor(apiService1)
.WaitFor(apiService2);

web.WithHttpHealthCheck();

builder.Eventing.Subscribe(apiService1.Resource, async (evt, ct) => {
throw new Exception("failure 1");
});
builder.Eventing.Subscribe(apiService2.Resource, async (evt, ct) => {
throw new Exception("failure 2");
});

builder.Build().Run();
```

### Describe the solution you'd like

I'd expect to see the exception from `ResourceReadyEvent` logged to `ResourceLoggerService.GetLogger(resorurce)`

### Additional context

Versions:
```xml


```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.