Skip to content

Add Azure Monitor OpenTelemetry Profiler for container deployments#1107

Merged
BenjaminMichaelis merged 2 commits into
mainfrom
agents/app-insights-profiler-check
May 15, 2026
Merged

Add Azure Monitor OpenTelemetry Profiler for container deployments#1107
BenjaminMichaelis merged 2 commits into
mainfrom
agents/app-insights-profiler-check

Conversation

@BenjaminMichaelis
Copy link
Copy Markdown
Member

Summary

Adds the Azure Monitor OpenTelemetry Profiler (Azure.Monitor.OpenTelemetry.Profiler) to enable Application Insights profiling and Code Optimizations 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

- Add Azure.Monitor.OpenTelemetry.Profiler 1.0.0-beta9 to CPM and web project
- Wire up AddAzureMonitorProfiler() chained on UseAzureMonitor() in Program.cs
- Profiler only activates when APPLICATIONINSIGHTS_CONNECTION_STRING is set
- Add profiler debug logging to appsettings.Development.json for local diagnostics
- Uses EventPipe (in-process) — compatible with chiseled container base image
- Enables Code Optimizations (AI-based perf insights) in Azure portal

Tested locally: profiler agent loads and initializes correctly on both
dotnet run and Docker (noble-chiseled-extra base image).
Copilot AI review requested due to automatic review settings May 15, 2026 04:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Azure Monitor OpenTelemetry Profiler support to the web app’s existing Azure Monitor OpenTelemetry path so production container deployments can collect profiling data for Application Insights Code Optimizations.

Changes:

  • Adds Azure.Monitor.OpenTelemetry.Profiler to central package management and the web project.
  • Chains AddAzureMonitorProfiler() onto the existing UseAzureMonitor() registration.
  • Enables development debug logging for profiler-related categories.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
Directory.Packages.props Adds the profiler package version under central package management.
EssentialCSharp.Web/EssentialCSharp.Web.csproj References the profiler package from the web project.
EssentialCSharp.Web/Program.cs Registers the profiler only on the Azure Monitor telemetry path.
EssentialCSharp.Web/appsettings.Development.json Adds profiler debug log levels for development diagnostics.

Comment thread EssentialCSharp.Web/Program.cs Fixed
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@BenjaminMichaelis BenjaminMichaelis merged commit d349822 into main May 15, 2026
8 checks passed
@BenjaminMichaelis BenjaminMichaelis deleted the agents/app-insights-profiler-check branch May 15, 2026 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants