-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Added documentation for automatic heap dumps #12848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| --- | ||
| title: Heap Dumps | ||
| sidebar_order: 23 | ||
| description: "This experimental feature allows you to automatically capture heap dumps for your application." | ||
| --- | ||
|
|
||
| <Alert> | ||
|
|
||
| The SDK relies on `dotnet-gcdump` to capture the heap dumps. `dotnet-gcdump` requires .NET 6 or later and must be [installed globally](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-gcdump#install) on the machine or container where the heap dumps will be captured. | ||
|
|
||
| </Alert> | ||
|
|
||
| Using the .NET SDK you can automatically captures heap dumps based on certain triggers. When triggered, the SDK captures the heap dump and sends an event to Sentry with the heap dump as an attachment. | ||
|
|
||
| The basic configuration for enabling automatic heap dumps is: | ||
|
|
||
| ```csharp | ||
| SentrySdk.Init(options => { | ||
| // All your other options like DSN etc. | ||
| ... | ||
| options.EnableHeapDumps( | ||
| // Triggers if the process uses more than 90% of the total available memory | ||
| 90, | ||
| // Limit heap dumps to 3 per day with at least 2 hours between each event | ||
| Debouncer.PerDay(3, TimeSpan.FromHours(2)), | ||
| // Set the level for heap dump events to Warning | ||
| SentryLevel.Warning | ||
| ); | ||
| }); | ||
| ``` | ||
|
|
||
| ### Trigger | ||
|
|
||
| The first argument to `EnableHeapDumps` is the *Trigger*. The above example passes an integer as the trigger, which configures the SDK to capture a heap dump when the memory allocated by your application exceeds a certain percentage threshold of total available memory. | ||
|
|
||
| Alternatively, there is an overload of `EnableHeapDumps` that allows you to specify a custom trigger: | ||
|
|
||
| ```csharp | ||
| SentrySdk.Init(options => { | ||
| // All your other options like DSN etc. | ||
| ... | ||
jamescrosswell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| options.EnableHeapDumps( | ||
| // Triggers if the process uses more than 10MB of memory | ||
| (usedMemory, totalMemory) => usedMemory > 10_000_000, | ||
| // Limit heap dumps to 3 per day with at least 2 hours between each event | ||
| Debouncer.PerDay(3, TimeSpan.FromHours(2)), | ||
| // Set the level for heap dump events to Warning | ||
| SentryLevel.Warning | ||
| ); | ||
| }); | ||
| ``` | ||
|
|
||
| ### Debouncer | ||
|
|
||
| The second argument is a *Debouncer*, which is used to prevent heap dumps from being captured too often. | ||
|
|
||
| The above examples configure a debouncer that limits heap dumps to 3 per day with a cooldown of at least 2 hours between each event. The other available debouncers are `PerMinute`, `PerHour`, and `PerApplicationLifetime`. | ||
|
|
||
| If no debouncer is specified, this defaults to Debouncer.PerApplicationLifetime(1) - which means only one heap dump will be captured each time the application is run. If the application keeps running for 3 months then no more than one heap dump will be sent during that 3 month period. | ||
|
|
||
| ### Event Level | ||
|
|
||
| The final argument determines the event level to associate with the event that the heap dump is attached to. If you don't specify a value then this defaults to `SentryLevel.Warning`. | ||
|
|
||
| ## Viewing heap dumps | ||
|
|
||
| Heap dumps will be displayed as "Memory threshold exceeded" events in the Sentry UI. Clicking on such an event, you’ll see all the usual event details. However the event will also contain a `.gcdump` file as an attachment, that you can download for analysis. | ||
|
|
||
| There are various different tools that you can use to view the dump file: | ||
| - [dotnet-gcdump report](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-gcdump) | ||
| - [dotnet-heapview](https://github.com/1hub/dotnet-heapview) | ||
jamescrosswell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - [Visual Studio](https://devblogs.microsoft.com/dotnet/collecting-and-analyzing-memory-dumps/) | ||
| - [Perfview](https://github.com/microsoft/perfview) | ||
|
|
||
| ## Feedback | ||
|
|
||
| This features is currently experimental and we're open to suggestions about how it could be improved. | ||
|
|
||
| If you have any feedback about the capabilities or the API design, please join the [discussion on GitHub](https://github.com/getsentry/sentry-dotnet/discussions/3885). | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.