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

Hub.IsEnabled check in logging integration #210

Merged
merged 7 commits into from
Jun 10, 2021
Merged
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Hub.IsEnabled check in logging integration ([#210](https://github.com/getsentry/sentry-unity/pull/210))

### Features

- Offline caching ([#208](https://github.com/getsentry/sentry-unity/pull/208))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,19 @@ public void Register(IHub hub, SentryOptions sentryOptions)
// Internal for testability
internal void OnLogMessageReceived(string condition, string stackTrace, LogType type)
{
if (_hub is null || !_hub.IsEnabled)
{
return;
}

var debounced = type switch
{
LogType.Error or LogType.Exception or LogType.Assert => ErrorTimeDebounce.Debounced(),
LogType.Log => LogTimeDebounce.Debounced(),
LogType.Warning => WarningTimeDebounce.Debounced(),
_ => true
};
if (!debounced || _hub is null)
if (!debounced)
{
return;
}
Expand Down
28 changes: 28 additions & 0 deletions test/Sentry.Unity.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,34 @@ public IEnumerator BugFarmScene_EventCaptured_IncludesApplicationInEditorOrProdu
actual.Environment);
}

[UnityTest]
public IEnumerator BugFarmScene_MultipleSentryInit_SendEventForTheLatest()
{
yield return SetupSceneCoroutine("1_BugFarmScene");

var sourceEventCapture = new TestEventCapture();
var sourceDsn = "https://94677106febe46b88b9b9ae5efd18a00@o447951.ingest.sentry.io/5439417";
SentryUnity.Init(options =>
{
options.Dsn = sourceDsn;
options.AddIntegration(new UnityApplicationLoggingIntegration(eventCapture: sourceEventCapture));
});

var nextEventCapture = new TestEventCapture();
var nextDsn = "https://a520c186ed684a8aa7d5d334bd7dab52@o447951.ingest.sentry.io/5801250";
SentryUnity.Init(options =>
{
options.Dsn = nextDsn;
options.AddIntegration(new UnityApplicationLoggingIntegration(eventCapture: nextEventCapture));
});

var testBehaviour = new GameObject("TestHolder").AddComponent<TestMonoBehaviour>();
testBehaviour.gameObject.SendMessage(nameof(testBehaviour.TestException));

Assert.AreEqual(0, sourceEventCapture.Events.Count, sourceDsn);
Assert.AreEqual(1, nextEventCapture.Events.Count, nextDsn);
}

private static IEnumerator SetupSceneCoroutine(string sceneName)
{
// load scene with initialized Sentry, SceneManager.LoadSceneAsync(sceneName);
Expand Down