Production profiling for .NET 10: dotnet-monitor as a sidecar with collection rules and egress, the Application Insights Profiler (classic SDK and the OpenTelemetry preview), overhead and blast radius, authentication, and Privacy Act obligations for diagnostic artefacts.
Safe production profiling means cheap signals always on and heavy captures rare, short and controlled.
I limit blast radius to one instance, and treat dumps as production data under the Privacy Act. The trade-off is evidence versus risk: a full dump answers anything but pauses the process and copies every secret in memory.
"I split production diagnostics into three tiers. The first is always on and cheap: runtime metrics like CPU, GC heap, ThreadPool queue length and request duration, plus distributed traces, all exported with OpenTelemetry to Azure Monitor. That tells me which endpoint, which instance and which kind of problem before I touch anything. The second tier is short, targeted captures: a 30-second CPU trace or a gcdump. The third is a full memory dump, which I only take for hangs, crashes or native memory, because it pauses the process and contains everything in memory, including tokens, connection strings and customer data.
In containers I make the second tier boring by running dotnet-monitor as a sidecar. It shares the app's diagnostics socket, listens on an internal port with an API key or Entra ID authentication, and writes artefacts to a Blob Storage account in Australia East using a managed identity that can only write. Collection rules mean I don't have to be awake: 'if CPU is above 80% for two minutes, take a 30-second trace, at most once an hour'. For example, at [company] [a rule caught a 3 am CPU spike caused by a regex timeout storm, and the trace was waiting for us in the morning]. On App Service, the Application Insights Profiler does something similar out of the box: it samples for a couple of minutes at a time and links traces to slow requests, which makes it easy to say 'this request was slow because of this stack'.
The mistake I see is treating diagnostics as harmless. A dump is a copy of production memory. If it ends up on a laptop or in a ticket, that's a possible notifiable data breach. So artefacts are encrypted, access-controlled, kept in an Australian region and deleted after [14] days."
| Capture | Overhead | Data sensitivity | Typical limit |
|---|---|---|---|
| Metrics (counters, OpenTelemetry) | Negligible | Low | Always on |
| Distributed traces | Low, with sampling | Medium (URLs, headers, SQL text) | Always on, sampled |
| CPU sampling trace (30–60 s) | A few % CPU | Low to medium (method names, some event payloads) | On demand or triggered, rate-limited |
| gcdump | Blocking full GC (100s of ms to seconds) | Low (types, no values) | On demand, one instance |
| Full dump | Process frozen while writing; disk = memory | High (everything) | Hangs/crashes only, approved |
| dotnet-monitor | Application Insights Profiler | |
|---|---|---|
| Where | Any host: AKS, Container Apps, VMs | Azure App Service, VMs, AKS with agent/SDK |
| What | Traces, gcdumps, dumps, logs, metrics on request or by rule | Periodic sampled CPU traces linked to requests |
| Control | You define triggers and egress | Mostly automatic; on-demand sessions |
| Status (late 2026) | Supported; .NET 10 release available | Classic SDK profiler GA; OpenTelemetry profiler in preview |
A payments API on AKS had a p99 spike every few days that lasted five minutes. A dotnet-monitor collection rule on request duration took a trace during the next spike; it showed thread pool starvation from a sync-over-async call in a rarely used refund path. The fix removed the spikes, and the rule's cost was one 40 MB trace in Blob Storage.
Checks whether the candidate can get evidence from production without causing an outage or a data breach.
Green flags
Red flags
Tier 1 always on metrics + traces + logs ──▶ Azure Monitor / Prometheus
│ alert
▼
Tier 2 targeted CPU trace, gcdump ──▶ dotnet-monitor / AI Profiler
│ still unexplained (hang, native, crash)
▼
Tier 3 heavy full dump ──▶ approved, one instance
Each tier is more expensive and more sensitive, so you go down only as far as you need.
The app and dotnet-monitor must share the diagnostics socket. In Kubernetes:
Pod
├─ app container DOTNET_DiagnosticPorts=/diag/dotnet-monitor.sock
├─ monitor container listens on /diag/dotnet-monitor.sock (Listen mode), :52323 API
└─ emptyDir volume /diag shared by both
In Listen mode the runtime connects to dotnet-monitor at start-up, so the monitor works even with a read-only /tmp. Endpoints include /processes, /trace, /gcdump, /dump, /logs, /livemetrics and /metrics (Prometheus). Collection rules combine a trigger (EventCounter thresholds, AspNetRequestDuration, AspNetResponseStatus), actions (CollectTrace, CollectGCDump, CollectDump) and limits (ActionCount, SlidingWindowDuration), with egress providers such as Azure Blob Storage.
The Profiler for .NET collects short ETW/EventPipe-based traces (by default for about two minutes at a time on a schedule, plus on-demand sessions and CPU or memory triggers) and correlates them with request telemetry, so the portal shows a 'hot path' for slow operations. As of late 2026 there are two paths: the classic Application Insights SDK profiler, and the Azure Monitor OpenTelemetry Profiler for .NET, which works with the Azure Monitor OpenTelemetry Distro and Application Insights SDK 3.x but is still prerelease. Check its current status before relying on it for production.
mcr.microsoft.com/dotnet/monitor image with Docker Compose, sharing a volume and setting DOTNET_DiagnosticPorts./processes and /trace?durationSeconds=30 with the API key.gc-heap-size exceeds a threshold; trigger it with a leaky endpoint.A Kubernetes pod with dotnet-monitor as a sidecar, sharing the diagnostics socket. Authentication stays on (the default); the API key comes from a Kubernetes secret.
apiVersion: v1
kind: Pod
metadata:
name: payments-api
spec:
volumes:
- name: diag
emptyDir: {}
containers:
- name: app
image: myregistry.azurecr.io/payments-api:1.42.0
env:
- name: DOTNET_DiagnosticPorts # runtime connects to the monitor
value: /diag/dotnet-monitor.sock
volumeMounts:
- { name: diag, mountPath: /diag }
- name: monitor
image: mcr.microsoft.com/dotnet/monitor:10
args: ["collect"] # auth is on by default; never pass --no-auth here
env:
- name: DotnetMonitor_DiagnosticPort__ConnectionMode
value: Listen
- name: DotnetMonitor_DiagnosticPort__EndpointName
value: /diag/dotnet-monitor.sock
- name: DotnetMonitor_Urls # internal only; no Service/Ingress
value: http://localhost:52323
- name: DotnetMonitor_Authentication__MonitorApiKey__Subject
valueFrom: { secretKeyRef: { name: dotnet-monitor-apikey, key: subject } }
- name: DotnetMonitor_Authentication__MonitorApiKey__PublicKey
valueFrom: { secretKeyRef: { name: dotnet-monitor-apikey, key: publicKey } }
volumeMounts:
- { name: diag, mountPath: /diag }
Generate the key pair once with dotnet monitor generatekey; callers send the token as Authorization: Bearer <token>.
A collection rule (in dotnet-monitor's settings) that takes at most one 30-second trace per hour when CPU stays high:
{
"CollectionRules": {
"HighCpu": {
"Trigger": {
"Type": "EventCounter",
"Settings": {
"ProviderName": "System.Runtime",
"CounterName": "cpu-usage",
"GreaterThan": 80,
"SlidingWindowDuration": "00:02:00"
}
},
"Actions": [
{
"Type": "CollectTrace",
"Settings": { "Profile": "Cpu", "Duration": "00:00:30", "Egress": "diagnosticsBlob" }
}
],
"Limits": { "ActionCount": 1, "ActionCountSlidingWindowDuration": "01:00:00" }
}
}
}
The senior move is to design for diagnosability before the incident: metrics and traces always on, dotnet-monitor or the Profiler deployed and tested, egress storage and access agreed with security, and a runbook that says which capture to take for which symptom. Then a production investigation is a 5-minute capture, not a week of 'can't reproduce'. I also involve security and privacy early: once they've agreed where artefacts live and who can open them, nobody hesitates during an incident.
| Option | When it fits | Cost | When not to |
|---|---|---|---|
| dotnet-monitor sidecar | AKS, Container Apps, VMs; custom triggers | Extra container, config, securing the API | Tiny services with no SLOs |
| Application Insights Profiler | App Service and Azure-hosted ASP.NET Core with AI | Agent/SDK, some overhead in sessions | Where the OTel profiler's preview status is unacceptable |
kubectl exec + CLI tools |
Ad-hoc, small teams | Tools in the image, shell access | Locked-down or distroless images |
| Full dump | Hang, crash, native memory | Pause, large sensitive file | CPU or simple managed-memory questions |
The .NET diagnostics tools all talk to the runtime over its diagnostics IPC channel, so they work on Windows, Linux and in containers without a debugger.
I start with counters because they are cheap, then pick the heavier tool the symptom points to. The trade-off is overhead and data sensitivity: a full dump contains every secret in memory.
When I can't attach a debugger, I take a dump: a snapshot of the process's memory, threads and stacks that I analyse offline. For a hang or a leak, dotnet-dump collect -p <pid> does it in seconds. For crashes, I enable automatic crash dumps with the DOTNET_DbgEnableMiniDump environment variables. On App Service I use Diagnose and solve problems, and in Kubernetes dotnet-monitor. Then I analyse with dotnet-dump analyze: clrstack -all and syncblk for hangs, dumpheap -stat and gcroot for leaks, pe for exceptions. Or I open the dump in Visual Studio and use the Threads and Parallel Stacks windows. Dumps contain customer data, so they're handled as sensitive.
OpenTelemetry gives you three correlated signals: traces (a span per operation, linked by trace id), metrics (cheap aggregated counters and histograms) and logs (events that carry the TraceId and SpanId of the span they were written in).
In .NET the runtime already emits Activity and Meter data; you call AddOpenTelemetry() with WithTracing, WithMetrics and WithLogging, set a resource (service.name), and choose an exporter: UseOtlpExporter() for any OTLP back end or Collector (endpoint from OTEL_EXPORTER_OTLP_ENDPOINT or options), or the Azure Monitor distro (UseAzureMonitor()) for Application Insights.
For cost: metrics for rates and latency (never sampled), sampled traces (the distro now defaults to a rate-limited sampler of 5 traces per second, which adapts the kept percentage to load; you can change the rate or switch to a fixed SamplingRatio), level-filtered logs, and tail sampling in a Collector, configured with policies to keep errors and slow traces. The trade-off is completeness versus ingestion cost.
How to tell it (STAR)
**S:** At [company] our payments API had a five-minute latency spike every few days, always overnight, and nobody could reproduce it. **T:** I needed evidence from production without waking someone at 3 am or risking customer data. **A:** I added dotnet-monitor as a sidecar with a collection rule on request duration, authenticated and writing to an Australian storage account with 14-day retention. When the rule fired, the trace showed threads blocked in Task.Wait in a refund reconciliation job. I made the job async and moved it to a background service with bounded concurrency. **R:** The spikes went from [every 2–4 days] to none in [three months], and the rule has since caught [two] other issues.
Last updated 23 Nov 2026.