Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/Sentry.Unity.Android/BreadcrumbExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static AndroidJavaObject ToJavaSentryLevel(this BreadcrumbLevel level)
using var javaSentryLevel = new AndroidJavaClass("io.sentry.SentryLevel");
return level switch
{
BreadcrumbLevel.Critical => javaSentryLevel.GetStatic<AndroidJavaObject>("FATAL"),
BreadcrumbLevel.Fatal => javaSentryLevel.GetStatic<AndroidJavaObject>("FATAL"),
BreadcrumbLevel.Error => javaSentryLevel.GetStatic<AndroidJavaObject>("ERROR"),
BreadcrumbLevel.Warning => javaSentryLevel.GetStatic<AndroidJavaObject>("WARNING"),
BreadcrumbLevel.Debug => javaSentryLevel.GetStatic<AndroidJavaObject>("DEBUG"),
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.Unity.iOS/NativeScopeObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal static int GetBreadcrumbLevel(BreadcrumbLevel breadcrumbLevel) =>
BreadcrumbLevel.Info => 2,
BreadcrumbLevel.Warning => 3,
BreadcrumbLevel.Error => 4,
BreadcrumbLevel.Critical => 5,
BreadcrumbLevel.Fatal => 5,
_ => 0
};
}
52 changes: 52 additions & 0 deletions src/Sentry.Unity/Integrations/LifeCycleIntegration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Sentry.Extensibility;
using Sentry.Integrations;

namespace Sentry.Unity.Integrations;

internal class LifeCycleIntegration : ISdkIntegration
{
private readonly SentryMonoBehaviour _sentryMonoBehaviour;
private readonly IApplication _application;

public LifeCycleIntegration(SentryMonoBehaviour sentryMonoBehaviour, IApplication? application = null)
{
_sentryMonoBehaviour = sentryMonoBehaviour;
_application = application ?? ApplicationAdapter.Instance;
}

public void Register(IHub hub, SentryOptions options)
{
if (!options.AutoSessionTracking)
{
return;
}

_sentryMonoBehaviour.ApplicationResuming += () =>
{
if (hub.IsSessionActive)
{
options.DiagnosticLogger?.LogDebug("Resuming session.");
hub.ResumeSession();
}
else
{
options.DiagnosticLogger?.LogDebug("No active session to resume found. Starting a new session.");
hub.StartSession();
}
};
_sentryMonoBehaviour.ApplicationPausing += () =>
{
if (hub.IsSessionActive)
{
options.DiagnosticLogger?.LogDebug("Pausing session.");
hub.PauseSession();
}
// else
// {
// // The SDK captured an unhandled exception and automatically ended the session
// }
};

_application.Quitting += () => hub.EndSession();
}
}
33 changes: 0 additions & 33 deletions src/Sentry.Unity/Integrations/SessionIntegration.cs

This file was deleted.

4 changes: 3 additions & 1 deletion src/Sentry.Unity/Integrations/UnityErrorLogException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public SentryException ToSentryException()
Mechanism = new Mechanism
{
Handled = true,
Type = "unity.log"
Type = "Debug.LogError",
Synthetic = true,
Data = { {Mechanism.TerminalKey, false} }
}
};
}
Expand Down
7 changes: 3 additions & 4 deletions src/Sentry.Unity/Integrations/UnityLogHandlerIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ internal void CaptureException(Exception exception, UnityEngine.Object? context)
// NOTE: This might not be entirely true, as a user could as well call `Debug.LogException`
// and expect a handled exception but it is not possible for us to differentiate
// https://docs.sentry.io/platforms/unity/troubleshooting/#unhandled-exceptions---debuglogexception
exception.Data[Mechanism.HandledKey] = false;
exception.Data[Mechanism.MechanismKey] = "Unity.LogException";
exception.SetSentryMechanism("Unity.LogException", handled: false, terminal: false);
_ = _hub.CaptureException(exception);
}

