-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Sitko.Core.App; | ||
|
||
namespace Sitko.Core.Sentry; | ||
|
||
public static class ApplicationExtensions | ||
{ | ||
public static Application AddSentry(this Application application, | ||
Action<IApplicationContext, SentryModuleOptions> configure, string? optionsKey = null) => | ||
application.AddModule<SentryModule, SentryModuleOptions>(configure, optionsKey); | ||
|
||
public static Application AddSentry(this Application application, | ||
Action<SentryModuleOptions>? configure = null, string? optionsKey = null) => | ||
application.AddModule<SentryModule, SentryModuleOptions>(configure, optionsKey); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Hosting; | ||
using Sentry.AspNetCore; | ||
using Sitko.Core.App; | ||
|
||
namespace Sitko.Core.Sentry; | ||
|
||
public class SentryModule : BaseApplicationModule<SentryModuleOptions>, | ||
IHostBuilderModule<SentryModuleOptions> | ||
{ | ||
public override string OptionsKey => "Sentry"; | ||
|
||
public void ConfigureHostBuilder(IApplicationContext context, IHostBuilder hostBuilder, SentryModuleOptions startupOptions) => | ||
hostBuilder.ConfigureWebHostDefaults(webHostBuilder => | ||
{ | ||
webHostBuilder.UseSentry(builder => | ||
{ | ||
startupOptions.ConfigureSentry?.Invoke(context, builder, startupOptions); | ||
builder.AddSentryOptions(o => | ||
{ | ||
o.Dsn = startupOptions.Dsn; | ||
o.Debug = startupOptions.EnableDebug; | ||
o.TracesSampleRate = startupOptions.TracesSampleRate; | ||
}); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using FluentValidation; | ||
using Sentry.AspNetCore; | ||
using Sitko.Core.App; | ||
|
||
namespace Sitko.Core.Sentry; | ||
|
||
public class SentryModuleOptions : BaseModuleOptions | ||
{ | ||
public string Dsn { get; set; } = ""; | ||
public bool EnableDebug { get; set; } | ||
public double TracesSampleRate { get; set; } = 1.0; | ||
public Action<IApplicationContext, ISentryBuilder, SentryModuleOptions>? ConfigureSentry { get; set; } | ||
} | ||
|
||
public class SentryModuleOptionsValidator : AbstractValidator<SentryModuleOptions> | ||
{ | ||
public SentryModuleOptionsValidator() | ||
{ | ||
RuleFor(options => options.Dsn).NotEmpty().WithMessage("Provide Sentry DSN"); | ||
RuleFor(options => options.TracesSampleRate).GreaterThan(0).WithMessage("Traces Sample Rate should be greater than zero"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<ItemGroup> | ||
<PackageReference Include="Sentry.AspNetCore" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Sitko.Core.App.Web\Sitko.Core.App.Web.csproj" /> | ||
</ItemGroup> | ||
</Project> |