Skip to content

Commit

Permalink
Merge pull request #719 from bugsnag/next
Browse files Browse the repository at this point in the history
Release v7.6.1
  • Loading branch information
richardelms authored Jun 13, 2023
2 parents bc94332 + ee29283 commit 9afeba9
Show file tree
Hide file tree
Showing 20 changed files with 172 additions and 32 deletions.
6 changes: 3 additions & 3 deletions .buildkite/pipeline.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ steps:
- Bugsnag.unitypackage
upload:
- features/fixtures/maze_runner/mazerunner_2018.4.36f1.apk
- features/fixtures/unity.log
- features/fixtures/build_android_apk.log
commands:
- rake test:android:build
retry:
Expand All @@ -220,7 +220,7 @@ steps:
- Bugsnag.unitypackage
upload:
- features/fixtures/maze_runner/mazerunner_2019.4.35f1.apk
- features/fixtures/unity.log
- features/fixtures/build_android_apk.log
commands:
- rake test:android:build
retry:
Expand All @@ -240,7 +240,7 @@ steps:
- Bugsnag.unitypackage
upload:
- features/fixtures/maze_runner/mazerunner_2021.3.13f1.apk
- features/fixtures/unity.log
- features/fixtures/build_android_apk.log
commands:
- rake test:android:build
retry:
Expand Down
2 changes: 1 addition & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ steps:
- Bugsnag.unitypackage
upload:
- features/fixtures/maze_runner/mazerunner_2020.3.32f1.apk
- features/fixtures/unity.log
- features/fixtures/build_android_apk.log
commands:
- rake test:android:build
retry:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 7.6.1 (2023-06-13)

## Bug Fixes

