Skip to content
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

feat: Runtime Init instrumentation #991

Merged
merged 47 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 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
80b9cc4
runtime init hooks
bitsandfoxes Sep 28, 2022
2ccf4df
Updated CHANGELOG.md
bitsandfoxes Sep 28, 2022
6a914bb
merge
bitsandfoxes Sep 29, 2022
880aaae
Updated CHANGELOG.md
bitsandfoxes Sep 29, 2022
42cc29a
span naming
bitsandfoxes Sep 30, 2022
1c858f3
setting span name/desc
bitsandfoxes Sep 30, 2022
eb2fab0
first scene load name tweak
bitsandfoxes Sep 30, 2022
edcab88
cleanup
bitsandfoxes Sep 30, 2022
83ef604
cleanup
bitsandfoxes Oct 5, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Features

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

### Dependencies
Expand Down
19 changes: 19 additions & 0 deletions package-dev/Runtime/SentryInitialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#endif

using System;
using Sentry.Extensibility;
#if UNITY_2020_3_OR_NEWER
using System.Buffers;
using System.Runtime.InteropServices;
Expand All @@ -40,6 +41,12 @@ namespace Sentry.Unity
{
public static class SentryInitialization
{
private const string StartupTransactionOperation = "app.start";
public static ISpan InitSpan;
private const string InitSpanOperation = "runtime.init";
public static ISpan SubSystemRegistrationSpan;
private const string SubSystemSpanOperation = "runtime.init.subsystem";

#if SENTRY_WEBGL
// On WebGL SubsystemRegistration is too early for the UnityWebRequestTransport and errors with 'URI empty'
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
Expand Down Expand Up @@ -83,6 +90,18 @@ public static void Init()
{
SentrySdk.CaptureException(nativeInitException);
}

#if !SENTRY_WEBGL
options.DiagnosticLogger?.LogInfo("Creating '{0}' transaction for runtime initialization.", StartupTransactionOperation);

var runtimeStartTransaction = SentrySdk.StartTransaction("runtime.initialization", StartupTransactionOperation);
SentrySdk.ConfigureScope(scope => scope.Transaction = runtimeStartTransaction);

options.DiagnosticLogger?.LogDebug("Creating '{0}' span.", InitSpanOperation);
InitSpan = runtimeStartTransaction.StartChild(InitSpanOperation, "runtime initialization");
options.DiagnosticLogger?.LogDebug("Creating '{0}' span.", SubSystemSpanOperation);
SubSystemRegistrationSpan = InitSpan.StartChild(SubSystemSpanOperation, "subsystem registration");
#endif
}
}
}
Expand Down
102 changes: 102 additions & 0 deletions package-dev/Runtime/SentryIntegrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
#define SENTRY_SCENE_MANAGER_TRACING_INTEGRATION
#endif

#if !UNITY_EDITOR
#if UNITY_WEBGL
#define SENTRY_WEBGL
#endif
#endif

using Sentry.Extensibility;
using Sentry.Integrations;
using UnityEngine;
Expand All @@ -16,6 +22,10 @@ public static void Configure(SentryUnityOptions options)
#if SENTRY_SCENE_MANAGER_TRACING_INTEGRATION
if (options.TracesSampleRate > 0.0)
{
// On WebGL the SDK initializes on BeforeScene so the Startup Tracing won't work properly. https://github.com/getsentry/sentry-unity/issues/1000
#if !SENTRY_WEBGL
options.AddIntegration(new StartupTracingIntegration());
#endif
options.AddIntegration(new SceneManagerTracingIntegration());
}
else
Expand All @@ -26,6 +36,98 @@ public static void Configure(SentryUnityOptions options)
}
}

#if !SENTRY_WEBGL
public class StartupTracingIntegration : ISdkIntegration
{
private static ISpan AfterAssembliesSpan;
private const string AfterAssembliesSpanOperation = "runtime.init.afterassemblies";
private static ISpan SplashScreenSpan;
private const string SplashScreenSpanOperation = "runtime.init.splashscreen";
private static ISpan FirstSceneLoadSpan;
private const string FirstSceneLoadSpanOperation = "runtime.init.firstscene";

// Flag to make sure we create spans through the runtime initialization only once
private static bool StartupAlreadyCaptured;
private static bool IntegrationRegistered;

private static IDiagnosticLogger Logger;

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

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)]
public static void AfterAssembliesLoaded()
{
if (!IntegrationRegistered || StartupAlreadyCaptured)
{
return;
}

SentryInitialization.SubSystemRegistrationSpan?.Finish(SpanStatus.Ok);
SentryInitialization.SubSystemRegistrationSpan = null;

Logger?.LogDebug("Creating '{0}' span.", AfterAssembliesSpanOperation);
AfterAssembliesSpan = SentryInitialization.InitSpan?.StartChild(AfterAssembliesSpanOperation, "after assemblies");
}

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)]
public static void BeforeSplashScreen()
{
if (!IntegrationRegistered || StartupAlreadyCaptured)
{
return;
}

AfterAssembliesSpan?.Finish(SpanStatus.Ok);
AfterAssembliesSpan = null;

Logger?.LogDebug("Creating '{0}' span.", SplashScreenSpanOperation);
SplashScreenSpan = SentryInitialization.InitSpan?.StartChild(SplashScreenSpanOperation, "splashscreen");
}

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
public static void BeforeSceneLoad()
{
if (!IntegrationRegistered || StartupAlreadyCaptured)
{
return;
}

SplashScreenSpan?.Finish(SpanStatus.Ok);
SplashScreenSpan = null;

Logger?.LogDebug("Creating '{0}' span.", FirstSceneLoadSpanOperation);
FirstSceneLoadSpan = SentryInitialization.InitSpan?.StartChild(FirstSceneLoadSpanOperation, "first scene load");
}

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
public static void AfterSceneLoad()
{
if (!IntegrationRegistered || StartupAlreadyCaptured)
{
return;
}

FirstSceneLoadSpan?.Finish(SpanStatus.Ok);
FirstSceneLoadSpan = null;

SentryInitialization.InitSpan?.Finish(SpanStatus.Ok);
SentryInitialization.InitSpan = null;

Logger?.LogInfo("Finishing '{0}' transaction.", SentryInitialization.StartupTransactionOperation);
SentrySdk.ConfigureScope(s =>
{
s.Transaction?.Finish(SpanStatus.Ok);
});

StartupAlreadyCaptured = true;
}
}
#endif

#if SENTRY_SCENE_MANAGER_TRACING_INTEGRATION
public class SceneManagerTracingIntegration : ISdkIntegration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public IEnumerator SceneManagerTracingIntegration_DuringSceneLoad_CreatesTransac
yield return SetupSceneCoroutine("1_Bugfarm");

var triggeredEvent = _testHttpClientHandler.GetEvent(TestEventType.SentryTransaction, _eventReceiveTimeout);

Assert.That(triggeredEvent, Does.Contain(SceneManagerTracingAPI.TransactionOperation));
}

Expand Down
6 changes: 3 additions & 3 deletions test/Scripts.Integration.Test/integration-test.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ┌───────────────────────────────────────────────────┐ #
# │ This script is for local use only, │ #
# ┌───────────────────────────────────────────────────┐ #
# │ This script is for local use only, │ #
# │ utilizing the scripts locally we use in CI. │ #
# └───────────────────────────────────────────────────┘ #
# └───────────────────────────────────────────────────┘ #

param(
[string] $UnityVersion,
Expand Down