mirror of
https://github.com/ppy/osu
synced 2024-12-24 15:53:37 +00:00
Add sentry logging
This commit is contained in:
parent
1ed6b23306
commit
2ea90ef98a
@ -4,7 +4,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using osu.Framework;
|
using osu.Framework;
|
||||||
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.IPC;
|
using osu.Game.IPC;
|
||||||
|
|
||||||
@ -20,6 +23,8 @@ namespace osu.Desktop
|
|||||||
|
|
||||||
using (DesktopGameHost host = Host.GetSuitableHost(@"osu", true))
|
using (DesktopGameHost host = Host.GetSuitableHost(@"osu", true))
|
||||||
{
|
{
|
||||||
|
host.ExceptionThrown += handleException;
|
||||||
|
|
||||||
if (!host.IsPrimaryInstance)
|
if (!host.IsPrimaryInstance)
|
||||||
{
|
{
|
||||||
var importer = new ArchiveImportIPCChannel(host);
|
var importer = new ArchiveImportIPCChannel(host);
|
||||||
@ -45,5 +50,22 @@ namespace osu.Desktop
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int allowableExceptions = 1;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allow a maximum of one unhandled exception, per second of execution.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="arg"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static bool handleException(Exception arg)
|
||||||
|
{
|
||||||
|
bool continueExecution = Interlocked.Decrement(ref allowableExceptions) >= 0;
|
||||||
|
|
||||||
|
Logger.Log($"Unhandled exception has been {(continueExecution ? "allowed" : "denied")} with {allowableExceptions} more allowable exceptions.");
|
||||||
|
|
||||||
|
Task.Delay(1000).ContinueWith(_ => Interlocked.Increment(ref allowableExceptions));
|
||||||
|
return Interlocked.Decrement(ref allowableExceptions) >= 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,8 @@ using osu.Game.Skinning;
|
|||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using osu.Game.Overlays.Volume;
|
using osu.Game.Overlays.Volume;
|
||||||
using osu.Game.Screens.Select;
|
using osu.Game.Screens.Select;
|
||||||
|
using osu.Game.Utils;
|
||||||
|
using LogLevel = osu.Framework.Logging.LogLevel;
|
||||||
|
|
||||||
namespace osu.Game
|
namespace osu.Game
|
||||||
{
|
{
|
||||||
@ -65,6 +67,8 @@ namespace osu.Game
|
|||||||
|
|
||||||
private ScreenshotManager screenshotManager;
|
private ScreenshotManager screenshotManager;
|
||||||
|
|
||||||
|
protected RavenLogger RavenLogger;
|
||||||
|
|
||||||
public virtual Storage GetStorageForStableInstall() => null;
|
public virtual Storage GetStorageForStableInstall() => null;
|
||||||
|
|
||||||
private Intro intro
|
private Intro intro
|
||||||
@ -106,6 +110,8 @@ namespace osu.Game
|
|||||||
this.args = args;
|
this.args = args;
|
||||||
|
|
||||||
forwardLoggedErrorsToNotifications();
|
forwardLoggedErrorsToNotifications();
|
||||||
|
|
||||||
|
RavenLogger = new RavenLogger(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ToggleSettings() => settings.ToggleVisibility();
|
public void ToggleSettings() => settings.ToggleVisibility();
|
||||||
@ -150,6 +156,8 @@ namespace osu.Game
|
|||||||
|
|
||||||
dependencies.CacheAs(this);
|
dependencies.CacheAs(this);
|
||||||
|
|
||||||
|
dependencies.Cache(RavenLogger);
|
||||||
|
|
||||||
dependencies.CacheAs(ruleset);
|
dependencies.CacheAs(ruleset);
|
||||||
dependencies.CacheAs<IBindable<RulesetInfo>>(ruleset);
|
dependencies.CacheAs<IBindable<RulesetInfo>>(ruleset);
|
||||||
|
|
||||||
@ -271,6 +279,12 @@ namespace osu.Game
|
|||||||
menu.Push(new PlayerLoader(new ReplayPlayer(s.Replay)));
|
menu.Push(new PlayerLoader(new ReplayPlayer(s.Replay)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
base.Dispose(isDisposing);
|
||||||
|
RavenLogger.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
// this needs to be cached before base.LoadComplete as it is used by MenuCursorContainer.
|
// this needs to be cached before base.LoadComplete as it is used by MenuCursorContainer.
|
||||||
@ -599,6 +613,7 @@ namespace osu.Game
|
|||||||
private void screenAdded(Screen newScreen)
|
private void screenAdded(Screen newScreen)
|
||||||
{
|
{
|
||||||
currentScreen = (OsuScreen)newScreen;
|
currentScreen = (OsuScreen)newScreen;
|
||||||
|
Logger.Log($"Screen changed → {currentScreen}");
|
||||||
|
|
||||||
newScreen.ModePushed += screenAdded;
|
newScreen.ModePushed += screenAdded;
|
||||||
newScreen.Exited += screenRemoved;
|
newScreen.Exited += screenRemoved;
|
||||||
@ -607,6 +622,7 @@ namespace osu.Game
|
|||||||
private void screenRemoved(Screen newScreen)
|
private void screenRemoved(Screen newScreen)
|
||||||
{
|
{
|
||||||
currentScreen = (OsuScreen)newScreen;
|
currentScreen = (OsuScreen)newScreen;
|
||||||
|
Logger.Log($"Screen changed ← {currentScreen}");
|
||||||
|
|
||||||
if (newScreen == null)
|
if (newScreen == null)
|
||||||
Exit();
|
Exit();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -141,6 +142,8 @@ namespace osu.Game.Screens.Select
|
|||||||
{
|
{
|
||||||
if (player != null) return false;
|
if (player != null) return false;
|
||||||
|
|
||||||
|
throw new Exception("this is a test!");
|
||||||
|
|
||||||
// Ctrl+Enter should start map with autoplay enabled.
|
// Ctrl+Enter should start map with autoplay enabled.
|
||||||
if (GetContainingInputManager().CurrentState?.Keyboard.ControlPressed == true)
|
if (GetContainingInputManager().CurrentState?.Keyboard.ControlPressed == true)
|
||||||
{
|
{
|
||||||
|
73
osu.Game/Utils/RavenLogger.cs
Normal file
73
osu.Game/Utils/RavenLogger.cs
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using osu.Framework.Logging;
|
||||||
|
using SharpRaven;
|
||||||
|
using SharpRaven.Data;
|
||||||
|
|
||||||
|
namespace osu.Game.Utils
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Report errors to sentry.
|
||||||
|
/// </summary>
|
||||||
|
public class RavenLogger : IDisposable
|
||||||
|
{
|
||||||
|
private readonly RavenClient raven = new RavenClient("https://5e342cd55f294edebdc9ad604d28bbd3@sentry.io/1255255");
|
||||||
|
|
||||||
|
private readonly List<Task> tasks = new List<Task>();
|
||||||
|
|
||||||
|
public RavenLogger(OsuGame game)
|
||||||
|
{
|
||||||
|
raven.Release = game.Version;
|
||||||
|
|
||||||
|
Logger.NewEntry += entry =>
|
||||||
|
{
|
||||||
|
if (entry.Level < LogLevel.Verbose) return;
|
||||||
|
|
||||||
|
if (entry.Exception != null)
|
||||||
|
queuePendingTask(raven.CaptureAsync(new SentryEvent(entry.Exception)));
|
||||||
|
else
|
||||||
|
raven.AddTrail(new Breadcrumb(entry.Target.ToString(), BreadcrumbType.Navigation) { Message = entry.Message });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void queuePendingTask(Task<string> task)
|
||||||
|
{
|
||||||
|
lock (tasks) tasks.Add(task);
|
||||||
|
task.ContinueWith(_ =>
|
||||||
|
{
|
||||||
|
lock (tasks)
|
||||||
|
tasks.Remove(task);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Disposal
|
||||||
|
|
||||||
|
~RavenLogger()
|
||||||
|
{
|
||||||
|
Dispose(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool isDisposed;
|
||||||
|
|
||||||
|
protected virtual void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
if (isDisposed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
isDisposed = true;
|
||||||
|
lock (tasks) Task.WaitAll(tasks.ToArray(), 5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
@ -18,9 +18,10 @@
|
|||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.1" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.1" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.1.1" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.1.1" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||||
<PackageReference Include="ppy.osu.Framework" Version="2018.801.1" />
|
<PackageReference Include="ppy.osu.Framework" Version="0.0.6500" />
|
||||||
<PackageReference Include="SharpCompress" Version="0.22.0" />
|
<PackageReference Include="SharpCompress" Version="0.22.0" />
|
||||||
<PackageReference Include="NUnit" Version="3.10.1" />
|
<PackageReference Include="NUnit" Version="3.10.1" />
|
||||||
|
<PackageReference Include="SharpRaven" Version="2.4.0" />
|
||||||
<PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" />
|
<PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
Loading…
Reference in New Issue
Block a user