From 38295f10a941c0209517cbeda1b69aff36de22eb Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Fri, 7 Aug 2026 01:47:43 -0700 Subject: [PATCH] fix(opentelemetry): gate profiler on supported platforms Add a platform check before registering the Azure Monitor profiler so the app can start on macOS. Also add a lightweight macOS GitHub Actions workflow that restores, builds, and tests the solution to catch future platform regressions. --- .github/workflows/macos-build-and-test.yml | 50 ++++++++++++++++++++++ EssentialCSharp.Web/Program.cs | 9 +++- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/macos-build-and-test.yml diff --git a/.github/workflows/macos-build-and-test.yml b/.github/workflows/macos-build-and-test.yml new file mode 100644 index 00000000..26a9140b --- /dev/null +++ b/.github/workflows/macos-build-and-test.yml @@ -0,0 +1,50 @@ +name: macOS Build and Test EssentialCSharp.Web + +on: + pull_request: + branches: ["main"] + merge_group: + workflow_dispatch: + +jobs: + build-and-test: + runs-on: macos-latest + + steps: + - uses: actions/checkout@v6 + + - name: Set up .NET Core + uses: actions/setup-dotnet@v5 + with: + global-json-file: global.json + + - name: Set up Node.js + uses: actions/setup-node@v6 + with: + node-version: "26" + cache: npm + cache-dependency-path: EssentialCSharp.Web/package-lock.json + + - name: Set up dependency caching for faster builds + uses: actions/cache@v5 + with: + path: | + ~/.nuget/packages + ${{ github.workspace }}/**/obj/project.assets.json + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + restore-keys: | + ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + ${{ runner.os }}-nuget- + + - name: Restore with dotnet + run: dotnet restore /p:AccessToNugetFeed=false + + - name: Install npm dependencies + working-directory: EssentialCSharp.Web + run: npm ci + + - name: Build with dotnet + run: dotnet build --configuration Release --no-restore /p:AccessToNugetFeed=false + + - name: Run .NET Tests + run: dotnet test --no-build --configuration Release diff --git a/EssentialCSharp.Web/Program.cs b/EssentialCSharp.Web/Program.cs index 48094a92..8bde16f6 100644 --- a/EssentialCSharp.Web/Program.cs +++ b/EssentialCSharp.Web/Program.cs @@ -51,6 +51,7 @@ private static void Main(string[] args) string? appInsightsConnectionString = builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]; bool useAzureMonitor = !string.IsNullOrWhiteSpace(appInsightsConnectionString); bool useOtlp = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]); + bool profilerSupportedPlatform = OperatingSystem.IsWindows() || OperatingSystem.IsLinux(); builder.Logging.AddOpenTelemetry(logging => { @@ -91,7 +92,13 @@ private static void Main(string[] args) }); if (useAzureMonitor) - otel.UseAzureMonitor().AddAzureMonitorProfiler(); + { + // Azure Monitor export is supported cross-platform, but the profiler currently only + // supports Windows and Linux. + var azureMonitor = otel.UseAzureMonitor(); + if (profilerSupportedPlatform) + azureMonitor.AddAzureMonitorProfiler(); + } else if (useOtlp) otel.UseOtlpExporter();