Skip to content

Commit

Permalink
Add local user tracking to sentry reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed May 10, 2022
1 parent 09c21cd commit 64cc6eb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion osu.Game/OsuGameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public virtual string Version

protected MusicController MusicController { get; private set; }

protected IAPIProvider API { get; set; }
protected internal IAPIProvider API { get; protected set; }

protected Storage Storage { get; set; }

Expand Down
17 changes: 17 additions & 0 deletions osu.Game/Utils/SentryLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
using System;
using System.IO;
using System.Net;
using JetBrains.Annotations;
using osu.Framework.Bindables;
using osu.Framework.Logging;
using osu.Game.Online.API.Requests.Responses;
using Sentry;

namespace osu.Game.Utils
Expand All @@ -18,6 +21,9 @@ public class SentryLogger : IDisposable
private Scope sentryScope;
private Exception lastException;

[UsedImplicitly]
private readonly IBindable<APIUser> localUser;

public SentryLogger(OsuGame game)
{
if (!game.IsDeployedBuild) return;
Expand All @@ -34,6 +40,16 @@ public SentryLogger(OsuGame game)
sentryScope = new Scope(options);

Logger.NewEntry += processLogEntry;

localUser = game.API.LocalUser.GetBoundCopy();
localUser.BindValueChanged(user =>
{
sentryScope.User = new User
{
Username = user.NewValue.Username,
Id = user.NewValue.Id.ToString(),
};
});
}

private void processLogEntry(LogEntry entry)
Expand All @@ -50,6 +66,7 @@ private void processLogEntry(LogEntry entry)
if (lastException != null && lastException.Message == exception.Message && exception.StackTrace.StartsWith(lastException.StackTrace, StringComparison.Ordinal)) return;

lastException = exception;

sentry.CaptureEvent(new SentryEvent(exception)
{
Message = entry.Message,
Expand Down

0 comments on commit 64cc6eb

Please sign in to comment.