public static void AssertOptions(SentryUnityOptions expected, SentryUnityOptions actual) { Assert.AreEqual(expected.Enabled, actual.Enabled); Assert.AreEqual(expected.Dsn, actual.Dsn); Assert.AreEqual(expected.CaptureInEditor, actual.CaptureInEditor); Assert.AreEqual(expected.EnableLogDebouncing, actual.EnableLogDebouncing); Assert.AreEqual(expected.TracesSampleRate, actual.TracesSampleRate); Assert.AreEqual(expected.AutoSessionTracking, actual.AutoSessionTracking); Assert.AreEqual(expected.AutoSessionTrackingInterval, actual.AutoSessionTrackingInterval); Assert.AreEqual(expected.AttachStacktrace, actual.AttachStacktrace); Assert.AreEqual(expected.MaxBreadcrumbs, actual.MaxBreadcrumbs); Assert.AreEqual(expected.ReportAssembliesMode, actual.ReportAssembliesMode); Assert.AreEqual(expected.SendDefaultPii, actual.SendDefaultPii); Assert.AreEqual(expected.IsEnvironmentUser, actual.IsEnvironmentUser); Assert.AreEqual(expected.MaxCacheItems, actual.MaxCacheItems); Assert.AreEqual(expected.InitCacheFlushTimeout, actual.InitCacheFlushTimeout); Assert.AreEqual(expected.SampleRate, actual.SampleRate); Assert.AreEqual(expected.ShutdownTimeout, actual.ShutdownTimeout); Assert.AreEqual(expected.MaxQueueItems, actual.MaxQueueItems); Assert.AreEqual(expected.Release, actual.Release); Assert.AreEqual(expected.Environment, actual.Environment); Assert.AreEqual(expected.CacheDirectoryPath, actual.CacheDirectoryPath); Assert.AreEqual(expected.Debug, actual.Debug); Assert.AreEqual(expected.DebugOnlyInEditor, actual.DebugOnlyInEditor); Assert.AreEqual(expected.DiagnosticLevel, actual.DiagnosticLevel); }
public void Configure_DefaultConfiguration_EnablesScopeSync() { var options = new SentryUnityOptions(); SentryNativeIos.Configure(options); Assert.True(options.EnableScopeSync); }
public void Configure_DefaultConfiguration_SetsScopeObserver() { var options = new SentryUnityOptions(); SentryNativeIos.Configure(options); Assert.IsAssignableFrom <IosNativeScopeObserver>(options.ScopeObserver); }
public void Configure_DefaultConfiguration_SetsCrashedLastRun() { var options = new SentryUnityOptions(); SentryNativeIos.Configure(options); Assert.IsNotNull(options.CrashedLastRun); }
public void ToSentryUnityOptions_ValueMapping_AreEqual(bool isBuilding, bool enableOfflineCaching) { var expectedOptions = new SentryUnityOptions { Enabled = false, Dsn = "test", CaptureInEditor = false, EnableLogDebouncing = true, TracesSampleRate = 1.0f, AutoSessionTracking = false, AutoSessionTrackingInterval = TimeSpan.FromSeconds(1), AttachStacktrace = true, MaxBreadcrumbs = 1, ReportAssembliesMode = ReportAssembliesMode.None, SendDefaultPii = true, IsEnvironmentUser = true, MaxCacheItems = 1, CacheDirectoryPath = enableOfflineCaching ? _fixture.Application.PersistentDataPath : null, InitCacheFlushTimeout = TimeSpan.FromSeconds(1), SampleRate = 0.5f, ShutdownTimeout = TimeSpan.FromSeconds(1), MaxQueueItems = 1, Release = "testRelease", Environment = "testEnvironment", Debug = true, DebugOnlyInEditor = true, DiagnosticLevel = SentryLevel.Info, }; var scriptableOptions = ScriptableObject.CreateInstance <ScriptableSentryUnityOptions>(); scriptableOptions.Enabled = expectedOptions.Enabled; scriptableOptions.Dsn = expectedOptions.Dsn; scriptableOptions.CaptureInEditor = expectedOptions.CaptureInEditor; scriptableOptions.EnableLogDebouncing = expectedOptions.EnableLogDebouncing; scriptableOptions.TracesSampleRate = expectedOptions.TracesSampleRate; scriptableOptions.AutoSessionTracking = expectedOptions.AutoSessionTracking; scriptableOptions.AutoSessionTrackingInterval = (int)expectedOptions.AutoSessionTrackingInterval.TotalMilliseconds; scriptableOptions.AttachStacktrace = expectedOptions.AttachStacktrace; scriptableOptions.MaxBreadcrumbs = expectedOptions.MaxBreadcrumbs; scriptableOptions.ReportAssembliesMode = expectedOptions.ReportAssembliesMode; scriptableOptions.SendDefaultPii = expectedOptions.SendDefaultPii; scriptableOptions.IsEnvironmentUser = expectedOptions.IsEnvironmentUser; scriptableOptions.MaxCacheItems = expectedOptions.MaxCacheItems; scriptableOptions.EnableOfflineCaching = enableOfflineCaching; scriptableOptions.InitCacheFlushTimeout = (int)expectedOptions.InitCacheFlushTimeout.TotalMilliseconds; scriptableOptions.SampleRate = expectedOptions.SampleRate; scriptableOptions.ShutdownTimeout = (int)expectedOptions.ShutdownTimeout.TotalMilliseconds; scriptableOptions.MaxQueueItems = expectedOptions.MaxQueueItems; scriptableOptions.ReleaseOverride = expectedOptions.Release; scriptableOptions.EnvironmentOverride = expectedOptions.Environment; scriptableOptions.Debug = expectedOptions.Debug; scriptableOptions.DebugOnlyInEditor = expectedOptions.DebugOnlyInEditor; scriptableOptions.DiagnosticLevel = expectedOptions.DiagnosticLevel; var optionsActual = ScriptableSentryUnityOptions.ToSentryUnityOptions(scriptableOptions, isBuilding, _fixture.Application); AssertOptions(expectedOptions, optionsActual); }
public void Configure_NativeIosSupportDisabled_DisabledScopeSync() { var options = new SentryUnityOptions { IosNativeSupportEnabled = false }; SentryNativeIos.Configure(options); Assert.False(options.EnableScopeSync); }
public void Configure_NativeIosSupportDisabled_ObserverIsNull() { var options = new SentryUnityOptions { IosNativeSupportEnabled = false }; SentryNativeIos.Configure(options); Assert.Null(options.ScopeObserver); }
public void SentryUnity_OptionsInvalid_DoesNotInitialize() { var options = new SentryUnityOptions(); // Even tho the defaults are set the DSN is missing making the options invalid for initialization SentryUnity.Init(options); Assert.IsFalse(SentrySdk.IsEnabled); }
public Fixture() { TestLogger = new TestLogger(); Options = new SentryUnityOptions { Debug = true, DiagnosticLevel = SentryLevel.Debug, DiagnosticLogger = TestLogger }; }
public void SentryUnity_OptionsValid_Initializes() { var options = new SentryUnityOptions { Dsn = "https://[email protected]/5439417" }; SentryUnity.Init(options); Assert.IsTrue(SentrySdk.IsEnabled); }
internal static SentryUnityOptions LoadFromJson(TextAsset sentryOptionsTextAsset) { var options = new SentryUnityOptions(); var json = JsonDocument.Parse(sentryOptionsTextAsset.bytes).RootElement; if (json.GetPropertyOrNull("enabled") is { } enabled) { options.Enabled = enabled.GetBoolean(); } if (json.GetPropertyOrNull("dsn") is { } dsn) { options.Dsn = string.Equals(dsn.GetString(), string.Empty) ? null : dsn.GetString(); } if (json.GetPropertyOrNull("captureInEditor") is { } captureInEditor) { options.CaptureInEditor = captureInEditor.GetBoolean(); } if (json.GetPropertyOrNull("debug") is { } debug) { options.Debug = debug.GetBoolean(); } if (json.GetPropertyOrNull("debugOnlyInEditor") is { } debugOnlyInEditor) { options.DebugOnlyInEditor = debugOnlyInEditor.GetBoolean(); } if (json.GetEnumOrNull <SentryLevel>("diagnosticLevel") is { } diagnosticLevel) { options.DiagnosticLevel = diagnosticLevel; } if (json.GetEnumOrNull <CompressionLevelWithAuto>("requestBodyCompressionLevel") is { } requestBodyCompressionLevel) { options.RequestBodyCompressionLevel = requestBodyCompressionLevel; } if (json.GetPropertyOrNull("attachStacktrace") is { } attachStacktrace) { options.AttachStacktrace = attachStacktrace.GetBoolean(); } if (json.GetPropertyOrNull("sampleRate") is { } sampleRate) { options.SampleRate = sampleRate.GetSingle() >= 1.0f ? null : sampleRate.GetSingle(); } if (json.GetPropertyOrNull("release") is { } release) { options.Release = release.GetString(); } if (json.GetPropertyOrNull("environment") is { } environment) { options.Environment = environment.GetString(); } SentryOptionsUtility.TryAttachLogger(options); return(options); }
// Forwarded from SmokeTestOptions.Configure() public static void Configure(SentryUnityOptions options) { Debug.Log("SmokeTester.Configure() called"); options.CreateHttpClientHandler = () => t; _crashedLastRun = () => { if (options.CrashedLastRun != null) { return(options.CrashedLastRun() ? 1 : 0); } return(-2); }; }
// This method gets called when you instantiated the scriptable object and added it to the configuration window public override void Configure(SentryUnityOptions options) { // NOTE: Changes to the options object done here will not affect native crashes. The native SDKs only take // options defined in the Sentry editor configuration window. // Learn more at: https://docs.sentry.io/platforms/unity/native-support/configuration/ options.BeforeSend = sentryEvent => { if (sentryEvent.Tags.ContainsKey("SomeTag")) { // Don't send events with a tag SomeTag to Sentry return(null); } return(sentryEvent); }; }
public void ToSentryOptions_OptionsCreated_AreEqualToNewOptions(bool isBuilding) { var expectedOptions = new SentryUnityOptions(_fixture.Application, isBuilding); var scriptableOptions = ScriptableObject.CreateInstance <ScriptableSentryUnityOptions>(); SentryOptionsUtility.SetDefaults(scriptableOptions); // These are config window specific differences in default values we actually want scriptableOptions.Debug = false; scriptableOptions.DebugOnlyInEditor = false; scriptableOptions.DiagnosticLevel = SentryLevel.Debug; var actualOptions = ScriptableSentryUnityOptions.ToSentryUnityOptions(scriptableOptions, isBuilding, _fixture.Application); AssertOptions(expectedOptions, actualOptions); }
public IEnumerator Init_OptionsAreDefaulted() { yield return(null); var expectedOptions = new SentryUnityOptions { Dsn = string.Empty // The SentrySDK tries to resolve the DSN from the environment when it's null }; SentryUnityOptions?actualOptions = null; using var _ = InitSentrySdk(o => { o.Dsn = string.Empty; // InitSentrySDK already sets a test dsn actualOptions = o; }); Assert.NotNull(actualOptions); ScriptableSentryUnityOptionsTests.AssertOptions(expectedOptions, actualOptions !); }
/// <summary> /// Configures the native Android support. /// </summary> /// <param name="options">The Sentry Unity options to use.</param> public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentryUnityInfo) { if (options.AndroidNativeSupportEnabled) { options.ScopeObserver = new AndroidJavaScopeObserver(options); options.EnableScopeSync = true; options.CrashedLastRun = () => { var crashedLastRun = SentryJava.CrashedLastRun(); if (crashedLastRun is null) { // Could happen if the Android SDK wasn't initialized before the .NET layer. options.DiagnosticLogger? .LogWarning("Unclear from the native SDK if the previous run was a crash. Assuming it was not."); crashedLastRun = false; } else { options.DiagnosticLogger? .LogDebug("Native Android SDK reported: 'crashedLastRun': '{0}'", crashedLastRun); } return(crashedLastRun.Value); }; // When running on Mono, we shouldn't take over the signal handler because its used to propagate exceptions into the VM. // If we take over, a C# null reference ends up crashing the app. if (sentryUnityInfo.IL2CPP) { // At this point Unity has taken the signal handler and will not invoke the original handler (Sentry) // So we register our backend once more to make sure user-defined data is available in the crash report. SentryNative.ReinstallBackend(); } ApplicationAdapter.Instance.Quitting += () => { // Sentry Native is initialized and closed by the Java SDK, no need to call into it directly options.DiagnosticLogger?.LogDebug("Closing the sentry-java SDK"); SentryJava.Close(); }; } }
/// <summary> /// Configures the native Android support. /// </summary> /// <param name="options">The Sentry Unity options to use.</param> public static void Configure(SentryUnityOptions options) { if (options.IosNativeSupportEnabled) { options.ScopeObserver = new IosNativeScopeObserver(options); options.EnableScopeSync = true; options.CrashedLastRun = () => { var crashedLastRun = SentryCocoaBridgeProxy.CrashedLastRun() == 1; options.DiagnosticLogger? .LogDebug("Native iOS SDK reported: 'crashedLastRun': '{0}'", crashedLastRun); return(crashedLastRun); }; ApplicationAdapter.Instance.Quitting += () => { options.DiagnosticLogger?.LogDebug("Closing the sentry-cocoa SDK"); SentryCocoaBridgeProxy.Close(); }; } }
/// <summary> /// Configures the native SDK. /// </summary> /// <param name="options">The Sentry Unity options to use.</param> public static void Configure(SentryUnityOptions options) { if (options.WindowsNativeSupportEnabled) { SentryNativeBridge.Init(options); ApplicationAdapter.Instance.Quitting += () => { options.DiagnosticLogger?.LogDebug("Closing the sentry-native SDK"); SentryNativeBridge.Close(); }; options.ScopeObserver = new NativeScopeObserver(options); options.EnableScopeSync = true; // Note: we must actually call the function now and on every other call use the value we get here. // Additionally, we cannot call this multiple times for the same directory, because the result changes // on subsequent runs. Therefore, we cache the value during the whole runtime of the application. var cacheDirectory = SentryNativeBridge.GetCacheDirectory(options); bool crashedLastRun = false; // In the event the SDK is re-initialized with a different path on disk, we need to track which ones were already read // Similarly we need to cache the value of each call since a subsequent call would return a different value // as the file used on disk to mark it as crashed is deleted after we read it. lock (_perDirectoryCrashInfo) { if (!_perDirectoryCrashInfo.TryGetValue(cacheDirectory, out crashedLastRun)) { crashedLastRun = SentryNativeBridge.HandleCrashedLastRun(options); _perDirectoryCrashInfo.Add(cacheDirectory, crashedLastRun); options.DiagnosticLogger? .LogDebug("Native SDK reported: 'crashedLastRun': '{0}'", crashedLastRun); } } options.CrashedLastRun = () => crashedLastRun; // At this point Unity has taken the signal handler and will not invoke the original handler (Sentry) // So we register our backend once more to make sure user-defined data is available in the crash report. SentryNativeBridge.ReinstallBackend(); } }
public void SetUp() { _fixture = new Fixture(); _hub = new TestHub(); _sentryOptions = new SentryUnityOptions(); }
public void AddNativeOptions(SentryUnityOptions options) { _nativeOptions.CreateFile(Path.Combine(_projectRoot, _optionsPath), options); _pbxProjectType.GetMethod("AddFile", BindingFlags.Public | BindingFlags.Instance) .Invoke(_project, new object[] { _optionsPath, _optionsPath, 1 }); // 1 is PBXSourceTree.Source }
// This method gets called when you instantiated the scriptable object and added it to the configuration window public override void Configure(SentryUnityOptions options) { // NOTE: Native support is already initialized by the time this method runs, so Unity bugs are captured. // That means changes done to the 'options' here will only affect events from C# scripts. SmokeTester.Configure(options); }
public void AddSentryToMain(SentryUnityOptions options) => _nativeMain.AddSentry(Path.Combine(_projectRoot, _mainPath), options.DiagnosticLogger);
public override void Configure(SentryUnityOptions options) => GotCalled = true;