Skip to content

Log exceptions evaluating IValueProvider whilst starting a resource#7032

Merged
davidfowl merged 2 commits intomicrosoft:mainfrom
afscrome:ivalueprovidererrorlogging
Jan 14, 2025
Merged

Log exceptions evaluating IValueProvider whilst starting a resource#7032
davidfowl merged 2 commits intomicrosoft:mainfrom
afscrome:ivalueprovidererrorlogging

Conversation

@afscrome
Copy link
Copy Markdown
Collaborator

@afscrome afscrome commented Jan 6, 2025

Description

When an exception happens evaluating IValueProvider when starting a resource, log the exception to the console output to provide more clues as to why the resource failed to start.

Makes errors more obvious for #7030 & #6330.

Before:
image

After:
image

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?
Microsoft Reviewers: Open in CodeFlow

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jan 6, 2025
@danmoseley
Copy link
Copy Markdown
Member

Thanks! Diagnosability is always good. I'll let code owner sign off.

catch (Exception ex)
{
resourceLogger.LogCritical("Failed to apply arguments. A dependency may have failed to start.");
_logger.LogDebug(ex, "Failed to apply arguments. A dependency may have failed to start.");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we no longer logging to _logger?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read this as a basic level of detail being logged as Critical, with the full detail only being logged at Debug. Now the critical level contains the full detail, the debug entry seemed redundant.

The other place in this file that does a resourceLogger.LogCritical(ex, ...) follows this same pattern - only logging the exception to the resourceLogger, and not _logger.

https://github.com/dotnet/aspire/blob/eca04807c4ca03bf44cfec6e13cbafdb092ab92e/src/Aspire.Hosting/Dcp/ApplicationExecutor.cs#L378

I can put the debug logs back if you wat

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resourceLogger and _logger are separate logs / instances. The first is the logs for the resource that shows up in the dashboard. The 2nd is the log for the AppHost itself (since the AppHost uses the ASP.NET/Microsoft.Extensions.Hosting app model).

It isn't redundant because it goes to 2 separate locations.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@afscrome Can you add the logs you removed back?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added debug logs back, although I did add {ResourceName} into the _logger log entries so you know which resource failed. (I didn't include this on resourceLogger entries since the resource is implied by the resourceLogger instance).

- Added missing logging for failures  in container runtime args
- Be more consistent with error message - always including `{ConfigKey}`
- Restore previously removed debug logging, with the addition of `{ResourceName}` to make clear which resource is the problem child.
Copy link
Copy Markdown
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the contribution!

@davidfowl davidfowl merged commit 66465d1 into microsoft:main Jan 14, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 13, 2025
@github-actions github-actions Bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Mar 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants