Add ILogger to BicepCliCompiler with ContainerRuntimeBase-style logging#12908
Conversation
… logging Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12908Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12908" |
|
/backport to release/13.0 |
|
Started backporting to release/13.0: https://github.com/dotnet/aspire/actions/runs/19287579631 |
There was a problem hiding this comment.
Pull Request Overview
This PR adds structured logging to BicepCliCompiler following the established logging pattern from ContainerRuntimeBase.cs. The changes provide observability for Bicep compilation operations through debug, info, and error logs, with the main implementation change being the addition of an ILogger<BicepCliCompiler> dependency and logging at key points during compilation.
Key changes:
- Added ILogger dependency injection with null validation
- Enhanced observability with debug/info/error logging throughout compilation lifecycle
- Changed ExecuteCommand return type from bool to int to expose exit codes for better error reporting
| } | ||
|
|
||
| var armTemplateContents = new StringBuilder(); | ||
| var errorOutput = new StringBuilder(); |
There was a problem hiding this comment.
The errorOutput StringBuilder is declared and populated but never used. While capturing stderr is good practice for potential future diagnostics, consider either logging the accumulated error output when compilation fails (to provide more context in the error log) or removing it if not needed.
There was a problem hiding this comment.
@copilot apply changes based on this feedback
Log the output in debug.
There was a problem hiding this comment.
Applied. The accumulated error output is now logged at debug level when compilation fails (commit 197f5f7). This provides additional diagnostic context while keeping the main error log focused on the exit code and file path.
Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
| var errorText = errorOutput.ToString(); | ||
| if (!string.IsNullOrWhiteSpace(errorText)) | ||
| { | ||
| _logger.LogDebug("Error output: {ErrorOutput}", errorText); | ||
| } |
There was a problem hiding this comment.
@copilot it occurs to me that we don't need this because we log the stderr already. Remove errorOutput fully.
There was a problem hiding this comment.
Removed in commit 1349f0c. The errorOutput StringBuilder was redundant since stderr is already being logged line-by-line in the OnErrorData callback.
…gged Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
|
/backport to release/13.0 |
|
Started backporting to release/13.0: https://github.com/dotnet/aspire/actions/runs/19322463663 |
|
OK this should be debug: |
Description
Adds structured logging to
BicepCliCompilerfollowing the established pattern inContainerRuntimeBase.cs. Provides observability for Bicep compilation operations with debug logs for command execution and stdout/stderr, error logs with exit codes, and info logs for successful compilations.Changes:
ILogger<BicepCliCompiler>constructor dependency with null validationExecuteCommandreturn type frombooltointfor exit code visibilityExample log output:
On compilation failure:
Fixes #12345
Checklist
<remarks />and<code />elements on your triple slash comments?doc-ideatemplatebreaking-changetemplatediagnostictemplateOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.