- Prevent callback to Unity from native layers for session and event callbacks if not used to avoid potential ANRs and improve performance. [#717](https://github.com/bugsnag/bugsnag-unity/pull/717)

## 7.6.0 (2023-05-25)

- Update bugsnag-cocoa from v6.25.2 to [v6.26.2](https://github.com/bugsnag/bugsnag-cocoa/blob/master/CHANGELOG.md#6262-2023-04-20)
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.6.0";
var version = "7.6.1";

Task("Restore-NuGet-Packages")
.Does(() => NuGetRestore(solution));
Expand Down
14 changes: 7 additions & 7 deletions features/csharp/csharp_events.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Feature: csharp events
And the event "unhandled" is false
And custom metadata is included in the event
And the stack frame methods should match:
| NotifySmokeTest.Run() | Main+<RunNextMazeCommand>d__7.MoveNext() |
| NotifySmokeTest.Run() | Main+<RunNextMazeCommand>d__8.MoveNext() |
And expected device metadata is included in the event
And expected app metadata is included in the event

Expand All @@ -26,7 +26,7 @@ Feature: csharp events
And custom metadata is included in the event
And the stack frame methods should match:
| UncaughtExceptionSmokeTest.Run() | |
| ScenarioRunner.RunScenario(System.String scenarioName, System.String apiKey, System.String host) | Main+<RunNextMazeCommand>d__7.MoveNext() |
| ScenarioRunner.RunScenario(System.String scenarioName, System.String apiKey, System.String host) | Main+<RunNextMazeCommand>d__8.MoveNext() |
And expected device metadata is included in the event
And expected app metadata is included in the event

Expand All @@ -39,7 +39,7 @@ Feature: csharp events
And the event "unhandled" is false
And custom metadata is included in the event
And the stack frame methods should match:
| DebugLogExceptionSmokeTest:Run() | DebugLogExceptionSmokeTest.Run() | <RunNextMazeCommand>d__7:MoveNext() | UnityEngine.SetupCoroutine.InvokeMoveNext(IEnumerator enumerator, IntPtr returnValueAddress) |
| DebugLogExceptionSmokeTest:Run() | DebugLogExceptionSmokeTest.Run() | <RunNextMazeCommand>d__8:MoveNext() | UnityEngine.SetupCoroutine.InvokeMoveNext(IEnumerator enumerator, IntPtr returnValueAddress) |
| ScenarioRunner:RunScenario(String, String, String) | ScenarioRunner.RunScenario(string scenarioName, string apiKey, string host) | UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) | UnityEngine.SetupCoroutine.InvokeMoveNext(IEnumerator enumerator, IntPtr returnValueAddress) |
And expected device metadata is included in the event
And expected app metadata is included in the event
Expand All @@ -53,7 +53,7 @@ Feature: csharp events
And the event "unhandled" is false
And custom metadata is included in the event
And the stack frame methods should match:
| DebugLogErrorSmokeTest:Run() | DebugLogErrorSmokeTest.Run() | <RunNextMazeCommand>d__7:MoveNext() | |
| DebugLogErrorSmokeTest:Run() | DebugLogErrorSmokeTest.Run() | <RunNextMazeCommand>d__8:MoveNext() | |
| ScenarioRunner:RunScenario(String, String, String) | ScenarioRunner.RunScenario(string scenarioName, string apiKey, string host) | ScenarioRunner:RunScenario(string,string,string) | UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) |
And expected device metadata is included in the event
And expected app metadata is included in the event
Expand All @@ -67,7 +67,7 @@ Feature: csharp events
And the event "unhandled" is false
And custom metadata is included in the event
And the stack frame methods should match:
| DebugLogWarningSmokeTest:Run() | DebugLogWarningSmokeTest.Run() | <RunNextMazeCommand>d__7:MoveNext() | |
| DebugLogWarningSmokeTest:Run() | DebugLogWarningSmokeTest.Run() | <RunNextMazeCommand>d__8:MoveNext() | |
| ScenarioRunner:RunScenario(String, String, String) | ScenarioRunner.RunScenario(string scenarioName, string apiKey, string host) | ScenarioRunner:RunScenario(string,string,string) | UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) |
And expected device metadata is included in the event
And expected app metadata is included in the event
Expand All @@ -81,7 +81,7 @@ Feature: csharp events
And the event "unhandled" is false
And custom metadata is included in the event
And the stack frame methods should match:
| DebugLogSmokeTest:Run() | DebugLogSmokeTest.Run() | <RunNextMazeCommand>d__7:MoveNext() | |
| DebugLogSmokeTest:Run() | DebugLogSmokeTest.Run() | <RunNextMazeCommand>d__8:MoveNext() | |
| ScenarioRunner:RunScenario(String, String, String) | ScenarioRunner.RunScenario(string scenarioName, string apiKey, string host) | ScenarioRunner:RunScenario(string,string,string) | UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) |
And expected device metadata is included in the event
And expected app metadata is included in the event
Expand All @@ -95,7 +95,7 @@ Feature: csharp events
And the event "unhandled" is false
And custom metadata is included in the event
And the stack frame methods should match:
| DebugLogAssertSmokeTest:Run() | DebugLogAssertSmokeTest.Run() | <RunNextMazeCommand>d__7:MoveNext() | |
| DebugLogAssertSmokeTest:Run() | DebugLogAssertSmokeTest.Run() | <RunNextMazeCommand>d__8:MoveNext() | |
| ScenarioRunner:RunScenario(String, String, String) | ScenarioRunner.RunScenario(string scenarioName, string apiKey, string host) | ScenarioRunner:RunScenario(string,string,string) | UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) |
And expected device metadata is included in the event
And expected app metadata is included in the event
Expand Down
28 changes: 28 additions & 0 deletions features/fixtures/maze_runner/Assets/Scripts/Logger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public class Logger : MonoBehaviour
{

const string LOG_PREFIX = "BUGSNAG_MAZERUNNER_LOG : ";

const string LOG_FILE_NAME = "mazerunner-unity.log";

private static string _currentLog;

public static void I(string msg)
{
Debug.Log(LOG_PREFIX + msg);
_currentLog = msg + "\n";
WriteLogFile();
}

private static void WriteLogFile()
{
var path = Path.Combine(Application.persistentDataPath, LOG_FILE_NAME);
File.WriteAllText(path, _currentLog);
}

}
11 changes: 11 additions & 0 deletions features/fixtures/maze_runner/Assets/Scripts/Logger.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 20 additions & 12 deletions features/fixtures/maze_runner/Assets/Scripts/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ public class Main : MonoBehaviour
private const string API_KEY = "a35a2a72bd230ac0aa0f52715bbdc6aa";
private string _mazeHost;

private const int MAX_CONFIG_GET_TRIES = 15;

public ScenarioRunner ScenarioRunner;

public IEnumerator Start()
{
Debug.Log("Maze Runner app started");
Log("Maze Runner app started");

yield return GetFixtureConfig();

Expand All @@ -56,28 +58,29 @@ private IEnumerator GetFixtureConfig()
Application.platform == RuntimePlatform.IPhonePlayer)
{
var numTries = 0;
while (numTries < 5)
while (numTries < MAX_CONFIG_GET_TRIES)
{
var configPath = Application.persistentDataPath + _fixtureConfigFileName;
if (File.Exists(configPath))
{
var configJson = File.ReadAllText(configPath);
Debug.Log("Mazerunner got fixture config json: " + configJson);
Log("Mazerunner got fixture config json: " + configJson);
var config = JsonUtility.FromJson<FixtureConfig>(configJson);
_mazeHost = "http://" + config.maze_address;
break;
}
else
{
Debug.Log("Mazerunner no fixture config found at path: " + configPath);
numTries++;
Log(string.Format("Maze Runner did not find the config file at path {0} try number {1}", configPath, numTries));
yield return new WaitForSeconds(1);
}
}
}

if (string.IsNullOrEmpty(_mazeHost))
{
Log("Host not set from config file, using hard coded");
_mazeHost = "http://localhost:9339";

if (Application.platform == RuntimePlatform.IPhonePlayer ||
Expand All @@ -86,7 +89,7 @@ private IEnumerator GetFixtureConfig()
_mazeHost = "http://bs-local.com:9339";
}
}
Debug.Log("Mazerunner host set to: " + _mazeHost);
Log("Mazerunner host set to: " + _mazeHost);
}

