Skip to content
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5eda61b
feat: scene-load transctions based on SceneManagerAPI
vaind May 31, 2022
abd5f1f
Update package-dev/Runtime/SentryInitialization.cs
vaind Jun 1, 2022
c6bf27e
merged main
bitsandfoxes Jul 1, 2022
2049f5c
creating span for loading
bitsandfoxes Jul 1, 2022
f63bb25
Merge branch 'main' into feat/scene-load-tx
bitsandfoxes Sep 1, 2022
40c06ff
capturing scene load transaction during startup
bitsandfoxes Sep 5, 2022
b048549
refactored the self initialization flag
bitsandfoxes Sep 6, 2022
fd475fb
creating spans through runtime initialzation and added test setup
bitsandfoxes Sep 7, 2022
f359157
finished startup capture & added tests
bitsandfoxes Sep 9, 2022
5c48b23
tweaked tests
bitsandfoxes Sep 9, 2022
f810587
tests & naming
bitsandfoxes Sep 21, 2022
510329c
test asmdef editor exclusive
bitsandfoxes Sep 21, 2022
9183831
asmdef for runtime tests only
bitsandfoxes Sep 21, 2022
eec3fbd
removed argument check in smoketest configure
bitsandfoxes Sep 22, 2022
779632d
logging cleanup
bitsandfoxes Sep 22, 2022
40bdd79
disabling auto session tracking on WebGL
bitsandfoxes Sep 26, 2022
2f71c0a
removing expected session from smoketest
bitsandfoxes Sep 26, 2022
bcd55a9
initialize later on webgl
bitsandfoxes Sep 26, 2022
74a520c
Merge branch 'main' into feat/scene-load-tx
bitsandfoxes Sep 26, 2022
9eefb51
Revert "Merge branch 'main' into feat/scene-load-tx"
bitsandfoxes Sep 26, 2022
152adbe
2020 symbol upload expectations
bitsandfoxes Sep 26, 2022
53c8279
renamed runtime spans
bitsandfoxes Sep 27, 2022
26dcf4a
span remame
bitsandfoxes Sep 27, 2022
99f4291
uncompressed webgl builds for local convenience
bitsandfoxes Sep 27, 2022
d97e3da
disabling runtime tracing on WebGL
bitsandfoxes Sep 27, 2022
f55d0cf
removed jetbrains annotations
bitsandfoxes Sep 27, 2022
79e6d68
unity 2020.3 guard
bitsandfoxes Sep 27, 2022
7364951
fixed broken merge
bitsandfoxes Sep 27, 2022
fbabbcb
rest of the merge
bitsandfoxes Sep 27, 2022
b4d5868
Merge branch 'main' into feat/scene-load-tx
bitsandfoxes Sep 27, 2022
c57c4c2
Updated CHANGELOG.md
bitsandfoxes Sep 27, 2022
7a4e7c6
Merge branch 'main' into feat/scene-load-tx
bitsandfoxes Sep 28, 2022
10b9c35
just scene loading
bitsandfoxes Sep 28, 2022
861d01e
Updated CHANGELOG.md
bitsandfoxes Sep 28, 2022
1d594f6
cleanup
bitsandfoxes Sep 28, 2022
8551d08
cleanup #2
bitsandfoxes Sep 28, 2022
eb2c2dd
logging
bitsandfoxes Sep 28, 2022
d000e57
revolved broken class naming
bitsandfoxes Sep 28, 2022
93de324
fixed span names
bitsandfoxes Sep 29, 2022
0e3d9aa
removed builder changes
bitsandfoxes Sep 29, 2022
bff3edd
test using dummy dsn
bitsandfoxes Sep 29, 2022
ac193c1
added dev-only comment to local integration test script
bitsandfoxes Sep 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Releasing temp render texture after capturing a screenshot ([#983](https://github.com/getsentry/sentry-unity/pull/983))

### Features

- Automated Performance Instrumentalisation for Scene Loading ([#768](https://github.com/getsentry/sentry-unity/pull/768))

### Dependencies

- Bump Java SDK from v6.4.1 to v6.4.2 ([#980](https://github.com/getsentry/sentry-unity/pull/980))
Expand Down
8 changes: 7 additions & 1 deletion package-dev/Runtime/SentryInitialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@ namespace Sentry.Unity
{
public static class SentryInitialization
{
#if SENTRY_WEBGL
// On WebGL SubsystemRegistration is too early for the UnityWebRequestTransport and errors with 'URI empty'
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
#else
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
#endif
public static void Init()
{
var sentryUnityInfo = new SentryUnityInfo();
var options = ScriptableSentryUnityOptions.LoadSentryUnityOptions(sentryUnityInfo);
if (options.ShouldInitializeSdk())
if (options != null && options.ShouldInitializeSdk())
{
SentryIntegrations.Configure(options);
Exception nativeInitException = null;

try
Expand Down
87 changes: 87 additions & 0 deletions package-dev/Runtime/SentryIntegrations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#if UNITY_2020_3_OR_NEWER
#define SENTRY_SCENE_MANAGER_TRACING_INTEGRATION
#endif

using Sentry.Extensibility;
using Sentry.Integrations;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace Sentry.Unity
{
public static class SentryIntegrations
{
public static void Configure(SentryUnityOptions options)
{
#if SENTRY_SCENE_MANAGER_TRACING_INTEGRATION
if (options.TracesSampleRate > 0.0)
{
options.AddIntegration(new SceneManagerTracingIntegration());
}
else
{
options.DiagnosticLogger?.LogDebug("Skipping SceneManagerTracing integration because performance tracing is disabled.");
}
#endif
}
}

#if SENTRY_SCENE_MANAGER_TRACING_INTEGRATION
public class SceneManagerTracingIntegration : ISdkIntegration
{
private static IDiagnosticLogger Logger;

public void Register(IHub hub, SentryOptions options)
{
Logger = options.DiagnosticLogger;

if (SceneManagerAPI.overrideAPI != null)
{
// TODO: Add a place to put a custom 'SceneManagerAPI' on the editor window so we can "decorate" it.
Logger?.LogWarning("Registering SceneManagerTracing integration - overwriting the previous SceneManagerAPI.overrideAPI.");
}

SceneManagerAPI.overrideAPI = new SceneManagerTracingAPI(Logger);
}
}

public class SceneManagerTracingAPI : SceneManagerAPI
{
public const string TransactionName = "unity.scene.loading";
private const string SpanName = "unity.scene.load";
private readonly IDiagnosticLogger _logger;

public SceneManagerTracingAPI(IDiagnosticLogger logger)
{
_logger = logger;
}

protected override AsyncOperation LoadSceneAsyncByNameOrIndex(string sceneName, int sceneBuildIndex, LoadSceneParameters parameters, bool mustCompleteNextFrame)
{
_logger?.LogInfo("Creating '{0}' transaction for '{1}'.", TransactionName, sceneName);

var transaction = SentrySdk.StartTransaction(TransactionName, sceneName ?? $"buildIndex:{sceneBuildIndex}");
SentrySdk.ConfigureScope(scope => scope.Transaction = transaction);

_logger?.LogDebug("Creating '{0}' span.", SpanName);
var span = SentrySdk.GetSpan()?.StartChild(SpanName);

var asyncOp = base.LoadSceneAsyncByNameOrIndex(sceneName, sceneBuildIndex, parameters, mustCompleteNextFrame);

// TODO: setExtra()? e.g. from the LoadSceneParameters:
// https://github.com/Unity-Technologies/UnityCsReference/blob/02d565cf3dd0f6b15069ba976064c75dc2705b08/Runtime/Export/SceneManager/SceneManager.cs#L30
// Note: asyncOp.completed triggers in the next frame after finishing (so the time isn't precise).
// https://docs.unity3d.com/2020.3/Documentation/ScriptReference/AsyncOperation-completed.html
asyncOp.completed += _ =>
{
_logger?.LogInfo("Finishing '{0}' transaction for '{1}'.", TransactionName, sceneName);

span?.Finish(SpanStatus.Ok);
transaction.Finish(SpanStatus.Ok);
};

return asyncOp;
}
}
#endif
}
65 changes: 65 additions & 0 deletions package-dev/Tests/Runtime/SentryIntegrationsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#if UNITY_2020_3_OR_NEWER
#define SENTRY_SCENE_MANAGER_TRACING_INTEGRATION
#endif

using System;
using System.Collections;
using NUnit.Framework;
using Sentry.Unity.Tests;
using UnityEngine.SceneManagement;
using UnityEngine.TestTools;

namespace Sentry.Unity
{
public class SentryIntegrationsTests : DisabledSelfInitializationTests
{
#if SENTRY_SCENE_MANAGER_TRACING_INTEGRATION
[UnityTest]
public IEnumerator Configure_TranceSampleRateOne_AddsSceneManagerTracingIntegration()
{
var options = new SentryUnityOptions
{
Dsn = "https://[email protected]/5439417",
TracesSampleRate = 1.0f
};

SentryIntegrations.Configure(options);
using var _ = InitSentrySdk(options);

yield return null;

Assert.IsNotNull(SceneManagerAPI.overrideAPI);
Assert.AreEqual(typeof(SceneManagerTracingAPI), SceneManagerAPI.overrideAPI.GetType());
}

// TODO: To be fixed: Currently fails if run after the integration has successfully been added. (because it doesn't get removed)
// [UnityTest]
// public IEnumerator Configure_TranceSampleRateZero_DoesNotAddSceneManagerTracingIntegration()
// {
// var options = new SentryUnityOptions
// {
// Dsn = "https://[email protected]/5439417",
// TracesSampleRate = 0f
// };
//
// SentryIntegrations.Configure(options);
// using var _ = InitSentrySdk(options);
//
// yield return null;
//
// Assert.IsNull(SceneManagerAPI.overrideAPI);
// }

public static IDisposable InitSentrySdk(SentryUnityOptions options)
{
SentryUnity.Init(options);
return new SentryDisposable();
}

private sealed class SentryDisposable : IDisposable
{
public void Dispose() => SentrySdk.Close();
}
#endif
}
}
56 changes: 56 additions & 0 deletions package-dev/Tests/Runtime/SentrySceneTracingIntegrationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#if UNITY_2020_3_OR_NEWER
#define SENTRY_SCENE_MANAGER_TRACING_INTEGRATION
#endif

using System;
using System.Collections;
using NUnit.Framework;
using Sentry.Unity.Tests;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.TestTools;

namespace Sentry.Unity
{
public class SentrySceneTracingIntegrationTests : DisabledSelfInitializationTests
{
#if SENTRY_SCENE_MANAGER_TRACING_INTEGRATION
private SentryUnityOptions _options;
private TestHttpClientHandler _testHttpClientHandler = null!; // Set in Setup
private readonly TimeSpan _eventReceiveTimeout = TimeSpan.FromSeconds(1);

[SetUp]
public void SetUp()
{
_testHttpClientHandler = new TestHttpClientHandler();
_options = new SentryUnityOptions
{
Dsn = "https://[email protected]/5439417",
TracesSampleRate = 1.0f,
CreateHttpClientHandler = () => _testHttpClientHandler
};
}

[UnityTest]
public IEnumerator SceneManagerTracingIntegration_DuringSceneLoad_CreatesTransaction()
{
SentryIntegrations.Configure(_options);
using var _ = SentryIntegrationsTests.InitSentrySdk(_options);

yield return SetupSceneCoroutine("1_Bugfarm");

var triggeredEvent = _testHttpClientHandler.GetEvent(TestEventType.SentryTransaction, _eventReceiveTimeout);
Assert.That(triggeredEvent, Does.Contain(SceneManagerTracingAPI.TransactionName));
}

internal static IEnumerator SetupSceneCoroutine(string sceneName)
{
LogAssert.ignoreFailingMessages = true;
SceneManager.LoadScene(sceneName);

// skip a frame for a Unity to properly load a scene
yield return null;
}
#endif
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "io.sentry.unity.dev.runtimetests",
"rootNamespace": "",
"references": [
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
"io.sentry.unity.dev.runtime"
],
"includePlatforms": [],
"excludePlatforms": [
"Android",
"GameCoreScarlett",
"GameCoreXboxOne",
"iOS",
"LinuxStandalone64",
"CloudRendering",
"Lumin",
"macOSStandalone",
"PS4",
"PS5",
"Stadia",
"Switch",
"tvOS",
"WSA",
"WebGL",
"WindowsStandalone32",
"WindowsStandalone64",
"XboxOne"
],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"Sentry.dll",
"Sentry.Unity.dll",
"Sentry.Unity.Tests.dll",
"nunit.framework.dll"
],
"autoReferenced": false,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
1 change: 1 addition & 0 deletions test/Scripts.Integration.Test/Editor/Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static void BuildIl2CPPPlayer(BuildTarget target, BuildTargetGroup group)
// Make sure the configuration is right.
EditorUserBuildSettings.selectedBuildTargetGroup = group;
PlayerSettings.SetScriptingBackend(group, ScriptingImplementation.IL2CPP);
PlayerSettings.WebGL.compressionFormat = WebGLCompressionFormat.Disabled;
DisableUnityAudio();

var buildPlayerOptions = new BuildPlayerOptions
Expand Down
8 changes: 0 additions & 8 deletions test/Scripts.Integration.Test/Scripts/SmokeTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ private static string GetTestArg()
public static void Configure(SentryUnityOptions options)
{
Debug.Log("SmokeTester.Configure() running");

if (GetTestArg() == null)
{
Debug.Log("SmokeTester.Configure() called but skipped because this is not a SmokeTest (no arg)");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A remnant from having the smoke test as part of the sample project.

return;
}

Debug.Log("SmokeTester setting up");
options.CreateHttpClientHandler = () => t;
_crashedLastRun = () =>
{
Expand Down
76 changes: 68 additions & 8 deletions test/Scripts.Integration.Test/integration-test.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,71 @@
param(
[string] $UnityPath
[string] $UnityVersion,
[string] $Platform,
[switch] $Clean,
[switch] $Repack,
[switch] $Recreate,
[switch] $Rebuild
)

# ./scripts/pack.ps1
./test/Scripts.Integration.Test/extract-package.ps1
./test/Scripts.Integration.Test/create-project.ps1 "$UnityPath"
./test/Scripts.Integration.Test/build-project.ps1 "$UnityPath"
./test/Scripts.Integration.Test/update-sentry.ps1 "$UnityPath"
./test/Scripts.Integration.Test/build-project.ps1 "$UnityPath"
./test/Scripts.Integration.Test/run-smoke-test.ps1 -Smoke
. ./test/Scripts.Integration.Test/globals.ps1

$UnityPath = $null

If ($IsMacOS) {
$UnityPath = "/Applications/Unity/Hub/Editor/$UnityVersion*/Unity.app/"
}

If (-not(Test-Path -Path $UnityPath)) {
Throw "Failed to find Unity at '$UnityPath'"
}

If($Clean) {
Write-Host "Cleanup"
If(Test-Path -Path "package-release.zip") {
Remove-Item -Path "package-release.zip" -Recurse -Force -Confirm:$false
}
If(Test-Path -Path "package-release") {
Remove-Item -Path "package-release" -Recurse -Force -Confirm:$false
}
If(Test-Path -Path $PackageReleaseOutput) {
Remove-Item -Path $PackageReleaseOutput -Recurse -Force -Confirm:$false
}
If(Test-Path -Path $NewProjectPath) {
Remove-Item -Path $NewProjectPath -Recurse -Force -Confirm:$false
}
}

If (-not(Test-Path -Path $PackageReleaseOutput) -Or $Repack) {
Write-Host "Creating Package"
./scripts/pack.ps1
Write-Host "Extracting Package"
./test/Scripts.Integration.Test/extract-package.ps1
}

If (-not(Test-Path -Path "$NewProjectPath") -Or $Recreate) {
Write-Host "Creating Project"
./test/Scripts.Integration.Test/create-project.ps1 "$UnityPath"
Write-Host "Updating Sentry"
./test/Scripts.Integration.Test/update-sentry.ps1 "$UnityPath" -Platform $Platform
}

# If ($Platform -eq "Android") {
# ./test/Scripts.Integration.Test/build-project.ps1 "$UnityPath" -Platform "Android"
# ./scripts/smoke-test-droid.ps1 -IsIntegrationTest
# }

# If ($Platform -eq "iOS") {
# ./test/Scripts.Integration.Test/build-project.ps1 "$UnityPath" -Platform "iOS"
# ./Scripts/smoke-test-ios.ps1 Build -UnityVersion "2022"
# ./Scripts/smoke-test-ios.ps1 Test "iOS 12.4" -IsIntegrationTest
# }

If ($Platform -eq "WebGL") {
If(-not(Test-Path -Path "Samples/IntegrationTest/Build") -Or $Rebuild) {
Write-Host "Building Project"
./test/Scripts.Integration.Test/build-project.ps1 "$UnityPath" -Platform "WebGL"
}

Write-Host "Running Smoke Test"
Start-Process "python3" -ArgumentList @("./Scripts/smoke-test-webgl.py", "Samples/IntegrationTest/Build")
}
2 changes: 2 additions & 0 deletions test/Scripts.Tests/package-release.zip.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ Runtime/Sentry.xml
Runtime/Sentry.xml.meta
Runtime/SentryInitialization.cs
Runtime/SentryInitialization.cs.meta
Runtime/SentryIntegrations.cs
Runtime/SentryIntegrations.cs.meta
Samples~/unity-of-bugs/Scenes.meta
Samples~/unity-of-bugs/Scripts.meta
Samples~/unity-of-bugs/Scenes/1_Bugfarm.unity
Expand Down
Loading