Skip to content

Commit

Permalink
Merge pull request #618 from bugsnag/next
Browse files Browse the repository at this point in the history
Release v7.2.0
  • Loading branch information
rich-bugsnag authored Sep 12, 2022
2 parents fa0f592 + ca4a227 commit d04bff3
Show file tree
Hide file tree
Showing 20 changed files with 142 additions and 26 deletions.
6 changes: 3 additions & 3 deletions .buildkite/pipeline.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ steps:
key: 'windows-2018-fixture'
depends_on: 'build-artifacts'
agents:
queue: windows-general-wsl
queue: windows-unity-wsl
env:
UNITY_VERSION: "2018.4.36f1"
command:
Expand All @@ -603,7 +603,7 @@ steps:
key: 'windows-2019-fixture'
depends_on: 'build-artifacts'
agents:
queue: windows-general-wsl
queue: windows-unity-wsl
env:
UNITY_VERSION: "2019.4.35f1"
command:
Expand All @@ -625,7 +625,7 @@ steps:
key: 'windows-2021-fixture'
depends_on: 'build-artifacts'
agents:
queue: windows-general-wsl
queue: windows-unity-wsl
env:
UNITY_VERSION: "2021.3.3f1"
commands:
Expand Down
4 changes: 2 additions & 2 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ steps:
- label: Ensure notifier builds on Windows (for development)
timeout_in_minutes: 30
agents:
queue: windows-general-wsl
queue: windows-unity-wsl
env:
UNITY_VERSION: "2018.4.36f1"
WSLENV: UNITY_VERSION
Expand Down Expand Up @@ -285,7 +285,7 @@ steps:
key: 'windows-2020-fixture'
depends_on: 'build-artifacts'
agents:
queue: windows-general-wsl
queue: windows-unity-wsl
env:
UNITY_VERSION: "2020.3.32f1"
plugins:
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 7.2.0 (2022-09-12)

### Enhancements

* Added `BugsnagEvent.FeatureFlags` to allow feature flags to be queried before event delivery.
[#613](https://github.com/bugsnag/bugsnag-unity/pull/613)

### Bug fixes

* Reverted the `HideFlags` fix introduced [here](https://github.com/bugsnag/bugsnag-unity/pull/604) as it was causing (harmless) `NullReferenceException`s in the editor.
[#617](https://github.com/bugsnag/bugsnag-unity/pull/617)

## 7.1.1 (2022-09-07)

### Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var target = Argument("target", "Default");
var solution = File("./BugsnagUnity.sln");
var configuration = Argument("configuration", "Release");
var project = File("./src/BugsnagUnity/BugsnagUnity.csproj");
var version = "7.1.1";
var version = "7.2.0";

Task("Restore-NuGet-Packages")
.Does(() => NuGetRestore(solution));
Expand Down
6 changes: 6 additions & 0 deletions features/android/android_callbacks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ Feature: Callbacks
And the event "breadcrumbs.0.type" equals "user"
And the event "breadcrumbs.0.metaData.Custom" equals "Metadata"

# Feature flags
And the event "featureFlags.0.featureFlag" equals "fromStartup"
And the event "featureFlags.0.variant" equals "a"
And the event "featureFlags.1.featureFlag" equals "fromCallback"
And the event "featureFlags.1.variant" equals "a"

# threads
And the event "threads.0.name" equals "Custom Name"

Expand Down
6 changes: 6 additions & 0 deletions features/desktop/callbacks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ Feature: Callbacks
And the event "breadcrumbs.0.name" equals "Custom Message"
And the event "breadcrumbs.0.metaData.test" equals "test"

# Feature flags
And the event "featureFlags.0.featureFlag" equals "fromStartup"
And the event "featureFlags.0.variant" equals "a"
And the event "featureFlags.1.featureFlag" equals "fromCallback"
And the event "featureFlags.1.variant" equals "a"

# Metadata
And the event "metaData.test1.test" equals "test"
And the event "metaData.test2" is null
7 changes: 7 additions & 0 deletions features/fixtures/maze_runner/Assets/Scripts/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ void PrepareConfigForScenario(Configuration config, string scenario)
@event.AddMetadata("test2", new Dictionary<string, object> { { "test", "test" } });
@event.ClearMetadata("test2");

@event.AddFeatureFlag("fromCallback", @event.FeatureFlags[0].Variant);
@event.ClearFeatureFlag("deleteMe");

return true;
});
Expand Down Expand Up @@ -537,6 +539,8 @@ void RunScenario(string scenario)
Invoke("LaunchException",6);
break;
case "EventCallbacks":
Bugsnag.AddFeatureFlag("fromStartup", "a");
Bugsnag.AddFeatureFlag("deleteMe");
DoNotify();
break;
case "BackgroundThreadCrash":
Expand Down Expand Up @@ -774,6 +778,9 @@ private IEnumerator NotifyPersistedEvents()

private void ClearBugsnagCache()
{
#if UNITY_SWITCH
return;
#endif
var path = Application.persistentDataPath + "/Bugsnag";
if(Directory.Exists(path))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ private Configuration PreapareConfigForScenario(string scenarioName)

@event.AddMetadata("test", "scoop", "dewoop");

@event.AddFeatureFlag("fromCallback", @event.FeatureFlags[0].Variant);
@event.ClearFeatureFlag("deleteMe");

return true;
});
Expand Down Expand Up @@ -395,6 +397,9 @@ private Configuration PreapareConfigForScenario(string scenarioName)

