Skip to content

Commit ed0fd8a

Browse files
Marked AutoHeapDump functionality as experimental
1 parent 90d41ed commit ed0fd8a

File tree

10 files changed

+58
-8
lines changed

10 files changed

+58
-8
lines changed

Directory.Build.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<Features>strict</Features>
1212
<ImplicitUsings>true</ImplicitUsings>
1313

14+
<!-- Ignore our own diagnostic ids - these are meant to be external warnings only -->
15+
<NoWarn>$(NoWarn);SENTRY0001</NoWarn>
16+
1417
<!-- Allow references to unsigned assemblies (like MAUI) from signed projects -->
1518
<NoWarn>$(NoWarn);CS8002</NoWarn>
1619

src/Sentry/Debouncer.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
using Sentry.Infrastructure;
2+
13
namespace Sentry;
24

5+
#if MEMORY_DUMP_SUPPORTED
6+
37
/// <summary>
48
/// A debouncer that can be used to limit the number of occurrences of an event within a given interval and optionally,
59
/// enforce a minimum cooldown period between events.
610
/// </summary>
11+
[Experimental(DiagnosticId.ExperimentalFeature)]
712
public class Debouncer
813
{
914
internal enum DebouncerInterval { Minute, Hour, Day, ApplicationLifetime }
@@ -101,3 +106,5 @@ internal bool CanProcess(DateTimeOffset? timestamp = null)
101106
return _cooldown is not { } cooldown || _lastEvent + cooldown <= eventTime;
102107
}
103108
}
109+
110+
#endif

src/Sentry/HeapDumpTriggers.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
using Sentry.Infrastructure;
2+
13
namespace Sentry;
24

5+
#if MEMORY_DUMP_SUPPORTED
6+
37
/// <summary>
48
/// Delegate that determines whether a heap dump should be triggered or not.
59
/// </summary>
610
/// <param name="usedMemory">Memory currently used by the process</param>
711
/// <param name="totalMemory">Total available memory</param>
812
/// <returns><see langword="true"/> if the heap dump should be triggered; otherwise, <see langword="false"/>.</returns>
13+
[Experimental(DiagnosticId.ExperimentalFeature)]
914
public delegate bool HeapDumpTrigger(long usedMemory, long totalMemory);
1015

