feat: add sentry error logging to dotnet-api and rust crates

This commit is contained in:
alyssa 2025-02-23 18:49:31 +00:00
parent 8266100155
commit 63777bf810
8 changed files with 86 additions and 38 deletions

View file

@ -31,6 +31,7 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.11" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="5.1.0" />
<PackageReference Include="Sentry" Version="4.13.0" />
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
</ItemGroup>
</Project>

View file

@ -14,6 +14,16 @@ public class Program
await BuildInfoService.LoadVersion();
var host = CreateHostBuilder(args).Build();
var config = host.Services.GetRequiredService<CoreConfig>();
// Initialize Sentry SDK, and make sure it gets dropped at the end
using var _ = SentrySdk.Init(opts =>
{
opts.Dsn = config.SentryUrl ?? "";
opts.Release = BuildInfoService.FullVersion;
opts.AutoSessionTracking = true;
// opts.DisableTaskUnobservedTaskExceptionCapture();
});
await host.Services.GetRequiredService<RedisService>().InitAsync(config);
await host.RunAsync();
}

View file

@ -62,8 +62,13 @@ public class Startup
await ctx.Response.WriteJSON(400, "{\"message\":\"400: Bad Request\",\"code\":0}");
else if (exc.Error is not PKError)
{
await ctx.Response.WriteJSON(500, "{\"message\":\"500: Internal Server Error\",\"code\":0}");
var sentryEvent = new SentryEvent(exc.Error);
SentrySdk.CaptureEvent(sentryEvent);
}
// for some reason, if we don't specifically cast to ModelParseError, it uses the base's ToJson method
else if (exc.Error is ModelParseError fe)
await ctx.Response.WriteJSON(fe.ResponseCode, JsonConvert.SerializeObject(fe.ToJson()));

View file

@ -28,6 +28,12 @@
"Microsoft.AspNetCore.Mvc.Versioning": "5.1.0"
}
},
"Sentry": {
"type": "Direct",
"requested": "[4.13.0, )",
"resolved": "4.13.0",
"contentHash": "Wfw3M1WpFcrYaGzPm7QyUTfIOYkVXQ1ry6p4WYjhbLz9fPwV23SGQZTFDpdox67NHM0V0g1aoQ4YKLm4ANtEEg=="
},
"Serilog.AspNetCore": {
"type": "Direct",
"requested": "[9.0.0, )",