@event.Errors[0].Stacktrace[0].Method = "Method";

@event.AddFeatureFlag("fromCallback", @event.FeatureFlags[0].Variant);
@event.ClearFeatureFlag("deleteMe");

return true;
});
break;
Expand Down Expand Up @@ -485,6 +490,8 @@ public void DoTestAction(string scenarioName)
Invoke("ThrowException", 6);
break;
case "Ios Signal":
Bugsnag.AddFeatureFlag("fromStartup", "a");
Bugsnag.AddFeatureFlag("deleteMe");
MobileNative.DoIosSignal();
break;
case "Check Last Run Info":
Expand Down Expand Up @@ -543,6 +550,8 @@ public void DoTestAction(string scenarioName)
case "Java Background Crash No Threads":
case "Java Background Crash":
AddMetadataForRedaction();
Bugsnag.AddFeatureFlag("fromStartup", "a");
Bugsnag.AddFeatureFlag("deleteMe");
MobileNative.TriggerBackgroundJavaCrash();
break;
case "Native exception":
Expand Down
6 changes: 6 additions & 0 deletions features/ios/ios_callbacks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ Feature: Callbacks
And the event "app.inForeground" is false
And the event "app.isLaunching" is false

# Feature flags
And the event "featureFlags.0.featureFlag" equals "fromStartup"
And the event "featureFlags.0.variant" equals "a"
And the event "featureFlags.1.featureFlag" equals "fromCallback"
And the event "featureFlags.1.variant" equals "a"

And the event "exceptions.0.stacktrace.0.method" equals "Method"
6 changes: 6 additions & 0 deletions features/steps/unity_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def execute_command(action, scenario_name = '')
execute_command('clear_cache')

when 'switch'

`ControlTarget.exe launch-application #{Maze.config.app}`

execute_command('clear_cache')

else
Expand Down Expand Up @@ -86,6 +89,9 @@ def execute_command(action, scenario_name = '')
execute_command('run_scenario', state)

when 'switch'

`ControlTarget.exe launch-application #{Maze.config.app}`

execute_command('run_scenario', state)

else
Expand Down
5 changes: 2 additions & 3 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@
# This is to get around a strange macos bug where clearing prefs does not work
$logger.info 'Killing defaults service'
Maze::Runner.run_command("killall -u #{ENV['USER']} cfprefsd")
elsif Maze.config.os == 'switch'
# Launch the app
`ControlTarget.exe launch-application #{Maze.config.app}`


end
end

Expand Down
27 changes: 18 additions & 9 deletions src/BugsnagUnity.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ void bugsnag_startBugsnagWithConfiguration(const void *configuration, char *noti
// Memory introspection is unused in a C/C++ context
}

