1
0
mirror of https://github.com/bitwarden/server.git synced 2025-02-22 02:51:33 +01:00

Add sentry logging support. (#240)

This commit is contained in:
David Roth 2018-03-23 18:33:31 +01:00 committed by Kyle Spearrin
parent bf3c01ac46
commit 702d833cea
15 changed files with 44 additions and 7 deletions

View File

@ -142,7 +142,7 @@ namespace Bit.Api
IApplicationLifetime appLifetime,
GlobalSettings globalSettings)
{
loggerFactory.AddSerilog(env, appLifetime, globalSettings, (e) =>
loggerFactory.AddSerilog(app, env, appLifetime, globalSettings, (e) =>
{
var context = e.Properties["SourceContext"].ToString();
if(e.Exception != null && (e.Exception.GetType() == typeof(SecurityTokenValidationException) ||

View File

@ -37,6 +37,9 @@
"uri": "SECRET",
"key": "SECRET"
},
"sentry": {
"dsn": "SECRET"
},
"notificationHub": {
"connectionString": "SECRET",
"hubName": "SECRET"

View File

@ -66,7 +66,7 @@ namespace Bit.Billing
GlobalSettings globalSettings,
ILoggerFactory loggerFactory)
{
loggerFactory.AddSerilog(env, appLifetime, globalSettings, (e) => e.Level >= LogEventLevel.Error);
loggerFactory.AddSerilog(app, env, appLifetime, globalSettings, (e) => e.Level >= LogEventLevel.Error);
if(env.IsDevelopment())
{

View File

@ -33,6 +33,9 @@
"uri": "SECRET",
"key": "SECRET"
},
"sentry": {
"dsn": "SECRET"
},
"notificationHub": {
"connectionString": "SECRET",
"hubName": "SECRET"

View File

@ -72,6 +72,7 @@
<PackageReference Include="IdentityServer4" Version="2.1.2" />
<PackageReference Include="Dapper" Version="1.50.4" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
<PackageReference Include="Serilog.Sinks.Sentry.AspNetCore" Version="2.1.4" />
<PackageReference Include="WindowsAzure.Storage" Version="9.0.0" />
<PackageReference Include="AspNetCoreRateLimit" Version="2.1.0" />
<PackageReference Include="Braintree" Version="3.12.0" />

View File

@ -22,6 +22,7 @@ namespace Bit.Core
public virtual IdentityServerSettings IdentityServer { get; set; } = new IdentityServerSettings();
public virtual DataProtectionSettings DataProtection { get; set; } = new DataProtectionSettings();
public virtual DocumentDbSettings DocumentDb { get; set; } = new DocumentDbSettings();
public virtual SentrySettings Sentry { get; set; } = new SentrySettings();
public virtual NotificationHubSettings NotificationHub { get; set; } = new NotificationHubSettings();
public virtual YubicoSettings Yubico { get; set; } = new YubicoSettings();
public virtual DuoSettings Duo { get; set; } = new DuoSettings();
@ -115,6 +116,11 @@ namespace Bit.Core
public string Key { get; set; }
}
public class SentrySettings
{
public string Dsn { get; set; }
}
public class NotificationHubSettings
{
private string _connectionString;

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;
@ -10,6 +11,7 @@ namespace Bit.Core.Utilities
{
public static ILoggerFactory AddSerilog(
this ILoggerFactory factory,
IApplicationBuilder appBuilder,
IHostingEnvironment env,
IApplicationLifetime appLifetime,
GlobalSettings globalSettings,
@ -32,6 +34,16 @@ namespace Bit.Core.Utilities
config.WriteTo.AzureDocumentDB(new Uri(globalSettings.DocumentDb.Uri), globalSettings.DocumentDb.Key,
timeToLive: TimeSpan.FromDays(7));
}
else if(globalSettings.Sentry != null && CoreHelpers.SettingHasValue(globalSettings.Sentry.Dsn))
{
config.WriteTo.Sentry(globalSettings.Sentry.Dsn)
.Enrich.FromLogContext()
.Enrich.WithProperty("Project", globalSettings.ProjectName)
.Destructure.With<HttpContextDestructingPolicy>()
.Filter.ByExcluding(e => e.Exception?.CheckIfCaptured() == true);
appBuilder.AddSentryContext();
}
else if(CoreHelpers.SettingHasValue(globalSettings.LogDirectory))
{
config.WriteTo.RollingFile($"{globalSettings.LogDirectory}/{globalSettings.ProjectName}/{{Date}}.txt");

View File

@ -81,7 +81,7 @@ namespace Bit.Events
IApplicationLifetime appLifetime,
GlobalSettings globalSettings)
{
loggerFactory.AddSerilog(env, appLifetime, globalSettings, (e) =>
loggerFactory.AddSerilog(app, env, appLifetime, globalSettings, (e) =>
{
var context = e.Properties["SourceContext"].ToString();
if(context.Contains("IdentityServer4.Validation.TokenValidator") ||

View File

@ -23,6 +23,9 @@
"documentDb": {
"uri": "SECRET",
"key": "SECRET"
},
"sentry": {
"dsn": "SECRET"
}
}
}

View File

@ -72,7 +72,7 @@ namespace Bit.Identity
IApplicationLifetime appLifetime,
GlobalSettings globalSettings)
{
loggerFactory.AddSerilog(env, appLifetime, globalSettings, (e) =>
loggerFactory.AddSerilog(app, env, appLifetime, globalSettings, (e) =>
{
var context = e.Properties["SourceContext"].ToString();
if(context.Contains("IdentityServer4.Validation.TokenValidator") ||

View File

@ -33,6 +33,9 @@
"uri": "SECRET",
"key": "SECRET"
},
"sentry": {
"dsn": "SECRET"
},
"notificationHub": {
"connectionString": "SECRET",
"hubName": "SECRET"

View File

@ -66,7 +66,7 @@ namespace Bit.Jobs
GlobalSettings globalSettings)
{
loggerFactory
.AddSerilog(env, appLifetime, globalSettings, e => e.Level >= LogEventLevel.Information)
.AddSerilog(app, env, appLifetime, globalSettings, e => e.Level >= LogEventLevel.Information)
.AddConsole()
.AddDebug();
}

View File

@ -30,6 +30,9 @@
"uri": "SECRET",
"key": "SECRET"
},
"sentry": {
"dsn": "SECRET"
},
"notificationHub": {
"connectionString": "SECRET",
"hubName": "SECRET"

View File

@ -63,7 +63,7 @@ namespace Bit.Scim
var telConfig = app.ApplicationServices.GetService<TelemetryConfiguration>();
telConfig.DisableTelemetry = true;
loggerFactory.AddSerilog(env, appLifetime, globalSettings, (e) => e.Level >= LogEventLevel.Error);
loggerFactory.AddSerilog(app, env, appLifetime, globalSettings, (e) => e.Level >= LogEventLevel.Error);
if(env.IsDevelopment())
{

View File

@ -33,6 +33,9 @@
"uri": "SECRET",
"key": "SECRET"
},
"sentry": {
"dsn": "SECRET"
},
"notificationHub": {
"connectionString": "SECRET",
"hubName": "SECRET"