Skip to content

Commit

Permalink
Add minimal sentry logging on mysql errors that were previously dropped
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Jan 8, 2025
1 parent 5b9e1b8 commit 204288a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
14 changes: 9 additions & 5 deletions osu.Server.Spectator/Database/DatabaseAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using System.Threading.Tasks;
using Dapper;
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.JsonWebTokens;
using MySqlConnector;
using osu.Game.Online.Metadata;
Expand All @@ -19,6 +20,12 @@ namespace osu.Server.Spectator.Database
public class DatabaseAccess : IDatabaseAccess
{
private MySqlConnection? openConnection;
private readonly ILogger<DatabaseAccess> logger;

public DatabaseAccess(ILoggerFactory loggerFactory)
{
logger = loggerFactory.CreateLogger<DatabaseAccess>();
}

public async Task<int?> GetUserIdFromTokenAsync(JsonWebToken jwtToken)
{
Expand Down Expand Up @@ -180,12 +187,9 @@ public async Task AddLoginForUserAsync(int userId, string? userIp)
IP = userIp
});
}
catch (MySqlException)
catch (MySqlException ex)
{
// we really don't care about failures in this as it's throwaway logging.
//
// although arguably we should at least be logging failures somewhere because this kind of thing could stop working
// without anyone noticing. same goes for other try-catch methods in this class..
logger.LogWarning(ex, "Could not log login for user {UserId}", userId);
}
}

Expand Down
11 changes: 10 additions & 1 deletion osu.Server.Spectator/Database/DatabaseFactory.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using Microsoft.Extensions.Logging;

namespace osu.Server.Spectator.Database
{
public class DatabaseFactory : IDatabaseFactory
{
public IDatabaseAccess GetInstance() => new DatabaseAccess();
private readonly ILoggerFactory loggerFactory;

public DatabaseFactory(ILoggerFactory loggerFactory)
{
this.loggerFactory = loggerFactory;
}

public IDatabaseAccess GetInstance() => new DatabaseAccess(loggerFactory);
}
}
2 changes: 1 addition & 1 deletion osu.Server.Spectator/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void ConfigureServices(IServiceCollection services)
logging.ClearProviders();
logging.AddConsole();
#if !DEBUG
logging.AddSentry();
logging.AddSentry(options => options.MinimumEventLevel = LogLevel.Warning);
#endif

// IdentityModelEventSource.ShowPII = true;
Expand Down

0 comments on commit 204288a

Please sign in to comment.