Expand All @@ -97,9 +96,9 @@ private void OnQuitting()
// 'OnQuitting' is invoked even when an uncaught exception happens in the ART. To make sure the .NET
// SDK checks with the native layer on restart if the previous run crashed (through the CrashedLastRun callback)
// we'll just pause sessions on shutdown. On restart they can be closed with the right timestamp and as 'exited'.
if (_sentryOptions?.AutoSessionTracking is true)
if (_sentryOptions?.AutoSessionTracking is true && _hub?.IsSessionActive is true)
{
_hub?.PauseSession();
_hub.PauseSession();
}
_hub?.FlushAsync(_sentryOptions?.ShutdownTimeout ?? TimeSpan.FromSeconds(1)).GetAwaiter().GetResult();
}
Expand Down
24 changes: 3 additions & 21 deletions src/Sentry.Unity/SentrySdk.Dotnet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,27 +324,6 @@ public static void CaptureFeedback(string message, string? contactEmail = null,
=> Sentry.SentrySdk.CaptureFeedback(new SentryFeedback(message, contactEmail, name, replayId, url, associatedEventId),
scope, hint);

/// <summary>
/// Captures a user feedback.
/// </summary>
/// <param name="userFeedback">The user feedback to send to Sentry.</param>
[DebuggerStepThrough]
[Obsolete("Use CaptureFeedback instead.")]
public static void CaptureUserFeedback(UserFeedback userFeedback)
=> Sentry.SentrySdk.CaptureUserFeedback(userFeedback);

/// <summary>
/// Captures a user feedback.
/// </summary>
/// <param name="eventId">The event Id.</param>
/// <param name="email">The user email.</param>
/// <param name="comments">The user comments.</param>
/// <param name="name">The optional username.</param>
[DebuggerStepThrough]
[Obsolete("Use CaptureFeedback instead.")]
public static void CaptureUserFeedback(SentryId eventId, string email, string comments, string? name = null)
=> Sentry.SentrySdk.CaptureUserFeedback(new UserFeedback(eventId, name, email, comments));

/// <summary>
/// Captures a transaction.
/// </summary>
Expand Down Expand Up @@ -531,6 +510,9 @@ public static void PauseSession()
public static void ResumeSession()
=> Sentry.SentrySdk.ResumeSession();

/// <inheritdoc cref="IHub.IsSessionActive"/>
public static bool IsSessionActive { [DebuggerStepThrough] get => Sentry.SentrySdk.IsSessionActive; }

/// <summary>
/// Deliberately crashes an application, which is useful for testing and demonstration purposes.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.Unity/SentryUnityOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ internal SentryUnityOptions(IApplication? application = null,
AddIntegration(new UnityBeforeSceneLoadIntegration());
AddIntegration(new SceneManagerIntegration());
AddIntegration(new SceneManagerTracingIntegration());
AddIntegration(new SessionIntegration(behaviour));
AddIntegration(new LifeCycleIntegration(behaviour));
AddIntegration(new TraceGenerationIntegration(behaviour));

AddExceptionFilter(new UnityBadGatewayExceptionFilter());
Expand Down
2 changes: 1 addition & 1 deletion src/sentry-dotnet
Submodule sentry-dotnet updated 292 files
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Sentry.Unity.Tests;

public class SessionIntegrationTests
public class LifeCycleIntegrationTests
{
[UnityTest]
public IEnumerator SessionIntegration_Init_SentryMonoBehaviourCreated()
Expand Down
8 changes: 2 additions & 6 deletions test/Sentry.Unity.Tests/Stubs/TestHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ public void CaptureFeedback(SentryFeedback feedback, Scope? scope = null, Sentry
throw new NotImplementedException();
}

[Obsolete("Obsolete")]
public void CaptureUserFeedback(UserFeedback userFeedback)
{
throw new NotImplementedException();
}

public void CaptureTransaction(SentryTransaction transaction) =>
_capturedTransactions.Add(transaction);

Expand Down Expand Up @@ -181,6 +175,8 @@ public void EndSession(SessionEndStatus status = SessionEndStatus.Exited)
// TODO: test sessions
}

public bool IsSessionActive { get; }

public SentryId CaptureEvent(SentryEvent evt, Action<Scope> configureScope)
{
throw new NotImplementedException();
Expand Down
2 changes: 1 addition & 1 deletion test/Sentry.Unity.iOS.Tests/NativeScopeObserverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void GetTimestamp_ReturnStringConformsToISO8601()
[TestCase(BreadcrumbLevel.Info, 2)]
[TestCase(BreadcrumbLevel.Warning, 3)]
[TestCase(BreadcrumbLevel.Error, 4)]
[TestCase(BreadcrumbLevel.Critical, 5)]
[TestCase(BreadcrumbLevel.Fatal, 5)]
public void GetBreadcrumbLevel_TestCases(BreadcrumbLevel level, int expectedNativeLevel)
{
var actualLevel = NativeScopeObserver.GetBreadcrumbLevel(level);
Expand Down