mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
feat: add sentry error logging to dotnet-api and rust crates
This commit is contained in:
parent
8266100155
commit
63777bf810
8 changed files with 86 additions and 38 deletions
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
|
|
|
|||
|
|
@ -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, )",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue