Skip to content

Commit

Permalink
Merge pull request #10 from MindscapeHQ/ro/cs-55/telerik-controls-fix
Browse files Browse the repository at this point in the history
[CS-55]: Fix issue with Android crashing when too many messages are sent
  • Loading branch information
ProRedCat committed Jan 18, 2024
2 parents 2b67d53 + 9066761 commit f76db3b
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 50 deletions.
3 changes: 3 additions & 0 deletions CHANGE-LOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Full Change Log for Raygun4Maui package

### v1.4.1
- Fixed issue with resource locking of device environment information on Android causing app to crash

### v1.4.0
- Dependency update to Raygun4Net 8.0.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ static MauiExceptions()

Android.Runtime.AndroidEnvironment.UnhandledExceptionRaiser += (sender, args) =>
{
args.Handled = true;
UnhandledException?.Invoke(sender, new UnhandledExceptionEventArgs(args.Exception, true));
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Raygun4Maui.MattJohnsonPint.Maui;
using System.Diagnostics;
using Raygun4Maui.MattJohnsonPint.Maui;
using Raygun4Net.BuildPlatforms;

namespace Raygun4Maui.MauiUnhandledExceptions
Expand All @@ -8,7 +9,7 @@ internal static class RaygunMauiUnhandledExceptionsExtensions
internal static MauiAppBuilder AddRaygunUnhandledExceptionsListener(
this MauiAppBuilder mauiAppBuilder,
Raygun4MauiSettings raygunMauiSettings
)
)
{
AttachMauiExceptionHandler(raygunMauiSettings);

Expand All @@ -19,15 +20,23 @@ private static void AttachMauiExceptionHandler(Raygun4MauiSettings raygunMauiSet
{
MauiExceptions.UnhandledException += (sender, args) =>
{
Exception e = (Exception)args.ExceptionObject;
List<string> tags = new List<string>() { "UnhandledException" };
try
{
Exception e = (Exception)args.ExceptionObject;
List<string> tags = new List<string>() { "UnhandledException" };
if (raygunMauiSettings.SendDefaultTags)
if (raygunMauiSettings.SendDefaultTags)
{
tags.Add(Raygun4NetBuildPlatforms.GetBuildPlatform());
}
RaygunMauiClient.Current.SendInBackground(e, tags, null);
}
catch (Exception e)
{
tags.Add(Raygun4NetBuildPlatforms.GetBuildPlatform());
Trace.TraceError($"Unhandled exception handler had an error: {e.Message}");
}
RaygunMauiClient.Current.Send(e, tags, null);
};
}
}
}
}
17 changes: 3 additions & 14 deletions Raygun4Maui/Raygun4Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.4.0</Version>
<PackageVersion>1.4.0</PackageVersion>
<Version>1.4.1</Version>
<PackageVersion>1.4.1</PackageVersion>
<Authors>Raygun</Authors>
<Company>Raygun</Company>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand All @@ -26,18 +26,7 @@
<PackageProjectUrl>https://raygun.com/platform/crash-reporting</PackageProjectUrl>
<RepositoryUrl>https://github.com/MindscapeHQ/raygun4maui</RepositoryUrl>
<PackageTags>Raygun4Maui; Raygun; Crash Reporting; MAUI; .NET; dotnet</PackageTags>
<PackageReleaseNotes>Expanded the device information that is collected when a crash is sent to Raygun.
The new information collected is as follows:
- Available physical memory
- Total physical memory
- Processor count
- Architecture
- Device manugacture
- Model
- Current orientation
- Resolution scale
- WindowBoundsWidth
- WindowBoundsHeight</PackageReleaseNotes>
<PackageReleaseNotes>https://github.com/MindscapeHQ/raygun4maui/blob/master/CHANGE-LOG.md</PackageReleaseNotes>
<Title>Raygun4Maui</Title>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
Expand Down
4 changes: 3 additions & 1 deletion Raygun4Maui/Raygun4Net.BuildPlatforms/RaygunPlatforms.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Raygun4Net.BuildPlatforms
// Namespace is different, doesn't include Raygun4Maui because we may want to move this to Raygun4Net
// ReSharper disable once CheckNamespace
namespace Raygun4Net.BuildPlatforms
{
public static class Raygun4NetBuildPlatforms
{
Expand Down
2 changes: 2 additions & 0 deletions Raygun4Maui/Raygun4Net.RaygunLogger/RaygunLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Raygun4Net.BuildPlatforms;
using Raygun4Maui;

// Namespace is different, doesn't include Raygun4Maui because we may want to move this to Raygun4Net
// ReSharper disable once CheckNamespace
namespace Raygun4Net.RaygunLogger
{
public sealed class RaygunLogger : ILogger
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.Extensions.Logging;
using Mindscape.Raygun4Net;

// Namespace is different, doesn't include Raygun4Maui because we may want to move this to Raygun4Net
// ReSharper disable once CheckNamespace
namespace Raygun4Net.RaygunLogger
{
public class RaygunLoggerConfiguration : RaygunSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;

// Namespace is different, doesn't include Raygun4Maui because we may want to move this to Raygun4Net
// ReSharper disable once CheckNamespace
namespace Raygun4Net.RaygunLogger
{
public static class RaygunLoggerMauiExtensions
Expand Down
2 changes: 2 additions & 0 deletions Raygun4Maui/Raygun4Net.RaygunLogger/RaygunLoggerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Microsoft.Extensions.Options;
using System.Collections.Concurrent;

// Namespace is different, doesn't include Raygun4Maui because we may want to move this to Raygun4Net
// ReSharper disable once CheckNamespace
namespace Raygun4Net.RaygunLogger
{
public sealed class RaygunLoggerProvider : ILoggerProvider
Expand Down
48 changes: 21 additions & 27 deletions Raygun4Maui/RaygunMauiClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

using System.Reflection;
using Mindscape.Raygun4Net;
using System.Globalization;
Expand All @@ -11,56 +10,50 @@ public class RaygunMauiClient : RaygunClient
private static RaygunMauiClient _instance;
public static RaygunMauiClient Current => _instance;

private readonly Lazy<RaygunMauiEnvironmentMessageBuilder> _lazyMessageBuilder =
new Lazy<RaygunMauiEnvironmentMessageBuilder>(RaygunMauiEnvironmentMessageBuilder.Init);

private RaygunMauiEnvironmentMessageBuilder EnvironmentMessageBuilder => _lazyMessageBuilder.Value;

private static readonly string Name = Assembly.GetExecutingAssembly().GetName().Name;
private static readonly string Version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
private static readonly string ClientUrl = "https://github.com/MindscapeHQ/raygun4maui"; //It does not seem like this can be obtained automatically

private static readonly string Version =
Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "Unknown";

private static readonly string
ClientUrl =
"https://github.com/MindscapeHQ/raygun4maui"; //It does not seem like this can be obtained automatically

public static readonly RaygunClientMessage clientMessage = new()
{
Name = Name,
Version = Version,
ClientUrl = ClientUrl
};

internal static void Attach(RaygunMauiClient client)
{
if (_instance != null)
{
throw new Exception("You should only call 'AddRaygun4maui' once in your app.");
}

_instance = client;
}

public RaygunMauiClient(string apiKey) : base(apiKey)
{

}

public RaygunMauiClient(RaygunSettings settings) : base(settings)
{
}



protected override async Task<RaygunMessage> BuildMessage(Exception exception, IList<string> tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo)
protected override async Task<RaygunMessage> BuildMessage(Exception exception, IList<string> tags,
IDictionary userCustomData, RaygunIdentifierMessage userInfo)
{
DateTime now = DateTime.Now;
var environment = new RaygunMauiEnvironmentMessage //Mostlikely should be static
{
UtcOffset = TimeZoneInfo.Local.GetUtcOffset(now).TotalHours,
Locale = CultureInfo.CurrentCulture.DisplayName,
OSVersion = DeviceInfo.Current.VersionString,
Architecture = NativeDeviceInfo.Architecture(),
WindowBoundsWidth = DeviceDisplay.MainDisplayInfo.Width,
WindowBoundsHeight = DeviceDisplay.MainDisplayInfo.Height,
DeviceManufacturer = DeviceInfo.Current.Manufacturer,
Platform = NativeDeviceInfo.Platform(),
Model = DeviceInfo.Current.Model,
ProcessorCount = Environment.ProcessorCount,
ResolutionScale = DeviceDisplay.MainDisplayInfo.Density,
TotalPhysicalMemory = NativeDeviceInfo.TotalPhysicalMemory(),
AvailablePhysicalMemory = NativeDeviceInfo.AvailablePhysicalMemory(),
CurrentOrientation = DeviceDisplay.MainDisplayInfo.Orientation.ToString(),
};
var environment = EnvironmentMessageBuilder.BuildEnvironmentMessage();

var details = new RaygunMessageDetails
{
Expand All @@ -70,7 +63,8 @@ protected override async Task<RaygunMessage> BuildMessage(Exception exception, I
UserCustomData = userCustomData,
Tags = tags,
Version = ApplicationVersion,
User = userInfo ?? UserInfo ?? (!String.IsNullOrEmpty(User) ? new RaygunIdentifierMessage(User) : null),
User = userInfo ??
UserInfo ?? (!String.IsNullOrEmpty(User) ? new RaygunIdentifierMessage(User) : null),
Environment = environment
};

Expand All @@ -90,4 +84,4 @@ protected override async Task<RaygunMessage> BuildMessage(Exception exception, I
return message;
}
}
}
}
53 changes: 53 additions & 0 deletions Raygun4Maui/RaygunMauiEnvironmentMessageBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System.Globalization;

namespace Raygun4Maui;

internal class RaygunMauiEnvironmentMessageBuilder
{
private static readonly object EnvironmentLock = new();

public string OSVersion { get; init; } = DeviceInfo.Current.VersionString;
public string Architecture { get; init; } = NativeDeviceInfo.Architecture();

private string DeviceManufacturer = DeviceInfo.Current.Manufacturer;
private string Platform = NativeDeviceInfo.Platform();
private string Model = DeviceInfo.Current.Model;

private int ProcessorCount = Environment.ProcessorCount;


private ulong TotalPhysicalMemory = NativeDeviceInfo.TotalPhysicalMemory();

internal RaygunMauiEnvironmentMessage BuildEnvironmentMessage()
{
// We create a lock so that during async tasks we do not access device information at the same time
// this has caused issues in Android
lock (EnvironmentLock)
{
DateTime now = DateTime.Now;

return new RaygunMauiEnvironmentMessage
{
UtcOffset = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now).TotalHours,
Locale = CultureInfo.CurrentCulture.DisplayName,
OSVersion = OSVersion,
Architecture = Architecture,
WindowBoundsWidth = DeviceDisplay.MainDisplayInfo.Width,
WindowBoundsHeight = DeviceDisplay.MainDisplayInfo.Height,
DeviceManufacturer = DeviceInfo.Current.Manufacturer,
Platform = Platform,
Model = Model,
ProcessorCount = ProcessorCount,
ResolutionScale = DeviceDisplay.MainDisplayInfo.Density,
TotalPhysicalMemory = TotalPhysicalMemory,
AvailablePhysicalMemory = NativeDeviceInfo.AvailablePhysicalMemory(),
CurrentOrientation = DeviceDisplay.MainDisplayInfo.Orientation.ToString(),
};
}
}

public static RaygunMauiEnvironmentMessageBuilder Init()
{
return new RaygunMauiEnvironmentMessageBuilder();
}
}

0 comments on commit f76db3b

Please sign in to comment.