const char * getMetadataJson(NSDictionary* dictionary){

if (!dictionary) {
static const char * getJson(id obj) {
if (!obj) {
return NULL;
}

@try {
NSError *error = nil;
NSData *data = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:&error];
NSData *data = [NSJSONSerialization dataWithJSONObject:obj options:0 error:&error];
if (data) {
return strndup((const char *)data.bytes, data.length);
} else {
Expand Down Expand Up @@ -83,7 +81,7 @@ void bugsnag_clearMetadataWithKey(const char * section, const char * key){

const char * bugsnag_getEventMetaData(const void *event, const char *tab) {
NSDictionary* sectionDictionary = [((__bridge BugsnagEvent *)event) getMetadataFromSection:@(tab)];
return getMetadataJson(sectionDictionary);
return getJson(sectionDictionary);
}

void bugsnag_clearEventMetadataWithKey(const void *event, const char *section, const char *key){
Expand Down Expand Up @@ -208,9 +206,20 @@ void bugsnag_getBreadcrumbsFromEvent(const void *event,const void *instance, voi
free(c_array);
}

const char * bugsnag_getFeatureFlagsFromEvent(BugsnagEvent *event) {
NSMutableArray *array = [NSMutableArray array];
for (BugsnagFeatureFlag *flag in event.featureFlags) {
[array addObject:[NSDictionary dictionaryWithObjectsAndKeys:
flag.name, @"featureFlag",
flag.variant, @"variant",
nil]];
}
return getJson(array);
}

const char * bugsnag_getBreadcrumbMetadata(const void *breadcrumb) {
NSDictionary* sectionDictionary = ((__bridge BugsnagBreadcrumb *)breadcrumb).metadata;
return getMetadataJson(sectionDictionary);
return getJson(sectionDictionary);
}

void bugsnag_setBreadcrumbMetadata(const void *breadcrumb, const char *jsonString) {
Expand Down Expand Up @@ -679,7 +688,7 @@ void bugsnag_setMetadata(const char *section, const char *jsonString) {
}

const char * bugsnag_retrieveMetaData() {
return getMetadataJson([Bugsnag.client metadata].dictionary);
return getJson([Bugsnag.client metadata].dictionary);
}

void bugsnag_removeMetadata(const void *configuration, const char *tab) {
Expand All @@ -703,7 +712,7 @@ void bugsnag_retrieveBreadcrumbs(const void *managedBreadcrumbs, void (*breadcru
const char *type = [BSGBreadcrumbTypeValue(crumb.type) UTF8String];

NSDictionary *metadata = crumb.metadata;
breadcrumb(managedBreadcrumbs, message, timestamp, type, getMetadataJson(metadata));
breadcrumb(managedBreadcrumbs, message, timestamp, type, getJson(metadata));

}];
}
Expand Down
20 changes: 19 additions & 1 deletion src/BugsnagUnity/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,27 @@

namespace BugsnagUnity
{
public partial class Configuration : IMetadataEditor, IFeatureFlagStore

public enum SwitchCacheType
{
None,
R,
I
}

public class Configuration : IMetadataEditor, IFeatureFlagStore
{

// Nintendo switch specifics ----------
public SwitchCacheType SwitchCacheType = SwitchCacheType.R;

public string SwitchCacheMountName = "BugsnagCache";

public int SwitchCacheIndex = 0;

public int SwitchMaxCacheSize = 10485760; //10MiB in Bytes
// ----------

public string AppType;

public string BundleVersion;
Expand Down
7 changes: 5 additions & 2 deletions src/BugsnagUnity/MainThreadDispatchBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public static MainThreadDispatchBehaviour Instance()
if (_instance == null)
{
_instance = new GameObject("Bugsnag main thread dispatcher").AddComponent<MainThreadDispatchBehaviour>();
DontDestroyOnLoad(_instance.gameObject);
_instance.gameObject.hideFlags = HideFlags.DontSave;
}
return _instance;
}
Expand Down Expand Up @@ -96,5 +94,10 @@ private IEnumerator DelayAction(Action action, float delay)
action.Invoke();
}

private void Awake()
{
DontDestroyOnLoad(gameObject);
}

}
}
18 changes: 18 additions & 0 deletions src/BugsnagUnity/Native/Android/NativeEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,23 @@ public void ClearFeatureFlags()
{
NativePointer.Call("clearFeatureFlags");
}

public ReadOnlyCollection<FeatureFlag> FeatureFlags
{
get
{
var objects = new List<FeatureFlag>();
var list = NativePointer.Call<AndroidJavaObject>("getFeatureFlags");
var iterator = list.Call<AndroidJavaObject>("iterator");
while (iterator.Call<bool>("hasNext"))
{
var javaObject = iterator.Call<AndroidJavaObject>("next");
var name = javaObject.Call<String>("getName");
var variant = javaObject.Call<String>("getVariant");
objects.Add(new FeatureFlag(name, variant));
}
return new ReadOnlyCollection<FeatureFlag>(objects);
}
}
}
}
5 changes: 3 additions & 2 deletions src/BugsnagUnity/Native/Cocoa/NativeCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ partial class NativeCode

[DllImport(Import)]
internal static extern void bugsnag_clearFeatureFlagsOnEvent(IntPtr @event);

[DllImport(Import)]
internal static extern string bugsnag_getFeatureFlagsFromEvent(IntPtr @event);
}
}


12 changes: 12 additions & 0 deletions src/BugsnagUnity/Native/Cocoa/NativeEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using AOT;
Expand Down Expand Up @@ -201,7 +202,18 @@ public void ClearFeatureFlag(string name)
public void ClearFeatureFlags()
{
NativeCode.bugsnag_clearFeatureFlagsOnEvent(NativePointer);
}

public ReadOnlyCollection<FeatureFlag> FeatureFlags
{
get
{
var jsonString = NativeCode.bugsnag_getFeatureFlagsFromEvent(NativePointer);
var jsonArray = (JsonArray)SimpleJson.DeserializeObject(jsonString);
var objects = jsonArray.Select((item)
=> new FeatureFlag(((JsonObject)item).GetDictionary()));
return new ReadOnlyCollection<FeatureFlag>(objects.ToList());
}
}
}
}
5 changes: 5 additions & 0 deletions src/BugsnagUnity/Payload/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,5 +341,10 @@ public void ClearFeatureFlags()
{
_featureFlags.Clear();
}

public ReadOnlyCollection<FeatureFlag> FeatureFlags
{
get => new ReadOnlyCollection<FeatureFlag>(_featureFlags);
}
}
}
Loading

0 comments on commit d04bff3

Please sign in to comment.