-
-
Notifications
You must be signed in to change notification settings - Fork 206
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
Automatically capture heap dumps #3667
base: version-5.0.0
Are you sure you want to change the base?
Conversation
…nto auto-heap-dump
…nto auto-heap-dump
This reverts commit ae55ae9.
…age collection monitoring
…nto auto-heap-dump
…nto auto-heap-dump
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we make an alpha from this branch and test on Symbol Collector?
samples/Sentry.Samples.Console.Basic/runtimeconfig.template.json
Outdated
Show resolved
Hide resolved
using var sut = _fixture.GetSut(); | ||
|
||
// Act | ||
sut.CaptureMemoryDump(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any tests where CaptureMemoryDump
throw? More concerned about the caller actually. Since we don't want to crash the app, do we handle every Task we create?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Task that calls that is ultimately this:
sentry-dotnet/src/Sentry/Internal/MemoryMonitor.cs
Lines 40 to 46 in 58d9e55
// Since we're not awaiting the task, the continuation will happen elsewhere but that's OK - all we care about | |
// is that any exceptions get logged as soon as possible. | |
GarbageCollectionMonitor.Start(CheckMemoryUsage, _cancellationTokenSource.Token) | |
.ContinueWith( | |
t => _options.LogError(t.Exception!, "Garbage collection monitor failed"), | |
TaskContinuationOptions.OnlyOnFaulted // guarantees that the exception is not null | |
); |
I played around with various things and eventually settled on a FireAndForget with a Continuation. The alternative of holding a reference to the task wasn't ideal because you only become aware of any errors when you await the task... which here would have to happen when disposing of the MemoryMonitor (application shutdown). I wanted to log any errors as soon as they occur however.
I've refactored the GarbageCollectionMonitor
and added some GarbageCollectionMonitorTests
just to make sure cancellation happens as we expect (without bubbling any exceptions up that might disrupt the calling code).
I think ultimately what you're wanting to test is that task continuation but the fire and forget nature of that code makes it difficult to test. I did test it manually in a console app, when I was investigating how to detect any non-cancellation errors as soon as they happen.
We can. Currently the merge target is the version-5.0.0 branch so an alternative would be to make a |
Lets make the release then, before we approve (lets not merge this accidently) |
This reverts commit 0142d29.
@jamescrosswell feel free to add it to https://github.com/getsentry/symbol-collector if it helps test this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll be honest I didn't look in detail as much as this change might require but it does seem good to go.
Looking at the preview package though, it does have a LOT of files. I wonder if we have to be concerned about the increase in size (sentry-cli is huge already)?
also maybe @filipnavara might be interested in this feature. So might be willing to review the PR too 🙏 |
Is CI on Windows really taking over 1 hour and 20 minutes? or this is hanging? https://github.com/getsentry/sentry-dotnet/actions/runs/11659928344/job/32500819174?pr=3667 The other day I killed a build that seemed to be handing but didn't take note of whcih agent |
Seems to be hanging since merging in the latest updates from the version-5.0.0 branch. |
Resolves #2580
Basic usage
samples/Sentry.Samples.Console.Basic/Sentry.Samples.Console.Basic.csproj
includes an example of how to configure automatic heap dumps:sentry-dotnet/samples/Sentry.Samples.Console.Basic/Program.cs
Lines 41 to 50 in ffad135
That sample demonstrates using a built in trigger that we provide, that triggers heap dumps when memory usage exceeds a certain threshold (5% in that example).
Alternatively there is an override for the
EnableHeapDumps
method that SDK users can call to provide a custom trigger:sentry-dotnet/src/Sentry/SentryOptions.cs
Line 561 in 265e397
Prerequisites
dotnet-gcdump
The SDK relies on dotnet-gcdump to capture the heap dumps.
SDK users can bundle this with their application by setting the
SentryBundleGCDump
build property totrue
in their csproj file.Alternatively, the
dotnet-gcdump
can be installed globally on the machine or container where the heap dumps will be captured.net6.0
dotnet-gcdump requires .NET 6 or later.
Analysing the Dump File
A couple of different options:
See Stefan Geiger's blog for a bit of info on the first two options.