diff --git a/CHANGELOG.md b/CHANGELOG.md index c160d133a7..123a822051 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Features +- Android - allow logcat attachments to be previewed in Sentry ([#3711](https://github.com/getsentry/sentry-dotnet/pull/3711)) - Added a `SetBeforeScreenshotCapture` callback to the options: allowing the user to set an action before the screenshot is taken ([#3661](https://github.com/getsentry/sentry-dotnet/pull/3661)) - Make `Sentry.AspNetCore.Blazor.WebAssembly` generally available. ([#3674](https://github.com/getsentry/sentry-dotnet/pull/3674)) diff --git a/src/Sentry/Platforms/Android/LogCatAttachmentEventProcessor.cs b/src/Sentry/Platforms/Android/LogCatAttachmentEventProcessor.cs index 6730d6fb88..6c2e1fdf5f 100644 --- a/src/Sentry/Platforms/Android/LogCatAttachmentEventProcessor.cs +++ b/src/Sentry/Platforms/Android/LogCatAttachmentEventProcessor.cs @@ -81,7 +81,7 @@ public SentryEvent Process(SentryEvent @event, SentryHint hint) output.Seek(0, SeekOrigin.Begin); var bytes = output.ToArray(); - hint.Attachments.Add(new SentryAttachment(AttachmentType.Default, new ByteAttachmentContent(bytes), "logcat.log", "text/logcat")); + hint.Attachments.Add(new SentryAttachment(AttachmentType.Default, new ByteAttachmentContent(bytes), "logcat.log", "text/plain")); //hint.AddAttachment($"{filesDir.Path}/{fileName}", AttachmentType.Default, "text/logcat"); diff --git a/test/Sentry.Maui.Tests/SentryMauiLogcatsTests.cs b/test/Sentry.Maui.Tests/SentryMauiLogcatsTests.cs new file mode 100644 index 0000000000..e590e687a9 --- /dev/null +++ b/test/Sentry.Maui.Tests/SentryMauiLogcatsTests.cs @@ -0,0 +1,67 @@ +using Microsoft.Extensions.Options; +#if ANDROID +using Sentry.Android; +#endif + +namespace Sentry.Maui.Tests; + +public class SentryMauiLogcatsTests +{ + private class Fixture + { + public MauiAppBuilder Builder { get; } + public FakeTransport Transport { get; private set; } = new FakeTransport(); + public InMemoryDiagnosticLogger Logger { get; private set; } = new InMemoryDiagnosticLogger(); + + public Fixture() + { + var builder = MauiApp.CreateBuilder(); + builder.Services.AddSingleton(Substitute.For()); + + builder.Services.Configure(options => + { + options.Transport = Transport; + options.Dsn = ValidDsn; + options.AttachScreenshot = false; //Disable the screenshot attachment to have the logcat as primary attachment + options.Debug = true; + options.DiagnosticLogger = Logger; + options.AutoSessionTracking = false; //Get rid of session envelope for easier Assert + options.CacheDirectoryPath = null; //Do not wrap our FakeTransport with a caching transport + options.FlushTimeout = TimeSpan.FromSeconds(10); + }); + Builder = builder; + } + } + + private readonly Fixture _fixture = new(); + +#if ANDROID + [Fact] + public void CaptureException_CheckLogcatType() + { + var builder = _fixture.Builder.UseSentry(options => + { + options.Android.LogCatIntegration = Android.LogCatIntegrationType.All; + }); + + // Arrange + var processor = Substitute.For(); + using var app = builder.Build(); + SentryHint hint = null; + var options = app.Services.GetRequiredService>().Value; + + var scope = new Scope(options); + + // Act + processor.Process(Arg.Any(), Arg.Do(h => hint = h)).Returns(new SentryEvent()); + options.AddEventProcessor(processor); + + _ = new SentryClient(options).CaptureEvent(new SentryEvent(), scope); + + + // Assert + hint.Should().NotBeNull(); + hint.Attachments.First().ContentType.Should().Be("text/plain", hint.Attachments.First().ContentType); + } +#endif +}