diff --git a/src/Api/Startup.cs b/src/Api/Startup.cs
index 75e109e47d..c545b323c0 100644
--- a/src/Api/Startup.cs
+++ b/src/Api/Startup.cs
@@ -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) ||
diff --git a/src/Api/appsettings.json b/src/Api/appsettings.json
index 02fc9b24e2..d682e8f865 100644
--- a/src/Api/appsettings.json
+++ b/src/Api/appsettings.json
@@ -37,6 +37,9 @@
"uri": "SECRET",
"key": "SECRET"
},
+ "sentry": {
+ "dsn": "SECRET"
+ },
"notificationHub": {
"connectionString": "SECRET",
"hubName": "SECRET"
diff --git a/src/Billing/Startup.cs b/src/Billing/Startup.cs
index a0fbc3f071..c218a206d3 100644
--- a/src/Billing/Startup.cs
+++ b/src/Billing/Startup.cs
@@ -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())
{
diff --git a/src/Billing/appsettings.json b/src/Billing/appsettings.json
index 06c1ff718e..7ae4ac0241 100644
--- a/src/Billing/appsettings.json
+++ b/src/Billing/appsettings.json
@@ -33,6 +33,9 @@
"uri": "SECRET",
"key": "SECRET"
},
+ "sentry": {
+ "dsn": "SECRET"
+ },
"notificationHub": {
"connectionString": "SECRET",
"hubName": "SECRET"
diff --git a/src/Core/Core.csproj b/src/Core/Core.csproj
index 4848e3a947..740d920d4c 100644
--- a/src/Core/Core.csproj
+++ b/src/Core/Core.csproj
@@ -72,6 +72,7 @@
+
diff --git a/src/Core/GlobalSettings.cs b/src/Core/GlobalSettings.cs
index f1367b4723..2e71e3550f 100644
--- a/src/Core/GlobalSettings.cs
+++ b/src/Core/GlobalSettings.cs
@@ -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;
diff --git a/src/Core/Utilities/LoggerFactoryExtensions.cs b/src/Core/Utilities/LoggerFactoryExtensions.cs
index 81d8ea7d09..7816ff88ca 100644
--- a/src/Core/Utilities/LoggerFactoryExtensions.cs
+++ b/src/Core/Utilities/LoggerFactoryExtensions.cs
@@ -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()
+ .Filter.ByExcluding(e => e.Exception?.CheckIfCaptured() == true);
+
+ appBuilder.AddSentryContext();
+ }
else if(CoreHelpers.SettingHasValue(globalSettings.LogDirectory))
{
config.WriteTo.RollingFile($"{globalSettings.LogDirectory}/{globalSettings.ProjectName}/{{Date}}.txt");
diff --git a/src/Events/Startup.cs b/src/Events/Startup.cs
index 22ced478b6..7743434e31 100644
--- a/src/Events/Startup.cs
+++ b/src/Events/Startup.cs
@@ -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") ||
diff --git a/src/Events/appsettings.json b/src/Events/appsettings.json
index 0e6e815724..7d5ebc123c 100644
--- a/src/Events/appsettings.json
+++ b/src/Events/appsettings.json
@@ -23,6 +23,9 @@
"documentDb": {
"uri": "SECRET",
"key": "SECRET"
+ },
+ "sentry": {
+ "dsn": "SECRET"
}
}
}
diff --git a/src/Identity/Startup.cs b/src/Identity/Startup.cs
index be6ad0f979..511ae6d5b2 100644
--- a/src/Identity/Startup.cs
+++ b/src/Identity/Startup.cs
@@ -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") ||
diff --git a/src/Identity/appsettings.json b/src/Identity/appsettings.json
index 363daaeb6b..26dccd516a 100644
--- a/src/Identity/appsettings.json
+++ b/src/Identity/appsettings.json
@@ -33,6 +33,9 @@
"uri": "SECRET",
"key": "SECRET"
},
+ "sentry": {
+ "dsn": "SECRET"
+ },
"notificationHub": {
"connectionString": "SECRET",
"hubName": "SECRET"
diff --git a/src/Jobs/Startup.cs b/src/Jobs/Startup.cs
index 6d5fcd5908..fdbafa2400 100644
--- a/src/Jobs/Startup.cs
+++ b/src/Jobs/Startup.cs
@@ -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();
}
diff --git a/src/Jobs/appsettings.json b/src/Jobs/appsettings.json
index 936e68dedd..968ae829f8 100644
--- a/src/Jobs/appsettings.json
+++ b/src/Jobs/appsettings.json
@@ -30,6 +30,9 @@
"uri": "SECRET",
"key": "SECRET"
},
+ "sentry": {
+ "dsn": "SECRET"
+ },
"notificationHub": {
"connectionString": "SECRET",
"hubName": "SECRET"
diff --git a/src/Scim/Startup.cs b/src/Scim/Startup.cs
index 79e50a8f3e..523473e900 100644
--- a/src/Scim/Startup.cs
+++ b/src/Scim/Startup.cs
@@ -63,7 +63,7 @@ namespace Bit.Scim
var telConfig = app.ApplicationServices.GetService();
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())
{
diff --git a/src/Scim/appsettings.json b/src/Scim/appsettings.json
index 06c1ff718e..7ae4ac0241 100644
--- a/src/Scim/appsettings.json
+++ b/src/Scim/appsettings.json
@@ -33,6 +33,9 @@
"uri": "SECRET",
"key": "SECRET"
},
+ "sentry": {
+ "dsn": "SECRET"
+ },
"notificationHub": {
"connectionString": "SECRET",
"hubName": "SECRET"