Skip to content

Commit

Permalink
Merge pull request ppy#18218 from peppy/sentry-more-context
Browse files Browse the repository at this point in the history
Add more context to sentry error reports
  • Loading branch information
peppy authored May 12, 2022
2 parents effc924 + b794deb commit 4a4f6ab
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
16 changes: 16 additions & 0 deletions osu.Game/Configuration/OsuConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using osu.Framework.Configuration;
using osu.Framework.Configuration.Tracking;
using osu.Framework.Extensions;
Expand Down Expand Up @@ -164,6 +166,20 @@ protected override void InitialiseDefaults()
SetDefault(OsuSetting.EditorHitAnimations, false);
}

public IDictionary<OsuSetting, string> GetLoggableState() =>
new Dictionary<OsuSetting, string>(ConfigStore.Where(kvp => !keyContainsPrivateInformation(kvp.Key)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value.ToString()));

private static bool keyContainsPrivateInformation(OsuSetting argKey)
{
switch (argKey)
{
case OsuSetting.Token:
return true;
}

return false;
}

public OsuConfigManager(Storage storage)
: base(storage)
{
Expand Down
12 changes: 12 additions & 0 deletions osu.Game/OsuGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using osu.Framework.Bindables;
using osu.Framework.Configuration;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
Expand Down Expand Up @@ -56,6 +57,8 @@
using osu.Game.Users;
using osu.Game.Utils;
using osuTK.Graphics;
using Sentry;
using Logger = osu.Framework.Logging.Logger;

namespace osu.Game
{
Expand Down Expand Up @@ -1197,6 +1200,15 @@ protected override void UpdateAfterChildren()

private void screenChanged(IScreen current, IScreen newScreen)
{
SentrySdk.ConfigureScope(scope =>
{
scope.Contexts[@"screen stack"] = new
{
Current = newScreen?.GetType().ReadableName(),
Previous = current?.GetType().ReadableName(),
};
});

switch (newScreen)
{
case IntroScreen intro:
Expand Down
51 changes: 51 additions & 0 deletions osu.Game/Utils/SentryLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Logging;
using osu.Framework.Statistics;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Database;
using osu.Game.Models;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
using osu.Game.Skinning;
using Sentry;
using Sentry.Protocol;

Expand All @@ -24,8 +33,11 @@ public class SentryLogger : IDisposable

private readonly IDisposable? sentrySession;

private readonly OsuGame game;

public SentryLogger(OsuGame game)
{
this.game = game;
sentrySession = SentrySdk.Init(options =>
{
// Not setting the dsn will completely disable sentry.
Expand Down Expand Up @@ -94,6 +106,45 @@ private void processLogEntry(LogEntry entry)
{
Message = entry.Message,
Level = getSentryLevel(entry.Level),
}, scope =>
{
var beatmap = game.Dependencies.Get<IBindable<WorkingBeatmap>>().Value.BeatmapInfo;

scope.Contexts[@"config"] = new
{
Game = game.Dependencies.Get<OsuConfigManager>().GetLoggableState()
// TODO: add framework config here. needs some consideration on how to expose.
};

game.Dependencies.Get<RealmAccess>().Run(realm =>
{
scope.Contexts[@"realm"] = new
{
Counts = new
{
BeatmapSets = realm.All<BeatmapSetInfo>().Count(),
Beatmaps = realm.All<BeatmapInfo>().Count(),
Files = realm.All<RealmFile>().Count(),
Skins = realm.All<SkinInfo>().Count(),
}
};
});

scope.Contexts[@"global statistics"] = GlobalStatistics.GetStatistics()
.GroupBy(s => s.Group)
.ToDictionary(g => g.Key, items => items.ToDictionary(i => i.Name, g => g.DisplayValue));

scope.Contexts[@"beatmap"] = new
{
Name = beatmap.ToString(),
beatmap.OnlineID,
};

scope.Contexts[@"clocks"] = new
{
Audio = game.Dependencies.Get<MusicController>().CurrentTrack.CurrentTime,
Game = game.Clock.CurrentTime,
};
});
}
else
Expand Down

0 comments on commit 4a4f6ab

Please sign in to comment.