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

Add UseAsyncFileIO option #1564

Merged
merged 2 commits into from
Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 17 additions & 2 deletions src/Sentry/FileAttachmentContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,26 @@ namespace Sentry
public class FileAttachmentContent : IAttachmentContent
{
private readonly string _filePath;
private readonly bool _readFileAsynchronously;

/// <summary>
/// Creates a new instance of <see cref="FileAttachmentContent"/>.
/// </summary>
public FileAttachmentContent(string filePath) => _filePath = filePath;
/// <param name="filePath">The path to the file to attach.</param>
public FileAttachmentContent(string filePath) : this(filePath, true)
{
}

/// <summary>
/// Creates a new instance of <see cref="FileAttachmentContent"/>.
/// </summary>
/// <param name="filePath">The path to the file to attach.</param>
/// <param name="readFileAsynchronously">Whether to use async file I/O to read the file.</param>
public FileAttachmentContent(string filePath, bool readFileAsynchronously)
{
_filePath = filePath;
_readFileAsynchronously = readFileAsynchronously;
}

/// <inheritdoc />
public Stream GetStream() => new FileStream(
Expand All @@ -21,6 +36,6 @@ public class FileAttachmentContent : IAttachmentContent
FileAccess.Read,
FileShare.ReadWrite,
bufferSize: 4096,
useAsync: true);
useAsync: _readFileAsynchronously);
}
}
2 changes: 1 addition & 1 deletion src/Sentry/ScopeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
9 changes: 9 additions & 0 deletions src/Sentry/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,15 @@ public StackTraceMode StackTraceMode
/// </remarks>
public bool AutoSessionTracking { get; set; } = false;

/// <summary>
/// Whether the SDK should attempt to use asynchronous file I/O.
/// For example, when reading a file to use as an attachment.
/// </summary>
/// <remarks>
/// This option should rarely be disabled, but is necessary in some environments such as Unity WebGL.
/// </remarks>
public bool UseAsyncFileIO { get; set; } = true;

/// <summary>
/// Delegate which is used to check whether the application crashed during last run.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -497,6 +498,7 @@ namespace Sentry
public Sentry.StackTraceMode StackTraceMode { get; set; }
public double TracesSampleRate { get; set; }
public System.Func<Sentry.TransactionSamplingContext, double?>? TracesSampler { get; set; }
public bool UseAsyncFileIO { get; set; }
}
public static class SentryOptionsExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -497,6 +498,7 @@ namespace Sentry
public Sentry.StackTraceMode StackTraceMode { get; set; }
public double TracesSampleRate { get; set; }
public System.Func<Sentry.TransactionSamplingContext, double?>? TracesSampler { get; set; }
public bool UseAsyncFileIO { get; set; }
}
public static class SentryOptionsExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -497,6 +498,7 @@ namespace Sentry
public Sentry.StackTraceMode StackTraceMode { get; set; }
public double TracesSampleRate { get; set; }
public System.Func<Sentry.TransactionSamplingContext, double?>? TracesSampler { get; set; }
public bool UseAsyncFileIO { get; set; }
}
public static class SentryOptionsExtensions
{
Expand Down
2 changes: 2 additions & 0 deletions test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -497,6 +498,7 @@ namespace Sentry
public Sentry.StackTraceMode StackTraceMode { get; set; }
public double TracesSampleRate { get; set; }
public System.Func<Sentry.TransactionSamplingContext, double?>? TracesSampler { get; set; }
public bool UseAsyncFileIO { get; set; }
}
public static class SentryOptionsExtensions
{
Expand Down
2 changes: 2 additions & 0 deletions test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -497,6 +498,7 @@ namespace Sentry
public Sentry.StackTraceMode StackTraceMode { get; set; }
public double TracesSampleRate { get; set; }
public System.Func<Sentry.TransactionSamplingContext, double?>? TracesSampler { get; set; }
public bool UseAsyncFileIO { get; set; }
}
public static class SentryOptionsExtensions
{
Expand Down
2 changes: 2 additions & 0 deletions test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -497,6 +498,7 @@ namespace Sentry
public Sentry.StackTraceMode StackTraceMode { get; set; }
public double TracesSampleRate { get; set; }
public System.Func<Sentry.TransactionSamplingContext, double?>? TracesSampler { get; set; }
public bool UseAsyncFileIO { get; set; }
}
public static class SentryOptionsExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -496,6 +497,7 @@ namespace Sentry
public Sentry.StackTraceMode StackTraceMode { get; set; }
public double TracesSampleRate { get; set; }
public System.Func<Sentry.TransactionSamplingContext, double?>? TracesSampler { get; set; }
public bool UseAsyncFileIO { get; set; }
}
public static class SentryOptionsExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -497,6 +498,7 @@ namespace Sentry
public Sentry.StackTraceMode StackTraceMode { get; set; }
public double TracesSampleRate { get; set; }
public System.Func<Sentry.TransactionSamplingContext, double?>? TracesSampler { get; set; }
public bool UseAsyncFileIO { get; set; }
}
public static class SentryOptionsExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -497,6 +498,7 @@ namespace Sentry
public Sentry.StackTraceMode StackTraceMode { get; set; }
public double TracesSampleRate { get; set; }
public System.Func<Sentry.TransactionSamplingContext, double?>? TracesSampler { get; set; }
public bool UseAsyncFileIO { get; set; }
}
public static class SentryOptionsExtensions
{
Expand Down