-
-
Notifications
You must be signed in to change notification settings - Fork 57
feat: scene-load transctions based on SceneManagerAPI #768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 abd5f1f
Update package-dev/Runtime/SentryInitialization.cs
vaind c6bf27e
merged main
bitsandfoxes 2049f5c
creating span for loading
bitsandfoxes f63bb25
Merge branch 'main' into feat/scene-load-tx
bitsandfoxes 40c06ff
capturing scene load transaction during startup
bitsandfoxes b048549
refactored the self initialization flag
bitsandfoxes fd475fb
creating spans through runtime initialzation and added test setup
bitsandfoxes f359157
finished startup capture & added tests
bitsandfoxes 5c48b23
tweaked tests
bitsandfoxes f810587
tests & naming
bitsandfoxes 510329c
test asmdef editor exclusive
bitsandfoxes 9183831
asmdef for runtime tests only
bitsandfoxes eec3fbd
removed argument check in smoketest configure
bitsandfoxes 779632d
logging cleanup
bitsandfoxes 40bdd79
disabling auto session tracking on WebGL
bitsandfoxes 2f71c0a
removing expected session from smoketest
bitsandfoxes bcd55a9
initialize later on webgl
bitsandfoxes 74a520c
Merge branch 'main' into feat/scene-load-tx
bitsandfoxes 9eefb51
Revert "Merge branch 'main' into feat/scene-load-tx"
bitsandfoxes 152adbe
2020 symbol upload expectations
bitsandfoxes 53c8279
renamed runtime spans
bitsandfoxes 26dcf4a
span remame
bitsandfoxes 99f4291
uncompressed webgl builds for local convenience
bitsandfoxes d97e3da
disabling runtime tracing on WebGL
bitsandfoxes f55d0cf
removed jetbrains annotations
bitsandfoxes 79e6d68
unity 2020.3 guard
bitsandfoxes 7364951
fixed broken merge
bitsandfoxes fbabbcb
rest of the merge
bitsandfoxes b4d5868
Merge branch 'main' into feat/scene-load-tx
bitsandfoxes c57c4c2
Updated CHANGELOG.md
bitsandfoxes 7a4e7c6
Merge branch 'main' into feat/scene-load-tx
bitsandfoxes 10b9c35
just scene loading
bitsandfoxes 861d01e
Updated CHANGELOG.md
bitsandfoxes 1d594f6
cleanup
bitsandfoxes 8551d08
cleanup #2
bitsandfoxes eb2c2dd
logging
bitsandfoxes d000e57
revolved broken class naming
bitsandfoxes 93de324
fixed span names
bitsandfoxes 0e3d9aa
removed builder changes
bitsandfoxes bff3edd
test using dummy dsn
bitsandfoxes ac193c1
added dev-only comment to local integration test script
bitsandfoxes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,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: | ||
bitsandfoxes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// 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 | ||
} |
This file contains hidden or 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,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", | ||
bitsandfoxes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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
56
package-dev/Tests/Runtime/SentrySceneTracingIntegrationTests.cs
This file contains hidden or 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,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 | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
package-dev/Tests/Runtime/io.sentry.unity.dev.runtimetests.asmdef
This file contains hidden or 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,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 | ||
} |
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -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)"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = () => | ||
{ | ||
|
This file contains hidden or 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,11 +1,71 @@ | ||
param( | ||
bitsandfoxes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
[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") | ||
} |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.