Skip to content

Add ILogger to BicepCliCompiler with ContainerRuntimeBase-style logging#12908

Merged
davidfowl merged 4 commits into
mainfrom
copilot/add-logger-to-bicep-compiler
Nov 13, 2025
Merged

Add ILogger to BicepCliCompiler with ContainerRuntimeBase-style logging#12908
davidfowl merged 4 commits into
mainfrom
copilot/add-logger-to-bicep-compiler

Conversation

Copilot AI commented Nov 11, 2025

Copy link
Copy Markdown
Contributor

Description

Adds structured logging to BicepCliCompiler following the established pattern in ContainerRuntimeBase.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:

  • Added ILogger<BicepCliCompiler> constructor dependency with null validation
  • Added debug logging: command execution and stdout/stderr via ProcessSpec callbacks (logged line-by-line as received)
  • Added error logging with exit codes on compilation failure
  • Added info logging on successful compilation
  • Changed ExecuteCommand return type from bool to int for exit code visibility

Example log output:

dbug: BicepCliCompiler[0]
      Running /usr/local/bin/bicep with arguments: build "template.bicep" --stdout
dbug: BicepCliCompiler[0]
      /usr/local/bin/bicep (stdout): { "$schema": "..." }
dbug: BicepCliCompiler[0]
      /usr/local/bin/bicep (stderr): [any error messages]
info: BicepCliCompiler[0]
      Bicep compilation for template.bicep succeeded.

On compilation failure:

erro: BicepCliCompiler[0]
      Bicep compilation for template.bicep failed with exit code 1.

Fixes #12345

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?
Original prompt

BicepCompiler should take an ILogger and CompileBicepToArmAsync should mimic the logging style of https://github.com/dotnet/aspire/blob/25b785a79a90a03da138ec0a6e62d5ba1439b2b3/src/Aspire.Hosting/Publishing/ContainerRuntimeBase.cs.


💡 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.

… logging

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ILogger to BicepCompiler and update logging style Add ILogger to BicepCliCompiler with ContainerRuntimeBase-style logging Nov 11, 2025
Copilot AI requested a review from davidfowl November 11, 2025 20:54
@davidfowl davidfowl marked this pull request as ready for review November 12, 2025 05:32
Copilot AI review requested due to automatic review settings November 12, 2025 05:32
@github-actions

github-actions Bot commented Nov 12, 2025

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12908

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12908"

@davidfowl

Copy link
Copy Markdown
Contributor

/backport to release/13.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/13.0: https://github.com/dotnet/aspire/actions/runs/19287579631

Copilot AI left a comment

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.

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();

Copilot AI Nov 12, 2025

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.

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.

@copilot apply changes based on this feedback

Log the output in debug.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread src/Aspire.Hosting.Azure/Provisioning/Internal/BicepCompiler.cs
Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Comment on lines +70 to +74
var errorText = errorOutput.ToString();
if (!string.IsNullOrWhiteSpace(errorText))
{
_logger.LogDebug("Error output: {ErrorOutput}", errorText);
}

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.

@copilot it occurs to me that we don't need this because we log the stderr already. Remove errorOutput fully.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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>
@davidfowl davidfowl merged commit 71ea2e1 into main Nov 13, 2025
584 of 591 checks passed
@davidfowl davidfowl deleted the copilot/add-logger-to-bicep-compiler branch November 13, 2025 06:17
@davidfowl

Copy link
Copy Markdown
Contributor

/backport to release/13.0

@dotnet-policy-service dotnet-policy-service Bot added this to the 13.1 milestone Nov 13, 2025
@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/13.0: https://github.com/dotnet/aspire/actions/runs/19322463663

@davidfowl

Copy link
Copy Markdown
Contributor

OK this should be debug:

[INF] Bicep compilation for
/var/folders/yx/2sfj5rw95xxb_4mg1vlnlpsh0000gn/T/aspire4zPb4z/templateapp-api-roles-postgres-kv.module.bicep succeeded.
00:56:14 (provision-postgres) i [INF] Bicep compilation for /var/folders/yx/2sfj5rw95xxb_4mg1vlnlpsh0000gn/T/aspireQwal5g/postgres.module.bicep succeeded.

@github-actions github-actions Bot locked and limited conversation to collaborators Dec 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decide if we want a UvicornAppResource deriving from PythonAppResource

5 participants