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:
parent
bf3c01ac46
commit
702d833cea
@ -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) ||
|
||||
|
@ -37,6 +37,9 @@
|
||||
"uri": "SECRET",
|
||||
"key": "SECRET"
|
||||
},
|
||||
"sentry": {
|
||||
"dsn": "SECRET"
|
||||
},
|
||||
"notificationHub": {
|
||||
"connectionString": "SECRET",
|
||||
"hubName": "SECRET"
|
||||
|
@ -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())
|
||||
{
|
||||
|
@ -33,6 +33,9 @@
|
||||
"uri": "SECRET",
|
||||
"key": "SECRET"
|
||||
},
|
||||
"sentry": {
|
||||
"dsn": "SECRET"
|
||||
},
|
||||
"notificationHub": {
|
||||
"connectionString": "SECRET",
|
||||
"hubName": "SECRET"
|
||||
|
@ -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" />
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
|
@ -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") ||
|
||||
|
@ -23,6 +23,9 @@
|
||||
"documentDb": {
|
||||
"uri": "SECRET",
|
||||
"key": "SECRET"
|
||||
},
|
||||
"sentry": {
|
||||
"dsn": "SECRET"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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") ||
|
||||
|
@ -33,6 +33,9 @@
|
||||
"uri": "SECRET",
|
||||
"key": "SECRET"
|
||||
},
|
||||
"sentry": {
|
||||
"dsn": "SECRET"
|
||||
},
|
||||
"notificationHub": {
|
||||
"connectionString": "SECRET",
|
||||
"hubName": "SECRET"
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -30,6 +30,9 @@
|
||||
"uri": "SECRET",
|
||||
"key": "SECRET"
|
||||
},
|
||||
"sentry": {
|
||||
"dsn": "SECRET"
|
||||
},
|
||||
"notificationHub": {
|
||||
"connectionString": "SECRET",
|
||||
"hubName": "SECRET"
|
||||
|
@ -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())
|
||||
{
|
||||
|
@ -33,6 +33,9 @@
|
||||
"uri": "SECRET",
|
||||
"key": "SECRET"
|
||||
},
|
||||
"sentry": {
|
||||
"dsn": "SECRET"
|
||||
},
|
||||
"notificationHub": {
|
||||
"connectionString": "SECRET",
|
||||
"hubName": "SECRET"
|
||||
|
Loading…
Reference in New Issue
Block a user