-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
871 additions
and
1,249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using AndroidConfiguration = Com.Bugsnag.Android.Configuration; | ||
|
||
namespace Bugsnag.Maui; | ||
|
||
public partial class BugsnagBuilder | ||
{ | ||
internal partial BugsnagMaui Build() | ||
{ | ||
ArgumentException.ThrowIfNullOrEmpty(this.apiKey); | ||
|
||
var config = new AndroidConfiguration(this.apiKey); | ||
config.AutoDetectErrors = this.autoDetectErrors; | ||
config.LaunchDurationMillis = this.launchDurationMillis ?? config.LaunchDurationMillis; | ||
config.ReleaseStage = this.releaseStage.ToString().ToLowerInvariant(); | ||
return new BugsnagMaui(config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
namespace Bugsnag.Maui; | ||
|
||
public partial class BugsnagBuilder | ||
{ | ||
private string? apiKey; | ||
private ReleaseStage releaseStage; | ||
private bool autoDetectErrors = true; | ||
private int? launchDurationMillis; | ||
|
||
public BugsnagBuilder WithApiKey(string apiKey) | ||
{ | ||
ArgumentException.ThrowIfNullOrEmpty(apiKey); | ||
this.apiKey = this.apiKey; | ||
return this; | ||
} | ||
|
||
public BugsnagBuilder WithReleaseStage(ReleaseStage releaseStage) | ||
{ | ||
this.releaseStage = releaseStage; | ||
return this; | ||
} | ||
|
||
|
||
public BugsnagBuilder WithAutoDetectErrors(bool autoDetectErrors) | ||
{ | ||
this.autoDetectErrors = autoDetectErrors; | ||
return this; | ||
} | ||
|
||
public BugsnagBuilder WithLaunchDurationMillis(int launchDurationMillis) | ||
{ | ||
this.launchDurationMillis = launchDurationMillis; | ||
return this; | ||
} | ||
|
||
internal partial BugsnagMaui Build(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Bugsnag.iOS; | ||
|
||
namespace Bugsnag.Maui; | ||
|
||
public partial class BugsnagBuilder | ||
{ | ||
internal partial BugsnagMaui Build() | ||
{ | ||
ArgumentException.ThrowIfNullOrEmpty(this.apiKey); | ||
|
||
var config = new BugsnagConfiguration(this.apiKey); | ||
config.AutoDetectErrors = this.autoDetectErrors; | ||
config.LaunchDurationMillis = (uint?)this.launchDurationMillis ?? config.LaunchDurationMillis; | ||
config.ReleaseStage = this.releaseStage.ToString().ToLowerInvariant(); | ||
|
||
return new BugsnagMaui(config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Bugsnag.Maui; | ||
|
||
public partial class BugsnagBuilder | ||
{ | ||
internal partial BugsnagMaui Build() | ||
{ | ||
ArgumentException.ThrowIfNullOrEmpty(this.apiKey); | ||
|
||
return new BugsnagMaui(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,118 @@ | ||
using System.Text.Json; | ||
using Bugsnag.iOS; | ||
using Foundation; | ||
|
||
namespace Bugsnag.Maui; | ||
|
||
public partial class BugsnagMaui | ||
{ | ||
public void Start(ReleaseStage releaseStage) | ||
private BugsnagBindingClient? bugsnagBindingClient; | ||
private readonly BugsnagConfiguration config; | ||
|
||
public BugsnagMaui(BugsnagConfiguration config) | ||
{ | ||
this.config = config; | ||
this.config.AddOnSendErrorBlock(ShouldSendError); | ||
this.ConfigureErrorHandling(); | ||
} | ||
|
||
public void Start() | ||
{ | ||
if (bugsnagBindingClient != null) | ||
{ | ||
return; | ||
} | ||
|
||
this.bugsnagBindingClient = new BugsnagBindingClient(); | ||
this.bugsnagBindingClient.Start(config); | ||
} | ||
|
||
private bool ShouldSendError(BugsnagEvent bugsnagEvent) | ||
{ | ||
var config = new BugsnagConfiguration(); | ||
config.ApiKey = this.apiKey; | ||
config.ReleaseStage = releaseStage.ToString().ToLowerInvariant(); | ||
config.AutoDetectErrors = true; | ||
BugsnagBindingClient.StartBugsnagWithConfiguration(config, "0.0.0"); | ||
if (!bugsnagEvent.Unhandled | ||
|| !(bugsnagEvent.Errors?.Length > 0) | ||
|| !(bugsnagEvent.Errors[0].Stacktrace?.Length > 1)) | ||
{ | ||
return true; | ||
} | ||
|
||
// Maui Errors are handled in the Maui layer, so we do not want to send the | ||
// native crash reports to Bugsnag. only go back 5 frames since the | ||
// xamaerin_unhandled_exception_handler is the best indicator that the error | ||
// was handled in the Maui layer. | ||
var stackTrace = bugsnagEvent.Errors[0].Stacktrace; | ||
for (int frame = 0; frame < 5; frame++) | ||
{ | ||
if (stackTrace[frame].Method?.Contains("xamarin_unhandled_exception_handler") == true) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public void MarkLaunchCompleted() | ||
{ | ||
BugsnagBindingClient.MarkLaunchCompleted(); | ||
this.bugsnagBindingClient?.MarkLaunchCompleted(); | ||
} | ||
|
||
public void AddFeatureFlag(string name, string variant) | ||
{ | ||
BugsnagBindingClient.AddFeatureFlag(name, variant); | ||
this.bugsnagBindingClient?.AddFeatureFlag(name, variant); | ||
} | ||
|
||
public void ClearFeatureFlag(string name) | ||
{ | ||
BugsnagBindingClient.ClearFeatureFlag(name); | ||
this.bugsnagBindingClient?.ClearFeatureFlag(name); | ||
} | ||
|
||
public void ClearFeatureFlags() | ||
{ | ||
BugsnagBindingClient.ClearFeatureFlags(); | ||
this.bugsnagBindingClient?.ClearFeatureFlags(); | ||
} | ||
|
||
public void SetUser(string userId) | ||
{ | ||
BugsnagBindingClient.SetUser(userId, null, null); | ||
this.bugsnagBindingClient?.SetUser(userId, null, null); | ||
} | ||
|
||
public void LeaveBreadcrumb(string message) | ||
{ | ||
BugsnagBindingClient.AddBreadcrumb(message, "State", null); | ||
this.bugsnagBindingClient?.LeaveBreadcrumb(message); | ||
} | ||
|
||
public void LeaveBreadcrumb(string message, Dictionary<string, object> metadata) | ||
{ | ||
BugsnagBindingClient.AddBreadcrumb(message, "State", JsonSerializer.Serialize(metadata)); | ||
|
||
this.bugsnagBindingClient?.LeaveBreadcrumb(message, ConvertJsonToNsDictionary(JsonSerializer.Serialize(metadata)), BSGBreadcrumbType.State); | ||
} | ||
|
||
private partial void PlatformNotify(Dictionary<string, object> report, bool unhandled) | ||
{ | ||
if (this.bugsnagBindingClient == null) | ||
{ | ||
return; | ||
} | ||
|
||
|
||
|
||
var @event = this.bugsnagBindingClient.CreateEvent(ConvertJsonToNsDictionary(JsonSerializer.Serialize(report)), unhandled, false); | ||
this.bugsnagBindingClient.DeliverEvent(@event); | ||
} | ||
|
||
public static NSDictionary ConvertJsonToNsDictionary(string jsonString) | ||
{ | ||
NSError error; | ||
NSData jsonData = NSData.FromString(jsonString, NSStringEncoding.UTF8); | ||
NSDictionary dictionary = (NSDictionary)NSJsonSerialization.Deserialize(jsonData, NSJsonReadingOptions.MutableContainers, out error); | ||
|
||
if (error != null) | ||
{ | ||
// Handle error | ||
Console.WriteLine($"Error converting JSON to NSDictionary: {error.LocalizedDescription}"); | ||
return null; | ||
} | ||
|
||
return dictionary; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.