diff --git a/CHANGELOG.md b/CHANGELOG.md index 651ad6aea0..bde86c6d92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Use a default value of 60 seconds if a `Retry-After` header is not present. ([#1537](https://github.com/getsentry/sentry-dotnet/pull/1537)) - Add new Protocol definitions for DebugImages and AddressMode ([#1513](https://github.com/getsentry/sentry-dotnet/pull/1513)) - Add `HttpTransport` extensibility and synchronous serialization support ([#1560](https://github.com/getsentry/sentry-dotnet/pull/1560)) +- Add `UseAsyncFileIO` to Sentry options (enabled by default) ([#1564](https://github.com/getsentry/sentry-dotnet/pull/1564)) ### Fixes diff --git a/src/Sentry/FileAttachmentContent.cs b/src/Sentry/FileAttachmentContent.cs index 2c9fba32bb..157ddc1a3d 100644 --- a/src/Sentry/FileAttachmentContent.cs +++ b/src/Sentry/FileAttachmentContent.cs @@ -8,11 +8,26 @@ namespace Sentry public class FileAttachmentContent : IAttachmentContent { private readonly string _filePath; + private readonly bool _readFileAsynchronously; /// /// Creates a new instance of . /// - public FileAttachmentContent(string filePath) => _filePath = filePath; + /// The path to the file to attach. + public FileAttachmentContent(string filePath) : this(filePath, true) + { + } + + /// + /// Creates a new instance of . + /// + /// The path to the file to attach. + /// Whether to use async file I/O to read the file. + public FileAttachmentContent(string filePath, bool readFileAsynchronously) + { + _filePath = filePath; + _readFileAsynchronously = readFileAsynchronously; + } /// public Stream GetStream() => new FileStream( @@ -21,6 +36,6 @@ public class FileAttachmentContent : IAttachmentContent FileAccess.Read, FileShare.ReadWrite, bufferSize: 4096, - useAsync: true); + useAsync: _readFileAsynchronously); } } diff --git a/src/Sentry/ScopeExtensions.cs b/src/Sentry/ScopeExtensions.cs index e99e4b0ce1..d49a15caee 100644 --- a/src/Sentry/ScopeExtensions.cs +++ b/src/Sentry/ScopeExtensions.cs @@ -159,7 +159,7 @@ public static void AddAttachment( scope.AddAttachment( new Attachment( type, - new FileAttachmentContent(filePath), + new FileAttachmentContent(filePath, scope.Options.UseAsyncFileIO), Path.GetFileName(filePath), contentType)); diff --git a/src/Sentry/SentryOptions.cs b/src/Sentry/SentryOptions.cs index a6f4d63ef7..45144f2b67 100644 --- a/src/Sentry/SentryOptions.cs +++ b/src/Sentry/SentryOptions.cs @@ -564,6 +564,15 @@ public StackTraceMode StackTraceMode /// public bool AutoSessionTracking { get; set; } = false; + /// + /// Whether the SDK should attempt to use asynchronous file I/O. + /// For example, when reading a file to use as an attachment. + /// + /// + /// This option should rarely be disabled, but is necessary in some environments such as Unity WebGL. + /// + public bool UseAsyncFileIO { get; set; } = true; + /// /// Delegate which is used to check whether the application crashed during last run. /// diff --git a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.Core3_1.verified.txt b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.Core3_1.verified.txt index 59cc4444a1..93b767227c 100644 --- a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.Core3_1.verified.txt +++ b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.Core3_1.verified.txt @@ -112,6 +112,7 @@ namespace Sentry public class FileAttachmentContent : Sentry.IAttachmentContent { public FileAttachmentContent(string filePath) { } + public FileAttachmentContent(string filePath, bool readFileAsynchronously) { } public System.IO.Stream GetStream() { } } public static class HasBreadcrumbsExtensions @@ -497,6 +498,7 @@ namespace Sentry public Sentry.StackTraceMode StackTraceMode { get; set; } public double TracesSampleRate { get; set; } public System.Func? TracesSampler { get; set; } + public bool UseAsyncFileIO { get; set; } } public static class SentryOptionsExtensions { diff --git a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt index ecd4dca74a..76bfd2921e 100644 --- a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt +++ b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt @@ -112,6 +112,7 @@ namespace Sentry public class FileAttachmentContent : Sentry.IAttachmentContent { public FileAttachmentContent(string filePath) { } + public FileAttachmentContent(string filePath, bool readFileAsynchronously) { } public System.IO.Stream GetStream() { } } public static class HasBreadcrumbsExtensions @@ -497,6 +498,7 @@ namespace Sentry public Sentry.StackTraceMode StackTraceMode { get; set; } public double TracesSampleRate { get; set; } public System.Func? TracesSampler { get; set; } + public bool UseAsyncFileIO { get; set; } } public static class SentryOptionsExtensions { diff --git a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt index 2327269c45..1bb34f5450 100644 --- a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt +++ b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt @@ -112,6 +112,7 @@ namespace Sentry public class FileAttachmentContent : Sentry.IAttachmentContent { public FileAttachmentContent(string filePath) { } + public FileAttachmentContent(string filePath, bool readFileAsynchronously) { } public System.IO.Stream GetStream() { } } public static class HasBreadcrumbsExtensions @@ -497,6 +498,7 @@ namespace Sentry public Sentry.StackTraceMode StackTraceMode { get; set; } public double TracesSampleRate { get; set; } public System.Func? TracesSampler { get; set; } + public bool UseAsyncFileIO { get; set; } } public static class SentryOptionsExtensions { diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt index ea672dbffc..abe61dffc8 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt @@ -112,6 +112,7 @@ namespace Sentry public class FileAttachmentContent : Sentry.IAttachmentContent { public FileAttachmentContent(string filePath) { } + public FileAttachmentContent(string filePath, bool readFileAsynchronously) { } public System.IO.Stream GetStream() { } } public static class HasBreadcrumbsExtensions @@ -497,6 +498,7 @@ namespace Sentry public Sentry.StackTraceMode StackTraceMode { get; set; } public double TracesSampleRate { get; set; } public System.Func? TracesSampler { get; set; } + public bool UseAsyncFileIO { get; set; } } public static class SentryOptionsExtensions { diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt index d852d89787..5136f07aa9 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt @@ -112,6 +112,7 @@ namespace Sentry public class FileAttachmentContent : Sentry.IAttachmentContent { public FileAttachmentContent(string filePath) { } + public FileAttachmentContent(string filePath, bool readFileAsynchronously) { } public System.IO.Stream GetStream() { } } public static class HasBreadcrumbsExtensions @@ -497,6 +498,7 @@ namespace Sentry public Sentry.StackTraceMode StackTraceMode { get; set; } public double TracesSampleRate { get; set; } public System.Func? TracesSampler { get; set; } + public bool UseAsyncFileIO { get; set; } } public static class SentryOptionsExtensions { diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt index 59cc4444a1..93b767227c 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt @@ -112,6 +112,7 @@ namespace Sentry public class FileAttachmentContent : Sentry.IAttachmentContent { public FileAttachmentContent(string filePath) { } + public FileAttachmentContent(string filePath, bool readFileAsynchronously) { } public System.IO.Stream GetStream() { } } public static class HasBreadcrumbsExtensions @@ -497,6 +498,7 @@ namespace Sentry public Sentry.StackTraceMode StackTraceMode { get; set; } public double TracesSampleRate { get; set; } public System.Func? TracesSampler { get; set; } + public bool UseAsyncFileIO { get; set; } } public static class SentryOptionsExtensions { diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt index ee3364a321..5bb1bc77f1 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt @@ -112,6 +112,7 @@ namespace Sentry public class FileAttachmentContent : Sentry.IAttachmentContent { public FileAttachmentContent(string filePath) { } + public FileAttachmentContent(string filePath, bool readFileAsynchronously) { } public System.IO.Stream GetStream() { } } public static class HasBreadcrumbsExtensions @@ -496,6 +497,7 @@ namespace Sentry public Sentry.StackTraceMode StackTraceMode { get; set; } public double TracesSampleRate { get; set; } public System.Func? TracesSampler { get; set; } + public bool UseAsyncFileIO { get; set; } } public static class SentryOptionsExtensions { diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt index ecd4dca74a..76bfd2921e 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt @@ -112,6 +112,7 @@ namespace Sentry public class FileAttachmentContent : Sentry.IAttachmentContent { public FileAttachmentContent(string filePath) { } + public FileAttachmentContent(string filePath, bool readFileAsynchronously) { } public System.IO.Stream GetStream() { } } public static class HasBreadcrumbsExtensions @@ -497,6 +498,7 @@ namespace Sentry public Sentry.StackTraceMode StackTraceMode { get; set; } public double TracesSampleRate { get; set; } public System.Func? TracesSampler { get; set; } + public bool UseAsyncFileIO { get; set; } } public static class SentryOptionsExtensions { diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt index 2327269c45..1bb34f5450 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt @@ -112,6 +112,7 @@ namespace Sentry public class FileAttachmentContent : Sentry.IAttachmentContent { public FileAttachmentContent(string filePath) { } + public FileAttachmentContent(string filePath, bool readFileAsynchronously) { } public System.IO.Stream GetStream() { } } public static class HasBreadcrumbsExtensions @@ -497,6 +498,7 @@ namespace Sentry public Sentry.StackTraceMode StackTraceMode { get; set; } public double TracesSampleRate { get; set; } public System.Func? TracesSampler { get; set; } + public bool UseAsyncFileIO { get; set; } } public static class SentryOptionsExtensions {