1116
internal static class HeapDumpTriggers
@@ -25,3 +30,5 @@ internal static HeapDumpTrigger MemoryPercentageThreshold(int memoryPercentageTh
2530
};
2631
}
2732
}
33+
34+
#endif
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Sentry.Infrastructure;
2+
3+
internal static class DiagnosticId
4+
{
5+
#if NET5_0_OR_GREATER
6+
/// <summary>
7+
/// Indicates that the feature is experimental and may be subject to change or removal in future versions.
8+
/// </summary>
9+
internal const string ExperimentalFeature = "SENTRY0001";
10+
#endif
11+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
namespace Sentry.Internal;
22

3+
#if MEMORY_DUMP_SUPPORTED
4+
35
internal record HeapDumpOptions(HeapDumpTrigger Trigger, Debouncer Debouncer, SentryLevel Level);
6+
7+
#endif

src/Sentry/SentryOptions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,18 @@ public int MaxQueueItems
525525
#if MEMORY_DUMP_SUPPORTED
526526

527527
/// <summary>
528+
/// <para>
528529
/// Configures a heap dump to be captured if the percentage of memory used exceeds a certain threshold.
529530
/// This can be useful to diagnose memory leaks.
531+
/// </para>
532+
/// <para>
533+
/// Note: This feature requires `dotnet-gcdump` to be installed globally on the machine or container where the heap
534+
/// dumps will be captured. You can install this by running: `dotnet tool install --global dotnet-gcdump`
535+
/// </para>
530536
/// </summary>
537+
/// <remarks>
538+
/// This API is experimental and may change in future versions.
539+
/// </remarks>
531540
/// <param name="memoryPercentageThreshold">
532541
/// The memory threshold at which to trigger a heap dump, as a percentage of total available memory.
533542
/// Must be a number between 1 and 99.
@@ -538,6 +547,7 @@ public int MaxQueueItems
538547
/// </param>
539548
/// <param name="level">Optional parameter controlling the event level associated with heap dumps.
540549
/// Defaults to <see cref="SentryLevel.Warning"/>.</param>
550+
[Experimental(DiagnosticId.ExperimentalFeature)]
541551
public void EnableHeapDumps(short memoryPercentageThreshold, Debouncer? debouncer = null, SentryLevel level = SentryLevel.Warning)
542552
=> EnableHeapDumps(HeapDumpTriggers.MemoryPercentageThreshold(memoryPercentageThreshold), debouncer, level);
543553

@@ -550,6 +560,9 @@ public void EnableHeapDumps(short memoryPercentageThreshold, Debouncer? debounce
550560
/// dumps will be captured. You can install this by running: `dotnet tool install --global dotnet-gcdump`
551561
/// </para>
552562
/// </summary>
563+
/// <remarks>
564+
/// This API is experimental and may change in future versions.
565+
/// </remarks>
553566
/// <param name="trigger">
554567
/// A custom trigger function that accepts the current memory usage and total available memory as arguments and
555568
/// return true to indicate that a heap dump should be captured or false otherwise.
@@ -560,6 +573,7 @@ public void EnableHeapDumps(short memoryPercentageThreshold, Debouncer? debounce
560573
/// </param>
561574
/// <param name="level">Optional parameter controlling the event level associated with heap dumps.
562575
/// Defaults to <see cref="SentryLevel.Warning"/>.</param>
576+
[Experimental(DiagnosticId.ExperimentalFeature)]
563577
public void EnableHeapDumps(HeapDumpTrigger trigger, Debouncer? debouncer = null, SentryLevel level = SentryLevel.Warning)
564578
=> HeapDumpOptions = new HeapDumpOptions(trigger, debouncer ?? Debouncer.PerApplicationLifetime(), level);
565579

test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ namespace Sentry
7575
ManagedBackgroundThread = 1,
7676
Native = 2,
7777
}
78+
[System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")]
7879
public class Debouncer
7980
{
8081
public static Sentry.Debouncer PerApplicationLifetime(int eventMaximum = 1, System.TimeSpan? cooldown = default) { }
@@ -132,6 +133,7 @@ namespace Sentry
132133
{
133134
public static void SetTags(this Sentry.IHasTags hasTags, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string>> tags) { }
134135
}
136+
[System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")]
135137
public delegate bool HeapDumpTrigger(long usedMemory, long totalMemory);
136138
public static class HintTypes
137139
{
@@ -730,7 +732,9 @@ namespace Sentry
730732
public void DisableSystemDiagnosticsMetricsIntegration() { }
731733
public void DisableUnobservedTaskExceptionCapture() { }
732734
public void DisableWinUiUnhandledExceptionIntegration() { }
735+
[System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")]
733736
public void EnableHeapDumps(Sentry.HeapDumpTrigger trigger, Sentry.Debouncer? debouncer = null, Sentry.SentryLevel level = 2) { }
737+
[System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")]
734738
public void EnableHeapDumps(short memoryPercentageThreshold, Sentry.Debouncer? debouncer = null, Sentry.SentryLevel level = 2) { }
735739
public System.Collections.Generic.IEnumerable<Sentry.Extensibility.ISentryEventProcessor> GetAllEventProcessors() { }
736740
public System.Collections.Generic.IEnumerable<Sentry.Extensibility.ISentryEventExceptionProcessor> GetAllExceptionProcessors() { }

test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ namespace Sentry
7575
ManagedBackgroundThread = 1,
7676
Native = 2,
7777
}
78+
[System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")]
7879
public class Debouncer
7980
{
8081
public static Sentry.Debouncer PerApplicationLifetime(int eventMaximum = 1, System.TimeSpan? cooldown = default) { }
@@ -132,6 +133,7 @@ namespace Sentry
132133
{
133134
public static void SetTags(this Sentry.IHasTags hasTags, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string>> tags) { }
134135
}
136+
[System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")]
135137
public delegate bool HeapDumpTrigger(long usedMemory, long totalMemory);
136138
public static class HintTypes
137139
{
@@ -730,7 +732,9 @@ namespace Sentry
730732
public void DisableSystemDiagnosticsMetricsIntegration() { }
731733
public void DisableUnobservedTaskExceptionCapture() { }
732734
public void DisableWinUiUnhandledExceptionIntegration() { }
735+
[System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")]
733736
public void EnableHeapDumps(Sentry.HeapDumpTrigger trigger, Sentry.Debouncer? debouncer = null, Sentry.SentryLevel level = 2) { }
737+
[System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")]
734738
public void EnableHeapDumps(short memoryPercentageThreshold, Sentry.Debouncer? debouncer = null, Sentry.SentryLevel level = 2) { }
735739
public System.Collections.Generic.IEnumerable<Sentry.Extensibility.ISentryEventProcessor> GetAllEventProcessors() { }
736740
public System.Collections.Generic.IEnumerable<Sentry.Extensibility.ISentryEventExceptionProcessor> GetAllExceptionProcessors() { }

test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@ namespace Sentry
7474
Managed = 0,
7575
ManagedBackgroundThread = 1,
7676
}
77-
public class Debouncer
78-
{
79-
public static Sentry.Debouncer PerApplicationLifetime(int eventMaximum = 1, System.TimeSpan? cooldown = default) { }
80-
public static Sentry.Debouncer PerDay(int eventMaximum = 1, System.TimeSpan? cooldown = default) { }
81-
public static Sentry.Debouncer PerHour(int eventMaximum = 1, System.TimeSpan? cooldown = default) { }
82-
public static Sentry.Debouncer PerMinute(int eventMaximum = 1, System.TimeSpan? cooldown = default) { }
83-
}
8477
[System.Flags]
8578
public enum DeduplicateMode
8679
{
@@ -130,7 +123,6 @@ namespace Sentry
130123
{
131124
public static void SetTags(this Sentry.IHasTags hasTags, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string>> tags) { }
132125
}
133-
public delegate bool HeapDumpTrigger(long usedMemory, long totalMemory);
134126
public static class HintTypes
135127
{
136128
public const string HttpResponseMessage = "http-response-message";

test/Sentry.Tests/DebouncerTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
namespace Sentry.Tests;
22

3+
#if MEMORY_DUMP_SUPPORTED
4+
35
public class DebouncerTests
46
{
57
[Fact]
@@ -142,3 +144,5 @@ public void RecordOccurence_AfterInterval_ResetsInterval()
142144
debouncer._lastEvent.Should().Be(secondEventTime);
143145
}
144146
}
147+
148+
#endif

0 commit comments

Comments
 (0)