private void DoRunNextMazeCommand()
Expand All @@ -97,7 +100,7 @@ private void DoRunNextMazeCommand()
IEnumerator RunNextMazeCommand()
{
var url = _mazeHost + "/command";
Console.WriteLine("RunNextMazeCommand called, requesting command from: {0}", url);
Log("Requesting maze command from: " + url);
using (UnityWebRequest request = UnityWebRequest.Get(url))
{
yield return request.SendWebRequest();
Expand All @@ -109,23 +112,23 @@ IEnumerator RunNextMazeCommand()
!request.isNetworkError;
#endif

Console.WriteLine("result is " + result);
Log("result is " + result);
if (result)
{
var response = request.downloadHandler?.text;
Console.WriteLine("Raw response: " + response);
Log("Raw response: " + response);
if (response == null || response == "null" || response == "No commands to provide")
{
Console.WriteLine("No Maze Runner command to process at present");
Log("No Maze Runner command to process at present");
}
else
{
var command = JsonUtility.FromJson<Command>(response);
if (command != null)
{
Console.WriteLine("Received Maze Runner command:");
Console.WriteLine("Action: " + command.action);
Console.WriteLine("Scenario: " + command.scenarioName);
Log("Received Maze Runner command:");
Log("Action: " + command.action);
Log("Scenario: " + command.scenarioName);

if ("clear_cache".Equals(command.action))
{
Expand Down Expand Up @@ -178,6 +181,11 @@ public static void ClearIOSData()
#endif
}

private static void Log(string msg)
{
Logger.I(msg);
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public override void PrepareConfig(string apiKey, string host)
base.PrepareConfig(apiKey, host);
Configuration.SetUser("1", "2", "3");
Configuration.ProjectPackages = new string[] { "test.test.test" };
Configuration.AddOnSession((s) => { return true; });
}

public override void Run()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class IosNativeException : Scenario
public override void PrepareConfig(string apiKey, string host)
{
base.PrepareConfig(apiKey, host);
Configuration.AddOnSession((s) => { return true; });
}

public override void Run()
Expand Down
2 changes: 1 addition & 1 deletion features/scripts/build_android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ popd
pushd "$script_path/../fixtures"

# Run unity and immediately exit afterwards, log all output
DEFAULT_CLI_ARGS="-quit -batchmode -nographics -logFile unity.log"
DEFAULT_CLI_ARGS="-quit -batchmode -nographics -logFile build_android_apk.log"

project_path=`pwd`/maze_runner

Expand Down
6 changes: 6 additions & 0 deletions src/BugsnagUnity.m
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,12 @@ void bugsnag_markLaunchCompleted() {
[Bugsnag markLaunchCompleted];
}

void bugsnag_registerForSessionCallbacksAfterStart(bool (*callback)(void *session)){
[Bugsnag addOnSessionBlock:^BOOL (BugsnagSession *session) {
return callback((__bridge void *)session);
}];
}

void *bugsnag_createConfiguration(char *apiKey) {
return (void *)CFBridgingRetain([[BugsnagConfiguration alloc] initWithApiKey:@(apiKey)]);
}
Expand Down
10 changes: 9 additions & 1 deletion src/BugsnagUnity/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ private void NotifyFromUnityLog(string condition, string stackTrace, LogType log
{
return;
}
if (condition.StartsWith("BUGSNAG_MAZERUNNER_LOG"))
{
return;
}
if (Configuration.AutoDetectErrors && logType.IsGreaterThanOrEqualTo(Configuration.NotifyLogLevel))
{
var logMessage = new UnityLogMessage(condition, stackTrace, logType);
Expand Down Expand Up @@ -575,7 +579,11 @@ public string GetContext()

public void RemoveOnError(Func<IEvent, bool> bugsnagCallback) => Configuration.RemoveOnError(bugsnagCallback);

public void AddOnSession(Func<ISession, bool> callback) => Configuration.AddOnSession(callback);
public void AddOnSession(Func<ISession, bool> callback)
{
Configuration.AddOnSession(callback);
NativeClient.RegisterForOnSessionCallbacks();
}

public void RemoveOnSession(Func<ISession, bool> callback) => Configuration.RemoveOnSession(callback);

Expand Down
5 changes: 5 additions & 0 deletions src/BugsnagUnity/INativeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,10 @@ interface INativeClient : IFeatureFlagStore

bool ShouldAttemptDelivery();

/// <summary>
/// Subscribes the Unity layer for session callbacks. Not many users use session callbacks, so we are only subscribing to the native side if necessary as an optimisation.
/// </summary>
void RegisterForOnSessionCallbacks();

}
}
5 changes: 5 additions & 0 deletions src/BugsnagUnity/Native/Android/NativeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ public bool ShouldAttemptDelivery()
{
return true;
}

public void RegisterForOnSessionCallbacks()
{
NativeInterface.RegisterForOnSessionCallbacks();
}
}

}
Loading

0 comments on commit 9afeba9

Please sign in to comment.