Skip to content

Commit

Permalink
Merge pull request #26 from peppy/add-basic-sentry-support
Browse files Browse the repository at this point in the history
Add basic sentry error reporting support
  • Loading branch information
smoogipoo authored Aug 21, 2023
2 parents 12826fd + 13a9ac3 commit 4c4f1bd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions osu.Server.QueueProcessor/QueueProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using MySqlConnector;
using Newtonsoft.Json;
using osu.Framework.Threading;
using Sentry;
using StackExchange.Redis;
using StatsdClient;

Expand Down Expand Up @@ -83,6 +84,7 @@ protected QueueProcessor(QueueConfiguration config)
/// <param name="cancellation">An optional cancellation token.</param>
public void Run(CancellationToken cancellation = default)
{
using (SentrySdk.Init(setupSentry))
using (new Timer(_ => outputStats(), null, TimeSpan.Zero, TimeSpan.FromSeconds(5)))
using (var cts = new GracefulShutdownSource(cancellation))
{
Expand Down Expand Up @@ -146,6 +148,9 @@ public void Run(CancellationToken cancellation = default)

Error?.Invoke(t.Exception, item);

if (t.Exception != null)
SentrySdk.CaptureException(t.Exception);

Console.WriteLine($"Error processing {item}: {t.Exception}");
attemptRetry(item);
}
Expand All @@ -165,6 +170,7 @@ public void Run(CancellationToken cancellation = default)
{
Interlocked.Increment(ref consecutiveErrors);
Console.WriteLine($"Error dequeueing from queue: {e}");
SentrySdk.CaptureException(e);
}
}

Expand All @@ -184,6 +190,12 @@ public void Run(CancellationToken cancellation = default)
outputStats();
}

private void setupSentry(SentryOptions options)
{
options.Dsn = Environment.GetEnvironmentVariable("SENTRY_DSN");
options.DefaultTags["queue"] = QueueName;
}

private void attemptRetry(T item)
{
item.Failed = false;
Expand Down
1 change: 1 addition & 0 deletions osu.Server.QueueProcessor/osu.Server.QueueProcessor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<PackageReference Include="MySqlConnector" Version="2.1.6" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="ppy.osu.Framework" Version="2022.204.0" />
<PackageReference Include="Sentry" Version="3.35.1" />
<PackageReference Include="StackExchange.Redis" Version="2.2.88" />
</ItemGroup>

Expand Down

0 comments on commit 4c4f1bd

Please sign in to comment.