Skip to content

Commit

Permalink
v2.3 Sentry error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
rgwood committed Dec 28, 2021
1 parent e791377 commit 69bab74
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Public domain. Do whatever you like with this code, no attribution needed.
- [ ] Display more project fields?
- [ ] [This is rough](https://github.com/rgwood/RezoningScraper/blob/ca38460e6ffbd177ef842b0362ff3449737bf3a5/RezoningScraper/TokenHelper.cs#L54-L60), there's gotta be a better way to query JSON
- [ ] Consider archiving old versions of projects
- [ ] Hook up to Sentry for error reporting
- [ ] Script deployment (just rsync and cron lol) to a remote server
- [x] Hook up to Sentry for error reporting
- [ ] Script deployment+setup (just rsync and cron lol) to a remote server
- [x] Strip line breaks from project titles - CoV does that sometimes and it breaks the Slack link format.
- [x] Consider excluding `published -> archived` state transitions from Slack. Lots of noise, not particularly useful
27 changes: 25 additions & 2 deletions RezoningScraper/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Spectre.Console;
using Sentry;
using Spectre.Console;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Diagnostics;
Expand Down Expand Up @@ -27,10 +28,32 @@ static async Task<int> Main(string[] args)
description: "Whether to save the API results to database.")
};

rootCommand.Handler = CommandHandler.Create<string, bool, bool>(RunScraper);
rootCommand.Handler = CommandHandler.Create<string, bool, bool>(RunScraperWithSentryExceptionLogging);

return await rootCommand.InvokeAsync(args);
}

// System.CommandLine has extremely annoying exception handling that means we can't do this in Main()
// https://github.com/dotnet/command-line-api/issues/796
static async Task RunScraperWithSentryExceptionLogging(string slackWebhookUrl, bool useCache, bool saveToDb)
{
using var sentry = SentrySdk.Init(o =>
{
o.Dsn = "https://[email protected]/6125607";
o.TracesSampleRate = 1.0; // Capture 100% of transactions
});

try
{
await RunScraper(slackWebhookUrl, useCache, saveToDb);
}
catch (Exception ex)
{
SentrySdk.CaptureException(ex);
throw;
}
}

static async Task RunScraper(string slackWebhookUrl, bool useCache, bool saveToDb)
{
MarkupLine($"[green]Welcome to RezoningScraper v{Assembly.GetExecutingAssembly().GetName().Version}[/]");
Expand Down
3 changes: 2 additions & 1 deletion RezoningScraper/RezoningScraper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>2.2.0.0</Version>
<Version>2.3.0.0</Version>

</PropertyGroup>

Expand All @@ -18,6 +18,7 @@
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.0" />
<PackageReference Include="Polly" Version="7.2.2" />
<PackageReference Include="Sentry" Version="3.12.3" />
<PackageReference Include="Spectre.Console" Version="0.42.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21308.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.14.1" />
Expand Down

0 comments on commit 69bab74

Please sign in to comment.