Skip to content
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

Merged
merged 85 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
44b7d65
POC
jamescrosswell Oct 9, 2024
157a4a9
Configurable level
jamescrosswell Oct 9, 2024
67a1c38
Changed dependency from net5.0 to net6.0
jamescrosswell Oct 9, 2024
4f8f917
Format code
getsentry-bot Oct 9, 2024
0d1aa2d
Update MemoryMonitor.cs
jamescrosswell Oct 9, 2024
5ceff11
Exclude on Android and iOS
jamescrosswell Oct 10, 2024
ae55ae9
Bundle dotnet-gcdump in the Sentry nuget package
jamescrosswell Oct 10, 2024
c5b75ad
Merge branch 'auto-heap-dump' of github.com:getsentry/sentry-dotnet i…
jamescrosswell Oct 10, 2024
60aeda0
Format code
getsentry-bot Oct 11, 2024
cc1a00e
Fixed Bindable tests
jamescrosswell Oct 11, 2024
b02fa28
Update CHANGELOG.md
jamescrosswell Oct 11, 2024
0625662
Merge branch 'auto-heap-dump' of github.com:getsentry/sentry-dotnet i…
jamescrosswell Oct 11, 2024
1d12b7c
Merge branch 'version-5.0.0' into auto-heap-dump
jamescrosswell Oct 11, 2024
ecfbce3
Update CHANGELOG.md
jamescrosswell Oct 11, 2024
1e6d29b
Tweaked the demos
jamescrosswell Oct 11, 2024
5b0f08e
Revert "Bundle dotnet-gcdump in the Sentry nuget package"
jamescrosswell Oct 13, 2024
ba4bcd9
Unbundled GCDump from NuGet package
jamescrosswell Oct 13, 2024
a357e9f
Switched to built in GC.RegisterForFullGCNotification events for garb…
jamescrosswell Oct 14, 2024
b6c3bff
Tweaked settings to expedite full GC in Heap Dump sample
jamescrosswell Oct 14, 2024
e36dfef
Added TryGetDumpLocation tests
jamescrosswell Oct 15, 2024
d35477b
Added CaptureMemoryDump tests
jamescrosswell Oct 15, 2024
4c0ccc8
Refactored MemoryMonitor to use triggers and debouncers
jamescrosswell Oct 15, 2024
ffad135
Format code
getsentry-bot Oct 15, 2024
265e397
Fixed tests
jamescrosswell Oct 15, 2024
7a3b109
Merge branch 'auto-heap-dump' of github.com:getsentry/sentry-dotnet i…
jamescrosswell Oct 15, 2024
da07de2
Format code
getsentry-bot Oct 15, 2024
975b9b1
Added CheckMemoryUsage tests
jamescrosswell Oct 15, 2024
38ad7bc
Fixed remaining BindableOptions tests
jamescrosswell Oct 15, 2024
ef3a33f
Merge branch 'auto-heap-dump' of github.com:getsentry/sentry-dotnet i…
jamescrosswell Oct 15, 2024
4b86619
Bundle dotnet-gcdump in Sentry.nupkg
jamescrosswell Oct 17, 2024
08c9db4
Use bundled version of gcdump if it is present
jamescrosswell Oct 17, 2024
169ef49
Delete buildlog.txt
jamescrosswell Oct 17, 2024
2e6a0f1
Review feedback
jamescrosswell Oct 23, 2024
87b76d8
Refactored error handling on garbage collection monitor to use a Cont…
jamescrosswell Oct 23, 2024
3f15073
Comment in Dispose
jamescrosswell Oct 23, 2024
2dfd4f4
Review feedback
jamescrosswell Oct 23, 2024
99af671
Use _options.FileSystem
jamescrosswell Oct 23, 2024
acf93ab
Type
jamescrosswell Oct 23, 2024
8708377
Merge branch 'version-5.0.0' into auto-heap-dump
jamescrosswell Oct 23, 2024
3b62d53
Merge branch 'auto-heap-dump' of github.com:getsentry/sentry-dotnet i…
jamescrosswell Oct 23, 2024
2a3d8b7
GCDump.props now downloads nuget directly, rather than installing dot…
jamescrosswell Oct 23, 2024
3eb2f73
Created separate demo and tweaked the API
jamescrosswell Oct 23, 2024
60f0b7e
Format code
getsentry-bot Oct 23, 2024
70486da
Typo in transitive build file
jamescrosswell Oct 23, 2024
d2755db
Merge branch 'auto-heap-dump' of github.com:getsentry/sentry-dotnet i…
jamescrosswell Oct 23, 2024
8133a63
Updated solution filters
jamescrosswell Oct 23, 2024
58d9e55
Reverted to Continuation to handle errors in the gc monitor
jamescrosswell Oct 23, 2024
7135767
Review feedback
jamescrosswell Oct 28, 2024
22760c8
Update SentrySdk.cs
jamescrosswell Oct 28, 2024
f371304
Update Directory.Build.props
jamescrosswell Oct 28, 2024
26c85b8
release: 14.12.1-dump1
getsentry-bot Oct 28, 2024
0142d29
Workaround issue in release action
jamescrosswell Oct 28, 2024
8a831fc
Revert "Workaround issue in release action"
jamescrosswell Oct 28, 2024
056ec48
Merge branch 'release/14.12.1-dump1' into auto-heap-dump
Oct 28, 2024
29058f1
Revert "Merge branch 'release/14.12.1-dump1' into auto-heap-dump"
jamescrosswell Oct 29, 2024
5469815
Review feedback
jamescrosswell Nov 4, 2024
f1c9e64
Merge branch 'version-5.0.0' into auto-heap-dump
jamescrosswell Nov 4, 2024
8a49c01
Update ApiApprovalTests.Run.DotNet9_0.verified.txt
jamescrosswell Nov 4, 2024
dbe9f60
Update action.yml
jamescrosswell Nov 4, 2024
be63db4
Revert "Update action.yml"
jamescrosswell Nov 4, 2024
36e4a2b
Update workaround for slow release builds for ios
jamescrosswell Nov 6, 2024
076e9f9
Removed async void unit tests
jamescrosswell Nov 6, 2024
506fba1
Drop net6.0 target from Sentry.Tests
jamescrosswell Nov 6, 2024
298f57c
Add diagnostic logging for Windows tests
jamescrosswell Nov 6, 2024
a234ef2
Update build.yml
jamescrosswell Nov 6, 2024
f4fba3a
Merge branch 'version-5.0.0' into auto-heap-dump
jamescrosswell Nov 7, 2024
4eafc16
Disabled diagnostics output on windows tests
jamescrosswell Nov 7, 2024
a09ffef
Update build.yml
jamescrosswell Nov 7, 2024
b8cffed
Use mock GC implementation for MemoryMonitorTests
jamescrosswell Nov 9, 2024
b216a3c
Update Sentry.Tests.csproj
jamescrosswell Nov 9, 2024
e1ba7c2
Try disabling heapdump tests on Windows in CI
jamescrosswell Nov 10, 2024
2c79a4a
Reverse skip condition
jamescrosswell Nov 10, 2024
72c90b5
Try re-enabling GarbageCollectionMonitorTests on Windows
jamescrosswell Nov 11, 2024
cadd0cf
Try reinstating MemoryMonitorTests (constructor test changed)
jamescrosswell Nov 11, 2024
84c436f
Update MemoryMonitor.cs
jamescrosswell Nov 11, 2024
3a9ba29
Refactored Constructor_NoHeapdumpsConfigured_Throws
jamescrosswell Nov 11, 2024
9fea039
Try re-enabling remaining MemoryMonitorTests
jamescrosswell Nov 11, 2024
845378c
Re-enable remaining MemoryMonitorTests
jamescrosswell Nov 11, 2024
4245a75
Unbundled dotnet-gcdump
jamescrosswell Nov 11, 2024
5865245
Disable CaptureMemoryDump and TryGetDumpLocation tests
jamescrosswell Nov 11, 2024
d9b9306
Re-enable CaptureMemoryDump tests
jamescrosswell Nov 11, 2024
13bfe6f
Disable CaptureMemoryDump and enable TryGetDumpLocation
jamescrosswell Nov 11, 2024
d330c2c
Fixed CaptureMemoryDump_CapturesDump
jamescrosswell Nov 11, 2024
8127bb5
Added remarks about dotnet-gcdump dependency to options
jamescrosswell Nov 11, 2024
e628bb3
Merge branch 'version-5.0.0' into auto-heap-dump
bruno-garcia Nov 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .generated.NoMobile.sln
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Hangfire", "src\Sent
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Hangfire.Tests", "test\Sentry.Hangfire.Tests\Sentry.Hangfire.Tests.csproj", "{46E40BE8-1AB0-4846-B0A2-A40AD0272C64}"
EndProject
Project("{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Samples.AspNetCore.WebAPI.Profiling", "samples\Sentry.Samples.AspNetCore.WebAPI.Profiling\Sentry.Samples.AspNetCore.WebAPI.Profiling.csproj", "{A5B26C14-7313-4EDC-91E3-287F9374AB75}"
Project("{00000000-0000-0000-0000-000000000000}") = "Sentry.Samples.AspNetCore.WebAPI.Profiling", "samples\Sentry.Samples.AspNetCore.WebAPI.Profiling\Sentry.Samples.AspNetCore.WebAPI.Profiling.csproj", "{A5B26C14-7313-4EDC-91E3-287F9374AB75}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root", "root", "{233D34AB-970E-4913-AA1E-172E833FB5B2}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -180,6 +180,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root", "root", "{233D34AB-9
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AspNetCore.Blazor.WebAssembly", "src\Sentry.AspNetCore.Blazor.WebAssembly\Sentry.AspNetCore.Blazor.WebAssembly.csproj", "{8298202C-9983-4D0A-851D-805539EE481A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Samples.Console.HeapDump", "samples\Sentry.Samples.Console.HeapDump\Sentry.Samples.Console.HeapDump.csproj", "{D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -276,6 +278,7 @@ Global
{4E0DC405-C372-4396-A5DF-F6AA108DA01C}.Release|Any CPU.Build.0 = Release|Any CPU
{9B175EC8-6B64-4345-A158-091CB8876077}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B175EC8-6B64-4345-A158-091CB8876077}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B175EC8-6B64-4345-A158-091CB8876077}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{9B175EC8-6B64-4345-A158-091CB8876077}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B175EC8-6B64-4345-A158-091CB8876077}.Release|Any CPU.Build.0 = Release|Any CPU
{EE0DC846-52F3-46AF-BC0D-DEF81150CEC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -498,6 +501,10 @@ Global
{A5B26C14-7313-4EDC-91E3-287F9374AB75}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5B26C14-7313-4EDC-91E3-287F9374AB75}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5B26C14-7313-4EDC-91E3-287F9374AB75}.Release|Any CPU.Build.0 = Release|Any CPU
{D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -581,5 +588,6 @@ Global
{46E40BE8-1AB0-4846-B0A2-A40AD0272C64} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D}
{8298202C-9983-4D0A-851D-805539EE481A} = {230B9384-90FD-4551-A5DE-1A5C197F25B6}
{A5B26C14-7313-4EDC-91E3-287F9374AB75} = {21B42F60-5802-404E-90F0-AEBCC56760C0}
{D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821} = {21B42F60-5802-404E-90F0-AEBCC56760C0}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
- `SentryOptions.EnableTracing` has been removed. Instead, tracing should be enabled or disabled by setting the `SentryOptions.TracesSampleRate` or by using `SentryOptions.TracesSampler` to configure a sampling function ([#3569](https://github.com/getsentry/sentry-dotnet/pull/3569))
- The `FailedRequestTargets`, `TagFilters` and `TracePropagationTargets` options have all been changed from `SubstringOrRegexPattern` to `IList<StringOrRegex>` ([#3566](https://github.com/getsentry/sentry-dotnet/pull/3566))
- `Scope.Transaction` is now always stored as an `AsyncLocal` also in [Global Mode](https://docs.sentry.io/platforms/dotnet/configuration/options/#is-global-mode-enabled), to prevent auto-instrumented spans from the UI ending up parented to transactions from a background task (or vice versa). ([#3596](https://github.com/getsentry/sentry-dotnet/pull/3596))
- Heap dumps can be captured automatically when memory usage exceeds a configurable threshold ([#3667](https://github.com/getsentry/sentry-dotnet/pull/3667))

## Unreleased
## Unreleased

### Features
Expand Down
11 changes: 10 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<VersionPrefix>4.12.1</VersionPrefix>
<VersionPrefix>4.12.2</VersionPrefix>
<LangVersion>12</LangVersion>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down Expand Up @@ -74,6 +74,15 @@
<SentryCLIDirectory>$(MSBuildThisFileDirectory)tools\sentry-cli\$(SentryCLIVersion)\</SentryCLIDirectory>
</PropertyGroup>

<!-- dotnet-gcdump needs net6+ and won't work on mobile. -->
<PropertyGroup>
<PlatformIsLegacy Condition="$(TargetFramework.StartsWith('net4')) or $(TargetFramework.StartsWith('netstandard'))">true</PlatformIsLegacy>
<PlatformIsMobile Condition="$(TargetFramework.EndsWith('android')) or $(TargetFramework.EndsWith('ios')) or $(TargetFramework.EndsWith('maccatalyst'))">true</PlatformIsMobile>
<MemoryDumpSupported Condition="!($(PlatformIsLegacy) == 'true' or $(PlatformIsMobile) == 'true')">true</MemoryDumpSupported>

<DefineConstants Condition="'$(MemoryDumpSupported)' == 'true'">$(DefineConstants);MEMORY_DUMP_SUPPORTED</DefineConstants>
</PropertyGroup>

<!-- Public key of .assets/Sentry.snk - not a secret. Used by other InternalsVisibleTo entries throughout the solution. -->
<PropertyGroup>
<SentryPublicKey>002400000480000094000000060200000024000052534131000400000100010059964a931488bcdbd14657f1ee0df32df61b57b3d14d7290c262c2cc9ddaad6ec984044f761f778e1823049d2cb996a4f58c8ea5b46c37891414cb34b4036b1c178d7b582289d2eef3c0f1e9b692c229a306831ee3d371d9e883f0eb0f74aeac6c6ab8c85fd1ec04b267e15a31532c4b4e2191f5980459db4dce0081f1050fb8</SentryPublicKey>
Expand Down
1 change: 1 addition & 0 deletions Sentry-CI-Build-Linux.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"samples\\Sentry.Samples.Azure.Functions.Worker\\Sentry.Samples.Azure.Functions.Worker.csproj",
"samples\\Sentry.Samples.Console.Basic\\Sentry.Samples.Console.Basic.csproj",
"samples\\Sentry.Samples.Console.Customized\\Sentry.Samples.Console.Customized.csproj",
"samples\\Sentry.Samples.Console.HeapDump\\Sentry.Samples.Console.HeapDump.csproj",
"samples\\Sentry.Samples.Console.Metrics\\Sentry.Samples.Console.Metrics.csproj",
"samples\\Sentry.Samples.Console.Native\\Sentry.Samples.Console.Native.csproj",
"samples\\Sentry.Samples.Console.Profiling\\Sentry.Samples.Console.Profiling.csproj",
Expand Down
1 change: 1 addition & 0 deletions Sentry-CI-Build-Windows.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"samples\\Sentry.Samples.Azure.Functions.Worker\\Sentry.Samples.Azure.Functions.Worker.csproj",
"samples\\Sentry.Samples.Console.Basic\\Sentry.Samples.Console.Basic.csproj",
"samples\\Sentry.Samples.Console.Customized\\Sentry.Samples.Console.Customized.csproj",
"samples\\Sentry.Samples.Console.HeapDump\\Sentry.Samples.Console.HeapDump.csproj",
"samples\\Sentry.Samples.Console.Metrics\\Sentry.Samples.Console.Metrics.csproj",
"samples\\Sentry.Samples.Console.Native\\Sentry.Samples.Console.Native.csproj",
"samples\\Sentry.Samples.Console.Profiling\\Sentry.Samples.Console.Profiling.csproj",
Expand Down
1 change: 1 addition & 0 deletions Sentry-CI-Build-macOS.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"samples\\Sentry.Samples.Azure.Functions.Worker\\Sentry.Samples.Azure.Functions.Worker.csproj",
"samples\\Sentry.Samples.Console.Basic\\Sentry.Samples.Console.Basic.csproj",
"samples\\Sentry.Samples.Console.Customized\\Sentry.Samples.Console.Customized.csproj",
"samples\\Sentry.Samples.Console.HeapDump\\Sentry.Samples.Console.HeapDump.csproj",
"samples\\Sentry.Samples.Console.Metrics\\Sentry.Samples.Console.Metrics.csproj",
"samples\\Sentry.Samples.Console.Native\\Sentry.Samples.Console.Native.csproj",
"samples\\Sentry.Samples.Console.Profiling\\Sentry.Samples.Console.Profiling.csproj",
Expand Down
9 changes: 8 additions & 1 deletion Sentry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Hangfire", "src\Sent
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Hangfire.Tests", "test\Sentry.Hangfire.Tests\Sentry.Hangfire.Tests.csproj", "{46E40BE8-1AB0-4846-B0A2-A40AD0272C64}"
EndProject
Project("{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Samples.AspNetCore.WebAPI.Profiling", "samples\Sentry.Samples.AspNetCore.WebAPI.Profiling\Sentry.Samples.AspNetCore.WebAPI.Profiling.csproj", "{A5B26C14-7313-4EDC-91E3-287F9374AB75}"
Project("{00000000-0000-0000-0000-000000000000}") = "Sentry.Samples.AspNetCore.WebAPI.Profiling", "samples\Sentry.Samples.AspNetCore.WebAPI.Profiling\Sentry.Samples.AspNetCore.WebAPI.Profiling.csproj", "{A5B26C14-7313-4EDC-91E3-287F9374AB75}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root", "root", "{233D34AB-970E-4913-AA1E-172E833FB5B2}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -180,6 +180,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root", "root", "{233D34AB-9
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AspNetCore.Blazor.WebAssembly", "src\Sentry.AspNetCore.Blazor.WebAssembly\Sentry.AspNetCore.Blazor.WebAssembly.csproj", "{8298202C-9983-4D0A-851D-805539EE481A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Samples.Console.HeapDump", "samples\Sentry.Samples.Console.HeapDump\Sentry.Samples.Console.HeapDump.csproj", "{D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -499,6 +501,10 @@ Global
{A5B26C14-7313-4EDC-91E3-287F9374AB75}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5B26C14-7313-4EDC-91E3-287F9374AB75}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5B26C14-7313-4EDC-91E3-287F9374AB75}.Release|Any CPU.Build.0 = Release|Any CPU
{D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -582,5 +588,6 @@ Global
{46E40BE8-1AB0-4846-B0A2-A40AD0272C64} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D}
{8298202C-9983-4D0A-851D-805539EE481A} = {230B9384-90FD-4551-A5DE-1A5C197F25B6}
{A5B26C14-7313-4EDC-91E3-287F9374AB75} = {21B42F60-5802-404E-90F0-AEBCC56760C0}
{D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821} = {21B42F60-5802-404E-90F0-AEBCC56760C0}
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions Sentry.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=OS/@EntryIndexedValue">OS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=QL/@EntryIndexedValue">QL</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=UI/@EntryIndexedValue">UI</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=debouncer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Enricher/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=enrichers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=instrumenter/@EntryIndexedValue">True</s:Boolean>
Expand Down
1 change: 1 addition & 0 deletions SentryNoMobile.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"samples\\Sentry.Samples.Azure.Functions.Worker\\Sentry.Samples.Azure.Functions.Worker.csproj",
"samples\\Sentry.Samples.Console.Basic\\Sentry.Samples.Console.Basic.csproj",
"samples\\Sentry.Samples.Console.Customized\\Sentry.Samples.Console.Customized.csproj",
"samples\\Sentry.Samples.Console.HeapDump\\Sentry.Samples.Console.HeapDump.csproj",
"samples\\Sentry.Samples.Console.Metrics\\Sentry.Samples.Console.Metrics.csproj",
"samples\\Sentry.Samples.Console.Native\\Sentry.Samples.Console.Native.csproj",
"samples\\Sentry.Samples.Console.Profiling\\Sentry.Samples.Console.Profiling.csproj",
Expand Down
6 changes: 3 additions & 3 deletions samples/Sentry.Samples.Console.Basic/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
* For more advanced features of the SDK, see Sentry.Samples.Console.Customized.
*/

// Initialize the Sentry SDK. (It is not necessary to dispose it.)

using System.Net.Http;
using static System.Console;

// 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.
Expand Down Expand Up @@ -55,7 +55,7 @@ async Task FirstFunction()
var messageHandler = new SentryHttpMessageHandler();
var httpClient = new HttpClient(messageHandler, true);
var html = await httpClient.GetStringAsync("https://example.com/");
Console.WriteLine(html);
WriteLine(html);
}

async Task SecondFunction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TargetFrameworks>net8.0;net6.0;net462</TargetFrameworks>
<TargetFrameworks>net8.0;net462</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith('net8'))">
<PublishAot>true</PublishAot>
Expand Down
72 changes: 72 additions & 0 deletions samples/Sentry.Samples.Console.HeapDump/Program.cs
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://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/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];
bruno-garcia marked this conversation as resolved.
Show resolved Hide resolved
array.Initialize();
memoryHog.Add(array);
}

GC.KeepAlive(memoryHog);
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>&#45;&#45;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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"configProperties": {
"System.GC.ConserveMemory": 9,
"System.GC.HighMemoryPercent": 20
}
}
3 changes: 3 additions & 0 deletions src/Sentry/BindableSentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ internal partial class BindableSentryOptions
public bool? JsonPreserveReferences { get; set; }
public bool? EnableSpotlight { get; set; }
public string? SpotlightUrl { get; set; }
#if MEMORY_DUMP_SUPPORTED
public SentryLevel? HeapDumpEventLevel { get; set; }
#endif

public void ApplyTo(SentryOptions options)
{
Expand Down
Loading
Loading