Covers capturing dumps in production safely: dump types (full, heap, triage, gcdump), dotnet-dump, createdump environment variables, dotnet-monitor sidecars and triggers, pause and size impact, storage and Privacy Act handling, and offline analysis.
First choose the dump type for the question: a gcdump (managed object graph only, no field values, usually tens of MB) for leaks; a heap or full dump for hangs, deadlocks and SOS analysis; a triage dump for crashes when you want less personal data. Capturing pauses the process for seconds; a full dump is roughly the size of the working set and a heap dump roughly the managed heap plus stacks, so I take the instance out of rotation, check there's disk space, and write to a mounted volume, not the container's ephemeral layer.
In containers I use dotnet-monitor as a sidecar, with collection rules that capture automatically on a trigger and egress to encrypted Blob storage, plus createdump environment variables for crashes. A heap dump contains tokens and customer data, so it's handled like production data: stored in-region, restricted, deleted after analysis. The trade-off is evidence versus impact and privacy.
"I start with what I need the dump to answer, because that decides the type. For a slow memory leak I want a gcdump:
dotnet-gcdumpopens an EventPipe session that triggers a gen 2 GC, the runtime streams the managed object graph (types, sizes and references) as events while it walks the heap, and the tool saves that as a.gcdumpfile, usually tens of megabytes with no field values, so no customer data. For a hang or deadlock I need thread stacks and locks, so a heap or full dump withdotnet-dump collect --type Heapand SOS. For crashes I configure createdump through environment variables so the runtime writes a dump when it dies.Then I think about impact. A heap or full dump suspends the process while memory is written out, which can be several seconds for a few gigabytes, and a gcdump runs a full blocking GC. A full dump is about the size of the working set, so a 3 GB process needs 3 GB of free disk, and in Kubernetes that can blow the pod's ephemeral storage limit and get it evicted, destroying the evidence. So I take the instance out of the load balancer or let the readiness probe fail first, write to a mounted volume, and copy the file out. For example, at [company] we [ran dotnet-monitor as a sidecar with a rule that captured a heap dump when the GC heap passed 2 GB and uploaded it to Blob storage], which meant [we had the evidence from a 3 am OOM before the pod restarted]. dotnet-monitor ships on its own release cadence alongside .NET servicing, so I check the current release's supported runtimes and trigger types before relying on a feature.
The part people forget is that a heap dump is a copy of everything in memory: bearer tokens, connection strings, Data Protection keys, customer names. Under the Privacy Act that's personal information, so the dump goes to encrypted storage in Australia East with access limited to the responders, never into a ticket or a laptop's Downloads folder, and it gets deleted when the investigation closes. If a dump might have exposed live tokens or secrets to someone outside that group, I treat them as compromised and rotate them. The mistake I see is treating dumps as harmless debug files."
| Type | How | Contains | Typical size | Use for |
|---|---|---|---|---|
| gcdump | dotnet-gcdump collect -p <pid> |
Managed object graph: types, counts, sizes, references | Tens to hundreds of MB | Leaks, "what is holding memory" |
| Heap | dotnet-dump collect --type Heap |
Managed heap, thread stacks, module list | β managed heap + stacks | Hangs, deadlocks, leaks with values |
| Full | dotnet-dump collect --type Full |
All process memory incl. native | β working set | Native leaks, interop crashes |
| Mini | --type Mini |
Thread stacks and modules | Small | Quick stacks only |
| Triage | --type Triage |
Mini dump with personal data such as paths and strings stripped | Small | Crash stacks to share more widely |
| Tool | When it fits | Watch out for |
|---|---|---|
dotnet-dump / dotnet-gcdump |
Someone is on the box, problem is happening now | Needs the tool in the container or a debug container |
| createdump on crash (env vars) | Crashes and fatal errors you can't predict | Disk space at crash time; the kernel OOM killer's SIGKILL does not produce a dump |
| dotnet-monitor collection rules | Containers; capture automatically on a condition | Sidecar must share the diagnostic port; secure its API |
| App Service "Collect memory dump" (Diagnose and solve problems) | App Service on Windows | Process pause; storage location |
| Risk | Mitigation |
|---|---|
| Process freezes during capture | Remove from rotation first; capture one instance, not all |
| Disk or ephemeral storage full | Mount an emptyDir with a size or a PVC; egress to Blob straight away |
| Pod OOMKilled before you capture | dotnet-monitor heap trigger below the limit, or GCHeapHardLimitPercent so the runtime throws OOM (and createdump runs) before the kernel kills it |
| Personal data in the dump | Prefer gcdump or triage; encrypted Blob in-region; RBAC; short retention; rotate exposed secrets |
| Wrong symbols at analysis time | Keep PDBs from the build; symbol server; same runtime version |
An order API on AKS was OOMKilled every few hours. A dotnet-monitor rule (System.Runtime gc-heap-size above 1,800 MB for 1 minute, one dump per hour at most) captured a 2.1 GB heap dump to Blob storage in Australia East; dumpheap -stat and gcroot on it showed 1.4 million cached PriceQuote objects held by a static dictionary, and the fix shipped the same day.
Checks the candidate can get evidence from production without causing an outage or a data breach, and choose the right dump type.
Green flags
Red flags
On Linux, dotnet-dump collect asks the runtime over the diagnostic port (a Unix domain socket in $TMPDIR named dotnet-diagnostic-<pid>-...) to run createdump, which suspends the process's threads and reads its memory through /proc/<pid>/mem, writing an ELF core file. On Windows it uses MiniDumpWriteDump. The process is frozen for the whole write, so time grows with dump size and disk speed.
dotnet-dump ββdiagnostic IPCβββΊ runtime in target process
β launches createdump
βΌ
suspend threads ββΊ read memory ββΊ write core file
β
resume process
dotnet-gcdump works differently: it starts an EventPipe session that triggers a gen 2 GC; while the GC walks the heap the runtime emits the object graph as events, and the tool builds the .gcdump file on its side. No process memory is copied, but the GC is blocking, so a big heap still pauses requests.
The runtime writes a dump on an unhandled exception or fatal error when configured:
DOTNET_DbgEnableMiniDump=1
DOTNET_DbgMiniDumpType=2 # 1 Mini, 2 Heap, 3 Triage, 4 Full
DOTNET_DbgMiniDumpName=/dumps/%e-%p-%t.dmp # %e exe, %p pid, %t time
DOTNET_CreateDumpDiagnostics=1 # log createdump problems
It can't help when the kernel OOM killer sends SIGKILL: there's no chance to run code. For OOMKilled pods you need a trigger before the limit (dotnet-monitor) or a GCHeapHardLimit / GCHeapHardLimitPercent below the container limit so the runtime throws OutOfMemoryException first and createdump can run.
dotnet-monitor runs as a separate container in the same pod. Both share a volume for the diagnostic socket; the usual setup is the app connecting to dotnet-monitor in listen mode via DOTNET_DiagnosticPorts. It exposes an HTTP API (default port 52323) for /dump, /gcdump, /trace, /logs, and a metrics endpoint. Collection rules make it automatic:
Trigger (EventCounter threshold, AspNetRequestDuration, AspNetResponseStatus, AspNetRequestCount)
βββΊ Actions (CollectDump, CollectGCDump, CollectTrace, CollectLogs) ββΊ Egress provider (Azure Blob)
βββΊ Limits (ActionCount, ActionCountSlidingWindowDuration, RuleDuration)
The API must be authenticated (API key or Entra ID) and never exposed outside the pod network: it can dump memory. dotnet-monitor is released separately from the runtime, so check which release supports your runtime and which triggers it offers before relying on a feature.
Chiseled and distroless images have no shell. Options: bake nothing in and use kubectl debug -it <pod> --image=mcr.microsoft.com/dotnet/sdk:10.0 --target=<container> to get an ephemeral container sharing the process namespace (the diagnostic socket lives in the target's /tmp, so you need access to it, e.g. via /proc/<pid>/root/tmp); or rely on the dotnet-monitor sidecar. Running as the same user ID matters for permissions.
A heap or full dump contains every managed string: JWTs, connection strings resolved from Key Vault, request bodies, customer names and addresses. Treat it as production data covered by the Privacy Act 1988 and your data classification:
dotnet-dump analyze api.dmp
> clrthreads # managed threads, lock counts, exceptions
> clrstack -all # every managed stack
> syncblk # who owns which Monitor lock
> dumpheap -stat # types by count and size
> gcroot <address> # why an object is still alive
Use the same runtime major version and architecture as the dump. Visual Studio (Debug Managed Memory, Parallel Stacks) and WinDbg can also open .NET Linux core dumps. Open .gcdump files in Visual Studio, PerfView or dotnet-gcdump report.
| Symptom | Likely cause | Fix |
|---|---|---|
Unable to connect to the process / no processes listed |
Tool can't see the diagnostic socket (different /tmp, different user, separate container) |
Same user ID; share /tmp or use /proc/<pid>/root/tmp; use kubectl debug --target |
Permission denied / ptrace errors |
Container security context blocks ptrace (seccomp, missing SYS_PTRACE in older setups) |
Run as the same user; allow ptrace for the debug container only |
| Dump file truncated or zero bytes | Disk or emptyDir filled during the write |
Size the volume above the working set; egress immediately |
| Pod evicted mid-capture | Ephemeral storage limit exceeded | Write to a sized volume, not the container layer |
| No crash dump after a crash | OOMKill (SIGKILL), wrong path, or volume not writable | Check DOTNET_CreateDumpDiagnostics=1 output; heap trigger before the limit |
| dotnet-monitor rule never fires | Wrong counter name, app not connected to the socket, limits reached | GET /processes on the monitor API; check its logs; review Limits |
Rehearse this in staging: a capture you have never tried will fail at 3 am for one of these reasons.
dotnet-gcdump and dotnet-dump --type Heap sizes and pause times while load is running.gc-heap-size and egress to Azurite or Blob storage.dumpheap -type System.String plus dumpobj) to see why dumps are sensitive.kubectl debug --target against a chiseled image and capture a dump; then break it on purpose (fill the volume, wrong user) and read the errors.A Kubernetes pod with a dotnet-monitor sidecar that captures a heap dump automatically when the managed heap grows too large, plus crash dumps to a mounted volume.
# Deployment excerpt: app + dotnet-monitor sharing the diagnostic socket and a dump volume.
spec:
containers:
- name: api
image: myregistry.azurecr.io/orders-api:1.42.0
env:
- { name: DOTNET_DiagnosticPorts, value: /diag/dotnet-monitor.sock } # app connects to monitor
- { name: DOTNET_DbgEnableMiniDump, value: "1" } # crash dumps
- { name: DOTNET_DbgMiniDumpType, value: "2" } # 2 = heap
- { name: DOTNET_DbgMiniDumpName, value: /dumps/%e-%p-%t.dmp }
volumeMounts:
- { name: diag, mountPath: /diag }
- { name: dumps, mountPath: /dumps }
- name: monitor
image: mcr.microsoft.com/dotnet/monitor:9 # use the tag that matches your supported runtime
args: ["collect", "--urls", "http://localhost:52323", "--metricUrls", "http://+:52325"]
env:
- { name: DOTNETMONITOR_DiagnosticPort__ConnectionMode, value: Listen }
- { name: DOTNETMONITOR_DiagnosticPort__EndpointName, value: /diag/dotnet-monitor.sock }
- { name: DOTNETMONITOR_Storage__DumpTempFolder, value: /dumps }
volumeMounts:
- { name: diag, mountPath: /diag }
- { name: dumps, mountPath: /dumps }
- { name: monitor-config, mountPath: /etc/dotnet-monitor } # settings.json below, from a ConfigMap/Secret
volumes:
- { name: diag, emptyDir: {} }
- name: dumps
emptyDir: { sizeLimit: 6Gi } # room for a dump without evicting the pod
- { name: monitor-config, secret: { secretName: dotnet-monitor-settings } }
{
"CollectionRules": {
"HeapTooBig": {
"Trigger": {
"Type": "EventCounter",
"Settings": { "ProviderName": "System.Runtime", "CounterName": "gc-heap-size", "GreaterThan": 1800, "SlidingWindowDuration": "00:01:00" }
},
"Actions": [ { "Type": "CollectDump", "Settings": { "Type": "WithHeap", "Egress": "incidentBlob" } } ],
"Limits": { "ActionCount": 1, "ActionCountSlidingWindowDuration": "01:00:00" }
}
},
"Egress": {
"AzureBlobStorage": {
"incidentBlob": {
"AccountUri": "https://stincidentdumpsaue.blob.core.windows.net",
"ContainerName": "dumps",
"ManagedIdentityClientId": "<client-id>"
}
}
}
}
# Manual capture from an ephemeral debug container sharing the process namespace
kubectl debug -it orders-api-7d9f -n orders --image=mcr.microsoft.com/dotnet/sdk:10.0 --target=api -- bash
dotnet tool install -g dotnet-dump dotnet-gcdump && export PATH=$PATH:~/.dotnet/tools
dotnet-gcdump collect -p 1 -o /tmp/orders.gcdump # leak: graph only, no values
dotnet-dump collect -p 1 --type Heap -o /tmp/orders.dmp # hang: stacks + heap
emptyDir or volume, then egress to Blob storage.GCHeapHardLimit below the container limit.The senior point is that a dump is evidence with a cost: it pauses a production process and creates a sensitive file. So I decide in advance, not at 3 am: which dump types we allow, where they go, who can read them and how long they live, and I wire automatic capture (dotnet-monitor rules, createdump variables) into the platform so the evidence exists before anyone is paged. If we only ever take gcdumps for leaks, we rarely create personal data at all.
| Approach | When it fits | Cost | When not to |
|---|---|---|---|
Manual dotnet-dump |
Live hang you can observe now | Needs tooling access, pause | Pod will restart before you get there |
| dotnet-monitor rules | Containers, recurring or overnight issues | Sidecar, config, securing its API | Very small services where it's overkill |
| createdump on crash | Unhandled exceptions, fatal errors | Disk at crash time | OOMKill (no dump is written) |
| App Insights Snapshot Debugger | Exceptions in App Service with the classic SDK | Small snapshots, limited scope | OpenTelemetry-only apps: check current support first |
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.
First confirm a leak: memory keeps rising across GCs under steady load, rather than a cache warming up. Then decide managed or native: if the GC heap size (dotnet-counters) grows with the working set, it is managed; if the working set grows while the GC heap is flat, look at native memory. For managed leaks, take two dotnet-gcdump snapshots some time apart and compare which types grow, then use dotnet-dump with dumpheap -stat and gcroot to find what keeps them alive. Typical roots: static collections and caches, event subscriptions, timers, captured closures, DI root-scoped transients, and unbounded queues. Fix, then verify with the same metrics under load.
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.
How to tell it (STAR)
**S:** At [company] our order API on AKS was being OOMKilled every few hours, mostly overnight, and every restart destroyed the evidence. **T:** I [owned / was asked to lead] getting a dump we could actually analyse, safely. **A:** I added a dotnet-monitor sidecar with a rule that captured one heap dump when the GC heap passed [1.5 GB], wrote it to a sized volume and egressed it to encrypted Blob storage in Australia East, with access limited to the incident group and a 14-day deletion rule because dumps hold customer data. The first night's dump showed a static dictionary cache with no eviction holding [1.4 million] quotes. **R:** We replaced it with HybridCache with a size limit, memory stabilised at [about 600 MB], and OOMKills went from [6 a day] to zero.
Last updated 23 Nov 2026.