-
-
Notifications
You must be signed in to change notification settings - Fork 226
Automatically capture heap dumps #3667
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 71 commits
Commits
Show all changes
85 commits
Select commit
Hold shift + click to select a range
44b7d65
POC
jamescrosswell 157a4a9
Configurable level
jamescrosswell 67a1c38
Changed dependency from net5.0 to net6.0
jamescrosswell 4f8f917
Format code
getsentry-bot 0d1aa2d
Update MemoryMonitor.cs
jamescrosswell 5ceff11
Exclude on Android and iOS
jamescrosswell ae55ae9
Bundle dotnet-gcdump in the Sentry nuget package
jamescrosswell c5b75ad
Merge branch 'auto-heap-dump' of github.com:getsentry/sentry-dotnet i…
jamescrosswell 60aeda0
Format code
getsentry-bot cc1a00e
Fixed Bindable tests
jamescrosswell b02fa28
Update CHANGELOG.md
jamescrosswell 0625662
Merge branch 'auto-heap-dump' of github.com:getsentry/sentry-dotnet i…
jamescrosswell 1d12b7c
Merge branch 'version-5.0.0' into auto-heap-dump
jamescrosswell ecfbce3
Update CHANGELOG.md
jamescrosswell 1e6d29b
Tweaked the demos
jamescrosswell 5b0f08e
Revert "Bundle dotnet-gcdump in the Sentry nuget package"
jamescrosswell ba4bcd9
Unbundled GCDump from NuGet package
jamescrosswell a357e9f
Switched to built in GC.RegisterForFullGCNotification events for garb…
jamescrosswell b6c3bff
Tweaked settings to expedite full GC in Heap Dump sample
jamescrosswell e36dfef
Added TryGetDumpLocation tests
jamescrosswell d35477b
Added CaptureMemoryDump tests
jamescrosswell 4c0ccc8
Refactored MemoryMonitor to use triggers and debouncers
jamescrosswell ffad135
Format code
getsentry-bot 265e397
Fixed tests
jamescrosswell 7a3b109
Merge branch 'auto-heap-dump' of github.com:getsentry/sentry-dotnet i…
jamescrosswell da07de2
Format code
getsentry-bot 975b9b1
Added CheckMemoryUsage tests
jamescrosswell 38ad7bc
Fixed remaining BindableOptions tests
jamescrosswell ef3a33f
Merge branch 'auto-heap-dump' of github.com:getsentry/sentry-dotnet i…
jamescrosswell 4b86619
Bundle dotnet-gcdump in Sentry.nupkg
jamescrosswell 08c9db4
Use bundled version of gcdump if it is present
jamescrosswell 169ef49
Delete buildlog.txt
jamescrosswell 2e6a0f1
Review feedback
jamescrosswell 87b76d8
Refactored error handling on garbage collection monitor to use a Cont…
jamescrosswell 3f15073
Comment in Dispose
jamescrosswell 2dfd4f4
Review feedback
jamescrosswell 99af671
Use _options.FileSystem
jamescrosswell acf93ab
Type
jamescrosswell 8708377
Merge branch 'version-5.0.0' into auto-heap-dump
jamescrosswell 3b62d53
Merge branch 'auto-heap-dump' of github.com:getsentry/sentry-dotnet i…
jamescrosswell 2a3d8b7
GCDump.props now downloads nuget directly, rather than installing dot…
jamescrosswell 3eb2f73
Created separate demo and tweaked the API
jamescrosswell 60f0b7e
Format code
getsentry-bot 70486da
Typo in transitive build file
jamescrosswell d2755db
Merge branch 'auto-heap-dump' of github.com:getsentry/sentry-dotnet i…
jamescrosswell 8133a63
Updated solution filters
jamescrosswell 58d9e55
Reverted to Continuation to handle errors in the gc monitor
jamescrosswell 7135767
Review feedback
jamescrosswell 22760c8
Update SentrySdk.cs
jamescrosswell f371304
Update Directory.Build.props
jamescrosswell 26c85b8
release: 14.12.1-dump1
getsentry-bot 0142d29
Workaround issue in release action
jamescrosswell 8a831fc
Revert "Workaround issue in release action"
jamescrosswell 056ec48
Merge branch 'release/14.12.1-dump1' into auto-heap-dump
29058f1
Revert "Merge branch 'release/14.12.1-dump1' into auto-heap-dump"
jamescrosswell 5469815
Review feedback
jamescrosswell f1c9e64
Merge branch 'version-5.0.0' into auto-heap-dump
jamescrosswell 8a49c01
Update ApiApprovalTests.Run.DotNet9_0.verified.txt
jamescrosswell dbe9f60
Update action.yml
jamescrosswell be63db4
Revert "Update action.yml"
jamescrosswell 36e4a2b
Update workaround for slow release builds for ios
jamescrosswell 076e9f9
Removed async void unit tests
jamescrosswell 506fba1
Drop net6.0 target from Sentry.Tests
jamescrosswell 298f57c
Add diagnostic logging for Windows tests
jamescrosswell a234ef2
Update build.yml
jamescrosswell f4fba3a
Merge branch 'version-5.0.0' into auto-heap-dump
jamescrosswell 4eafc16
Disabled diagnostics output on windows tests
jamescrosswell a09ffef
Update build.yml
jamescrosswell b8cffed
Use mock GC implementation for MemoryMonitorTests
jamescrosswell b216a3c
Update Sentry.Tests.csproj
jamescrosswell e1ba7c2
Try disabling heapdump tests on Windows in CI
jamescrosswell 2c79a4a
Reverse skip condition
jamescrosswell 72c90b5
Try re-enabling GarbageCollectionMonitorTests on Windows
jamescrosswell cadd0cf
Try reinstating MemoryMonitorTests (constructor test changed)
jamescrosswell 84c436f
Update MemoryMonitor.cs
jamescrosswell 3a9ba29
Refactored Constructor_NoHeapdumpsConfigured_Throws
jamescrosswell 9fea039
Try re-enabling remaining MemoryMonitorTests
jamescrosswell 845378c
Re-enable remaining MemoryMonitorTests
jamescrosswell 4245a75
Unbundled dotnet-gcdump
jamescrosswell 5865245
Disable CaptureMemoryDump and TryGetDumpLocation tests
jamescrosswell d9b9306
Re-enable CaptureMemoryDump tests
jamescrosswell 13bfe6f
Disable CaptureMemoryDump and enable TryGetDumpLocation
jamescrosswell d330c2c
Fixed CaptureMemoryDump_CapturesDump
jamescrosswell 8127bb5
Added remarks about dotnet-gcdump dependency to options
jamescrosswell e628bb3
Merge branch 'version-5.0.0' into auto-heap-dump
bruno-garcia 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
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
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
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
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
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
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
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
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
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
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
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,72 @@ | ||
| /* | ||
| * This sample demonstrates how you can configure Sentry to automatically capture heap dumps based on certain memory | ||
| * triggers (e.g. if memory consumption exceeds a certain percentage threshold). | ||
| * | ||
| * Note that this functionality is only available when targeting net6.0 or above and is not available on iOS, Android | ||
| * or Mac Catalyst. | ||
| */ | ||
|
|
||
| using System.Reflection; | ||
| using static System.Console; | ||
|
|
||
| var cts = new CancellationTokenSource(); | ||
|
|
||
| // Initialize the Sentry SDK. (It is not necessary to dispose it.) | ||
| SentrySdk.Init(options => | ||
| { | ||
| // You can set here in code, or you can set it in the SENTRY_DSN environment variable. | ||
| // See https://docs.sentry.io/product/sentry-basics/dsn-explainer/ | ||
| options.Dsn = "https://[email protected]/5428537"; | ||
|
|
||
| // When debug is enabled, the Sentry client will emit detailed debugging information to the console. | ||
| // This might be helpful, or might interfere with the normal operation of your application. | ||
| // We enable it here for demonstration purposes. | ||
| // You should not do this in your applications unless you are troubleshooting issues with Sentry. | ||
| options.Debug = true; | ||
|
|
||
| // Set TracesSampleRate = 0 to disable tracing for this demo | ||
| options.TracesSampleRate = 0; | ||
|
|
||
| // This option tells Sentry to capture a heap dump and send these as a file attachment in a Sentry event | ||
| options.EnableHeapDumps( | ||
| // Triggers a heap dump if the process uses more than 5% of the total memory. We could use any threshold or even | ||
| // provide a custom trigger function here instead. | ||
| 5, | ||
| // Limit the frequency of heap dumps to a maximum of 3 events per day and at least 1 hour between each event. | ||
| Debouncer.PerDay(3, TimeSpan.FromHours(1)), | ||
| // Set the level for heap dump events to Info | ||
| SentryLevel.Info | ||
| ); | ||
|
|
||
| // This is an example of intercepting events before they get sent to Sentry. Typically, you might use this to | ||
| // filter events that you didn't want to send but in this case we're using it to detect when a heap dump has | ||
| // been captured, so we know when to stop allocating memory in the heap dump demo. | ||
| options.SetBeforeSend((evt, hint) => | ||
| { | ||
| if (hint.Attachments.Any(a => a.FileName.EndsWith("gcdump"))) | ||
| { | ||
| cts.Cancel(); | ||
| } | ||
| return evt; // If we returned null here, that would stop the event from being sent | ||
| }); | ||
| }); | ||
|
|
||
| // In Debug mode there will be a bit of stuff logged out during initialization... wait for that to play out | ||
| await Task.Delay(1000); | ||
|
|
||
| var memoryHog = new List<object>(); | ||
| WriteLine(); | ||
|
|
||
| WriteLine("Hogging memory..."); | ||
|
|
||
| // Sentry checks memory usage every time a full garbage collection occurs. It might take a while to trigger this, | ||
| // although we've configured some ridiculously aggressive settings in the runtimeconfig.template.json file to make | ||
| // this happen more quickly, for the purposes of this demo... definitely don't do this in production! | ||
| while (cts.Token.IsCancellationRequested == false) | ||
| { | ||
| var array = new byte[2_000_000_000]; | ||
| array.Initialize(); | ||
| memoryHog.Add(array); | ||
| } | ||
|
|
||
| GC.KeepAlive(memoryHog); | ||
55 changes: 55 additions & 0 deletions
55
samples/Sentry.Samples.Console.HeapDump/Sentry.Samples.Console.HeapDump.csproj
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,55 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <InvariantGlobalization>true</InvariantGlobalization> | ||
| </PropertyGroup> | ||
| <PropertyGroup> | ||
| <!-- | ||
| Note, these options do nothing if you are not authenticated. | ||
| See https://docs.sentry.io/platforms/dotnet/configuration/msbuild/#authentication | ||
| --> | ||
| <!-- | ||
| <SentryUrl>...your Sentry URL if self-hosted, or omit this line if using sentry.io...</SentryUrl> | ||
| --> | ||
| <SentryOrg>sentry-sdks</SentryOrg> | ||
| <SentryProject>sentry-dotnet</SentryProject> | ||
|
|
||
| <!-- | ||
| After the above properties are configured, you can use the following features. | ||
| Uploading symbols to Sentry will enable server-side symbolication (i.e. when the PDB is not present at runtime, or for AOT published programs). | ||
| Uploading sources to Sentry during the build will enable Source Context in the Sentry issue details page. | ||
| --> | ||
| <SentryUploadSymbols>true</SentryUploadSymbols> | ||
| <SentryUploadSources>true</SentryUploadSources> | ||
|
|
||
| <!-- | ||
| You can automatically create releases via sentry-cli and control their creation via these properties | ||
| See https://docs.sentry.io/cli/releases/#creating-releases | ||
| --> | ||
| <SentryCreateRelease>true</SentryCreateRelease> | ||
|
|
||
| <!-- | ||
| To associate commits with releases | ||
| See https://docs.sentry.io/cli/releases/#commit-integration | ||
| --> | ||
| <SentrySetCommits>true</SentrySetCommits> | ||
| <SentrySetCommitOptions>--local</SentrySetCommitOptions> | ||
|
|
||
| <!-- | ||
| To associate commits with releases | ||
| See https://docs.sentry.io/cli/releases/#commit-integration | ||
| --> | ||
| <!-- <SentrySetCommits>true</SentrySetCommits>--> | ||
| <!-- <SentrySetCommitOptions>--local</SentrySetCommitOptions>--> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- In your own project, this would be a PackageReference to the latest version of Sentry. --> | ||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\src\Sentry\Sentry.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
6 changes: 6 additions & 0 deletions
6
samples/Sentry.Samples.Console.HeapDump/runtimeconfig.template.json
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,6 @@ | ||
| { | ||
| "configProperties": { | ||
| "System.GC.ConserveMemory": 9, | ||
| "System.GC.HighMemoryPercent": 20 | ||
| } | ||
| } |
Oops, something went wrong.
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.