You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add Azure Monitor OpenTelemetry Profiler for container deployments (#1107)
## Summary
Adds the [Azure Monitor OpenTelemetry
Profiler](https://github.com/Azure/azuremonitor-opentelemetry-profiler-net)
(`Azure.Monitor.OpenTelemetry.Profiler`) to enable Application Insights
profiling and [Code
Optimizations](https://learn.microsoft.com/en-us/azure/azure-monitor/optimization-insights/code-optimizations-profiler-overview)
in production.
## Why this package (not
`Microsoft.ApplicationInsights.Profiler.AspNetCore`)
The app already uses `Azure.Monitor.OpenTelemetry.AspNetCore` (OTel
distro). Microsoft's docs list two profiler paths:
- **Old SDK path**: `Microsoft.ApplicationInsights.Profiler.AspNetCore`
+ `AddServiceProfiler()` — uses a native uploader binary, incompatible
with chiseled containers
- **New OTel path**: `Azure.Monitor.OpenTelemetry.Profiler` +
`AddAzureMonitorProfiler()` ← **this PR** — uses EventPipe (pure
in-process), compatible with chiseled images
## Changes
- **`Directory.Packages.props`**: Add
`Azure.Monitor.OpenTelemetry.Profiler 1.0.0-beta9` to Central Package
Management (prerelease-only; TODO comment added to update at GA)
- **`EssentialCSharp.Web.csproj`**: Reference the new package
- **`Program.cs`**: Chain `.AddAzureMonitorProfiler()` onto
`UseAzureMonitor()` — profiler only activates when
`APPLICATIONINSIGHTS_CONNECTION_STRING` is set (production only, never
local/OTLP)
- **`appsettings.Development.json`**: Add `Debug` log level for profiler
namespaces for local diagnostics
## Testing
| Test | Result |
|---|---|
| `dotnet run` with fake connection string | ✅ Profiler agent loads,
initializes, CPU sampling begins — fails only on invalid key (expected)
|
| Docker (`noble-chiseled-extra`) with fake key | ✅ Identical behavior —
no native dependency errors, no shell-not-found failures |
## What this enables in production
Once `APPLICATIONINSIGHTS_CONNECTION_STRING` is set in the ACA
deployment config:
- **Sampling trigger**: Profiles ~2 min/hour automatically
- **CPU trigger**: Profiles when CPU >80%
- **Memory trigger**: Profiles when memory >80%
- **Code Optimizations**: AI-based perf insights in Azure portal (works
because we use default storage, not BYOS)
## Notes
- No BYOS (Bring Your Own Storage) — intentional; BYOS would disable
Code Optimizations
- No manual request tracking needed — ASP.NET Core auto-tracks requests
- Trigger thresholds can be tuned in Azure portal → App Insights →
Performance → Profiler → Triggers
---------
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
0 commit comments