diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 500d9f9a9..e3b99e61e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -8,7 +8,7 @@ on:
pull_request:
paths:
- - '.github/**/*.yaml'
+ - '.github/**/*.yml'
- 'src/**'
- 'test/**'
- 'sample/**'
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9002bdf0f..803a14f9d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@
### Fixes
- SDK version format correction (#120)
+- Auto compression option is part of drop down (no extra checkbox) (#160)
## 0.0.13
diff --git a/src/Sentry.Unity.Editor/SentryWindow.cs b/src/Sentry.Unity.Editor/SentryWindow.cs
index 82bfb4202..c11a485fa 100644
--- a/src/Sentry.Unity.Editor/SentryWindow.cs
+++ b/src/Sentry.Unity.Editor/SentryWindow.cs
@@ -120,12 +120,11 @@ private void OnGUI()
Options.SampleRate = EditorGUILayout.Slider(
new GUIContent("Event Sample Rate", "What random sample rate to apply. 1.0 captures everything, 0.7 captures 70%."),
Options.SampleRate ?? 1.0f, 0.01f, 1);
- Options.EnableAutoPayloadCompression = EditorGUILayout.Toggle(
- new GUIContent("Compress Payload (Auto)", "The level of which to compress the Sentry event before sending to Sentry (Auto)."),
- Options.EnableAutoPayloadCompression);
- Options.RequestBodyCompressionLevel = (CompressionLevel)EditorGUILayout.EnumPopup(
+
+ Options.RequestBodyCompressionLevel = (CompressionLevelWithAuto)EditorGUILayout.EnumPopup(
new GUIContent("Compress Payload", "The level of which to compress the Sentry event before sending to Sentry."),
Options.RequestBodyCompressionLevel);
+
Options.AttachStacktrace = EditorGUILayout.Toggle(
new GUIContent("Stacktrace For Logs", "Whether to include a stack trace for non error events like logs. " +
"Even when Unity didn't include and no Exception was thrown.."),
diff --git a/src/Sentry.Unity/SentryUnity.cs b/src/Sentry.Unity/SentryUnity.cs
index cb740d2d0..290b3d0e2 100644
--- a/src/Sentry.Unity/SentryUnity.cs
+++ b/src/Sentry.Unity/SentryUnity.cs
@@ -3,17 +3,28 @@
namespace Sentry.Unity
{
+ ///
+ /// Sentry Unity initialization class.
+ ///
public static class SentryUnity
{
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Init(SentryUnityOptions sentryUnityOptions)
- => SentrySdk.Init(sentryUnityOptions);
-
+ ///
+ /// Initializes Sentry Unity SDK while configuring the options.
+ ///
+ /// Callback to configure the options.
public static void Init(Action unitySentryOptionsConfigure)
{
var unitySentryOptions = new SentryUnityOptions();
unitySentryOptionsConfigure.Invoke(unitySentryOptions);
Init(unitySentryOptions);
}
+
+ ///
+ /// Initializes Sentry Unity SDK while providing an options object.
+ ///
+ /// The options object.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static void Init(SentryUnityOptions unitySentryOptions)
+ => SentrySdk.Init(unitySentryOptions);
}
}
diff --git a/src/Sentry.Unity/SentryUnityOptions.cs b/src/Sentry.Unity/SentryUnityOptions.cs
index 7c2807764..e6c129b87 100644
--- a/src/Sentry.Unity/SentryUnityOptions.cs
+++ b/src/Sentry.Unity/SentryUnityOptions.cs
@@ -38,7 +38,30 @@ internal static string GetConfigPath(string? notDefaultConfigName = null)
public bool CaptureInEditor { get; set; } = true; // Lower entry barrier, likely set to false after initial setup.
public bool DebugOnlyInEditor { get; set; } = true;
public SentryLevel DiagnosticsLevel { get; set; } = SentryLevel.Error; // By default logs out Error or higher.
- public bool EnableAutoPayloadCompression { get; set; }
+
+ private CompressionLevelWithAuto _requestBodyCompressionLevel = CompressionLevelWithAuto.Auto;
+
+ public new CompressionLevelWithAuto RequestBodyCompressionLevel
+ {
+ get => _requestBodyCompressionLevel;
+ set
+ {
+ _requestBodyCompressionLevel = value;
+ if (value == CompressionLevelWithAuto.Auto)
+ {
+ // TODO: If WebGL, then NoCompression, else .. optimize (e.g: adapt to platform)
+ // The target platform is known when building the player, so 'auto' should resolve there(here).
+ // Since some platforms don't support GZipping fallback: no compression.
+ base.RequestBodyCompressionLevel = CompressionLevel.NoCompression;
+ }
+ else
+ {
+ // Auto would result in -1 set if not treated before providing the options to the Sentry .NET SDK
+ // DeflateStream would throw System.ArgumentOutOfRangeException
+ base.RequestBodyCompressionLevel = (CompressionLevel)value;
+ }
+ }
+ }
public SentryUnityOptions()
{
@@ -48,12 +71,6 @@ public SentryUnityOptions()
// Uses the game `version` as Release unless the user defined one via the Options
Release ??= Application.version; // TODO: Should we move it out and use via IApplication something?
- // The target platform is known when building the player, so 'auto' should resolve there.
- // Since some platforms don't support GZipping fallback no no compression.
- RequestBodyCompressionLevel = EnableAutoPayloadCompression
- ? CompressionLevel.NoCompression
- : RequestBodyCompressionLevel;
-
Environment = Environment is { } environment
? environment
: Application.isEditor // TODO: Should we move it out and use via IApplication something?
@@ -96,8 +113,7 @@ public void WriteTo(Utf8JsonWriter writer)
writer.WriteNumber("diagnosticsLevel", (int)DiagnosticsLevel);
writer.WriteBoolean("attachStacktrace", AttachStacktrace);
- writer.WriteBoolean("enableAutoPayloadCompression", EnableAutoPayloadCompression);
- writer.WriteNumber("requestBodyCompressionLevel", EnableAutoPayloadCompression ? (int)CompressionLevel.NoCompression : (int)RequestBodyCompressionLevel);
+ writer.WriteNumber("requestBodyCompressionLevel", (int)RequestBodyCompressionLevel);
if (SampleRate != null)
{
@@ -127,8 +143,7 @@ public static SentryUnityOptions FromJson(JsonElement json)
Debug = json.GetPropertyOrNull("debug")?.GetBoolean() ?? true,
DebugOnlyInEditor = json.GetPropertyOrNull("debugOnlyInEditor")?.GetBoolean() ?? true,
DiagnosticsLevel = json.GetEnumOrNull("diagnosticsLevel") ?? SentryLevel.Error,
- RequestBodyCompressionLevel = json.GetEnumOrNull("requestBodyCompressionLevel") ?? CompressionLevel.NoCompression,
- EnableAutoPayloadCompression = json.GetPropertyOrNull("enableAutoPayloadCompression")?.GetBoolean() ?? false,
+ RequestBodyCompressionLevel = json.GetEnumOrNull("requestBodyCompressionLevel") ?? CompressionLevelWithAuto.Auto,
AttachStacktrace = json.GetPropertyOrNull("attachStacktrace")?.GetBoolean() ?? false,
SampleRate = json.GetPropertyOrNull("sampleRate")?.GetSingle() ?? 1.0f,
Release = json.GetPropertyOrNull("release")?.GetString(),
@@ -150,4 +165,27 @@ public void SaveToUnity(string path)
WriteTo(writer);
}
}
+
+ ///
+ /// with an additional value for Automatic
+ ///
+ public enum CompressionLevelWithAuto
+ {
+ ///
+ /// The Unity SDK will attempt to choose the best option for the target player.
+ ///
+ Auto = -1,
+ ///
+ /// The compression operation should be optimally compressed, even if the operation takes a longer time (and CPU) to complete.
+ ///
+ Optimal = CompressionLevel.Optimal,
+ ///
+ /// The compression operation should complete as quickly as possible, even if the resulting data is not optimally compressed.
+ ///
+ Fastest = CompressionLevel.Fastest,
+ ///
+ /// No compression should be performed.
+ ///
+ NoCompression = CompressionLevel.NoCompression,
+ }
}
diff --git a/test/Sentry.Unity.Tests/Stubs/TestApplication.cs b/test/Sentry.Unity.Tests/Stubs/TestApplication.cs
index 19bb73d07..f98a1abb0 100644
--- a/test/Sentry.Unity.Tests/Stubs/TestApplication.cs
+++ b/test/Sentry.Unity.Tests/Stubs/TestApplication.cs
@@ -9,5 +9,10 @@ internal sealed class TestApplication : IApplication
public event Application.LogCallback? LogMessageReceived;
public event Action? Quitting;
public string ActiveSceneName => "TestSceneName";
+
+ private void OnQuitting() => Quitting?.Invoke();
+
+ private void OnLogMessageReceived(string condition, string stacktrace, LogType type)
+ => LogMessageReceived?.Invoke(condition, stacktrace, type);
}
}
diff --git a/test/Sentry.Unity.Tests/UnitySentryOptionsTest.cs b/test/Sentry.Unity.Tests/UnitySentryOptionsTest.cs
index 6fe41a4f6..391c0b550 100644
--- a/test/Sentry.Unity.Tests/UnitySentryOptionsTest.cs
+++ b/test/Sentry.Unity.Tests/UnitySentryOptionsTest.cs
@@ -30,13 +30,12 @@ public void Options_WriteRead_Equals()
var optionsExpected = new SentryUnityOptions
{
Enabled = true,
- Dsn = "http://test.com",
+ Dsn = "https://test.com",
CaptureInEditor = true,
Debug = true,
DebugOnlyInEditor = false,
DiagnosticsLevel = SentryLevel.Info,
- EnableAutoPayloadCompression = false,
- RequestBodyCompressionLevel = CompressionLevel.NoCompression,
+ RequestBodyCompressionLevel = CompressionLevelWithAuto.NoCompression,
AttachStacktrace = true,
SampleRate = 1f,
Release = "release",
@@ -68,7 +67,6 @@ private static void AssertOptions(SentryUnityOptions actual, SentryUnityOptions
Assert.AreEqual(expected.SampleRate, actual.SampleRate);
Assert.AreEqual(expected.Release, actual.Release);
Assert.AreEqual(expected.Environment, actual.Environment);
- Assert.AreEqual(expected.EnableAutoPayloadCompression, actual.EnableAutoPayloadCompression);
Assert.AreEqual(expected.RequestBodyCompressionLevel, actual.RequestBodyCompressionLevel);
}