Skip to content

Commit

Permalink
Attach user to sentry later in startup flow
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed May 10, 2022
1 parent a5b454e commit 3338bff
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 2 additions & 0 deletions osu.Game/OsuGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ private void load()
{
dependencies.CacheAs(this);

SentryLogger.AttachUser(API.LocalUser);

dependencies.Cache(osuLogo = new OsuLogo { Alpha = 0 });

// bind config int to database RulesetInfo
Expand Down
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 internal IAPIProvider API { get; protected set; }
protected IAPIProvider API { get; set; }

protected Storage Storage { get; set; }

Expand Down
26 changes: 15 additions & 11 deletions osu.Game/Utils/SentryLogger.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable enable

using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using JetBrains.Annotations;
using osu.Framework.Bindables;
using osu.Framework.Logging;
using osu.Game.Online.API.Requests.Responses;
Expand All @@ -19,10 +21,9 @@ public class SentryLogger : IDisposable
{
private SentryClient sentry;
private Scope sentryScope;
private Exception lastException;
private Exception? lastException;

[UsedImplicitly]
private readonly IBindable<APIUser> localUser;
private IBindable<APIUser>? localUser;

public SentryLogger(OsuGame game)
{
Expand All @@ -40,16 +41,21 @@ public SentryLogger(OsuGame game)
sentryScope = new Scope(options);

Logger.NewEntry += processLogEntry;
}

public void AttachUser(IBindable<APIUser> user)
{
Debug.Assert(localUser == null);

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

private void processLogEntry(LogEntry entry)
Expand Down Expand Up @@ -137,8 +143,6 @@ public void Dispose()
protected virtual void Dispose(bool isDisposing)
{
Logger.NewEntry -= processLogEntry;
sentry = null;
sentryScope = null;
}

#endregion
Expand Down

0 comments on commit 3338bff

Please sign in to comment.