feat: integrate Azure Monitor OTel Profiler + Code Optimizations#288
Merged
BenjaminMichaelis merged 4 commits intoMay 15, 2026
Merged
Conversation
- NuGet.config: add nuget.org source + Azure.Monitor.* / OpenTelemetry.* package source mapping - Directory.Packages.props: pin Azure.Monitor.OpenTelemetry.AspNetCore 1.5.0 and Azure.Monitor.OpenTelemetry.Profiler 1.0.1-beta.1 - Microsoft.TryDotNet.csproj: add PackageReference for both OTel packages - Program.cs: wire AddOpenTelemetry().UseAzureMonitor().AddAzureMonitorProfiler(); add startup warning for missing connection string - appsettings.json: suppress OTel log noise (Default=Warning), keep Microsoft.ServiceProfiler=Information for initial validation
Add 'Azure.Monitor.OpenTelemetry.Profiler' category to OpenTelemetry log provider section. The OTel profiler emits startup/session logs under 'Azure.Monitor.OpenTelemetry.Profiler.*' (not 'Microsoft.ServiceProfiler' which is the classic AI SDK category). Without this, profiler startup confirmation logs were suppressed in Azure Monitor (still visible in container stdout via the global Default:Information, but not exported). Keep 'Microsoft.ServiceProfiler' as the README troubleshooting guide recommends it for internal diagnostics from the underlying profiler agent.
There was a problem hiding this comment.
Pull request overview
This PR integrates Azure Monitor’s modern OpenTelemetry distro (including the Azure Monitor Profiler) into Microsoft.TryDotNet so CPU-heavy Roslyn compilation workloads (notably POST /commands) can be analyzed via Application Insights Profiler / Code Optimizations.
Changes:
- Adds Azure Monitor OpenTelemetry distro + Profiler packages via Central Package Management.
- Wires up
AddOpenTelemetry().UseAzureMonitor().AddAzureMonitorProfiler()inProgram.csand emits a startup warning when no AI connection string is present. - Updates NuGet restore configuration to include
nuget.organd source mapping for Azure Monitor / OpenTelemetry packages; updates logging configuration inappsettings.json.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/Microsoft.TryDotNet/Program.cs |
Registers Azure Monitor OpenTelemetry + Profiler and adds a missing-connection-string startup warning. |
src/Microsoft.TryDotNet/Microsoft.TryDotNet.csproj |
Adds package references for Azure Monitor OpenTelemetry distro + Profiler (versions resolved via CPM). |
src/Microsoft.TryDotNet/appsettings.json |
Adds logging configuration intended to surface profiler-related categories. |
NuGet.config |
Adds nuget.org feed and maps Azure Monitor / OpenTelemetry package IDs to it. |
Directory.Packages.props |
Pins Azure.Monitor.OpenTelemetry.AspNetCore and prerelease Azure.Monitor.OpenTelemetry.Profiler. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
UseAzureMonitor() throws InvalidOperationException when APPLICATIONINSIGHTS_CONNECTION_STRING is not set, which breaks CI test runs and local dev environments without Azure Monitor configured. Wrap the OTel registration in a null/empty check so it's a no-op when the connection string is absent. The startup warning in Main() already informs operators when telemetry is inactive.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/Microsoft.TryDotNet/Program.cs:81
- This repeats the
APPLICATIONINSIGHTS_CONNECTION_STRINGlookup already done inMain. Consider caching the value (or passing it intoCreateWebApplicationAsync) to avoid duplicate env reads and to keep the conditional/warning consistent.
if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING")))
{
builder.Services.AddOpenTelemetry()
.UseAzureMonitor()
.AddAzureMonitorProfiler();
}
Avoids silent drift if the warning check and OTel guard ever used different strings. Both callers now use AppInsightsConnectionStringEnvVar.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Integrates Azure Monitor Application Insights Profiler (via the modern OpenTelemetry path) into
Microsoft.TryDotNetto enable Code Optimizations insights on the CPU-heavy Roslyn compilation workloads inPOST /commands.What changed
NuGet.confignuget.orgsource +Azure.Monitor.*/OpenTelemetry.*package source mapping (was blocked by<clear/>)Directory.Packages.propsAzure.Monitor.OpenTelemetry.AspNetCore1.5.0 +Azure.Monitor.OpenTelemetry.Profiler1.0.1-beta.1src/Microsoft.TryDotNet/Microsoft.TryDotNet.csproj<PackageReference>entries (no version — resolved by CPM)src/Microsoft.TryDotNet/Program.csAddOpenTelemetry().UseAzureMonitor().AddAzureMonitorProfiler(); startup warning when connection string missingsrc/Microsoft.TryDotNet/appsettings.jsonSDK path chosen
Azure Monitor OpenTelemetry Distro (
Azure.Monitor.OpenTelemetry.AspNetCore+Azure.Monitor.OpenTelemetry.Profiler) — the canonical modern path. ClassicMicrosoft.ApplicationInsights.Profiler.AspNetCorewas rejected (legacy, not on repo feeds).Key decisions
CSharpProjectKernelneeds fulldotnettoolchainAPPLICATIONINSIGHTS_CONNECTION_STRINGat deploy time; never baked inPost-deploy steps required
APPLICATIONINSIGHTS_CONNECTION_STRINGas container env varStarting application insights profiler with connection string: ...Reviewed by
Three agents (Sonnet, Opus 4.6, GPT-5.5) reviewed against all 5 Microsoft Learn docs. All findings addressed. Unanimous approval after fix to profiler logger category in
appsettings.json.