diff --git a/src/Sentry/Internal/MemoryMonitor.cs b/src/Sentry/Internal/MemoryMonitor.cs index 03813a5268..a32ae66edb 100644 --- a/src/Sentry/Internal/MemoryMonitor.cs +++ b/src/Sentry/Internal/MemoryMonitor.cs @@ -100,7 +100,37 @@ internal void CaptureMemoryDump(Action dumpProcessRunner) return; } + + const long maxDumpSizeInBytes = 20 * 1024 * 1024; + + var fileInfo = new FileInfo(dumpFile); + if (fileInfo.Length > maxDumpSizeInBytes) + { + _options.LogWarning($"Memory dump file is too large ({fileInfo.Length} bytes). and will not be attached to the Sentry event."); + + try + { + File.Delete(dumpFile); + } + catch (Exception ex) + { + _options.LogError($"Error deleting memory dump file: {ex.Message}"); + } + + return; + } + + _onDumpCollected(dumpFile); + + try + { + File.Delete(dumpFile); + } + catch (Exception ex) + { + _options.LogError($"Error deleting memory dump file after sending to Sentry: {ex.Message}"); + } } /// diff --git a/src/Sentry/SentryClient.cs b/src/Sentry/SentryClient.cs index 7aef9aa8b5..ab793c7aad 100644 --- a/src/Sentry/SentryClient.cs +++ b/src/Sentry/SentryClient.cs @@ -15,6 +15,7 @@ namespace Sentry; /// public class SentryClient : ISentryClient, IDisposable { + private readonly ITransport _transport; private readonly SentryOptions _options; private readonly ISessionManager _sessionManager; private readonly RandomValuesFactory _randomValuesFactory; @@ -84,6 +85,16 @@ public SentryId CaptureEvent(SentryEvent? @event, Scope? scope = null, SentryHin /// public void CaptureFeedback(SentryFeedback feedback, Scope? scope = null, SentryHint? hint = null) { + + var processedFeedback = _options?.BeforeSendFeedbackInternal?.Invoke(feedback, hint); + if (processedFeedback is null) + { + _options?.DiagnosticLogger?.LogDebug("BeforeSendFeedback returned null, dropping feedback."); + return; + } + + _transport.EnqueueFeedback(processedFeedback, hint); + if (string.IsNullOrEmpty(feedback.Message)) { _options.LogWarning("Feedback dropped due to empty message."); diff --git a/src/Sentry/SentryOptions.cs b/src/Sentry/SentryOptions.cs index a1c056acdc..0f0a8b5eab 100644 --- a/src/Sentry/SentryOptions.cs +++ b/src/Sentry/SentryOptions.cs @@ -442,6 +442,26 @@ internal bool IsSentryRequest(Uri? requestUri) internal Func? BeforeSendInternal => _beforeSend; + private Func? _beforeSendFeedback; + internal Func? BeforeSendFeedbackInternal => _beforeSendFeedback; + + + /// + /// Configures a callback to invoke before sending feedback to Sentry. + /// + public void SetBeforeSendFeedback(Func beforeSendFeedback) + { + _beforeSendFeedback = beforeSendFeedback; + } + + /// + /// Configures a callback to invoke before sending feedback to Sentry. + /// + public void SetBeforeSendFeedback(Func beforeSendFeedback) + { + _beforeSendFeedback = (feedback, _) => beforeSendFeedback(feedback); + } + /// /// Configures a callback function to be invoked before sending an event to Sentry ///