diff --git a/Directory.Packages.props b/Directory.Packages.props index f97ada3f..c6262929 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -39,6 +39,7 @@ + diff --git a/Wino.Authentication/Wino.Authentication.csproj b/Wino.Authentication/Wino.Authentication.csproj index a89ef2bb..3c7c77ce 100644 --- a/Wino.Authentication/Wino.Authentication.csproj +++ b/Wino.Authentication/Wino.Authentication.csproj @@ -9,11 +9,12 @@ - - + + - - + + + diff --git a/Wino.Core.Domain/Interfaces/IApplicationConfiguration.cs b/Wino.Core.Domain/Interfaces/IApplicationConfiguration.cs index 3b1f71eb..120c593e 100644 --- a/Wino.Core.Domain/Interfaces/IApplicationConfiguration.cs +++ b/Wino.Core.Domain/Interfaces/IApplicationConfiguration.cs @@ -27,5 +27,5 @@ public interface IApplicationConfiguration /// /// Application insights instrumentation key. /// - string ApplicationInsightsInstrumentationKey { get; } + string SentryDNS { get; } } diff --git a/Wino.Core.ViewModels/Wino.Core.ViewModels.csproj b/Wino.Core.ViewModels/Wino.Core.ViewModels.csproj index 00c2b2ab..f0cce77b 100644 --- a/Wino.Core.ViewModels/Wino.Core.ViewModels.csproj +++ b/Wino.Core.ViewModels/Wino.Core.ViewModels.csproj @@ -8,6 +8,7 @@ + diff --git a/Wino.Core/Wino.Core.csproj b/Wino.Core/Wino.Core.csproj index 1b7ec732..4c44cde9 100644 --- a/Wino.Core/Wino.Core.csproj +++ b/Wino.Core/Wino.Core.csproj @@ -26,6 +26,7 @@ + diff --git a/Wino.Mail.ViewModels/Wino.Mail.ViewModels.csproj b/Wino.Mail.ViewModels/Wino.Mail.ViewModels.csproj index 72e32d96..7cbcd411 100644 --- a/Wino.Mail.ViewModels/Wino.Mail.ViewModels.csproj +++ b/Wino.Mail.ViewModels/Wino.Mail.ViewModels.csproj @@ -9,6 +9,7 @@ + diff --git a/Wino.Mail/Wino.Mail.csproj b/Wino.Mail/Wino.Mail.csproj index 6053cf2e..4f66bcb5 100644 --- a/Wino.Mail/Wino.Mail.csproj +++ b/Wino.Mail/Wino.Mail.csproj @@ -83,6 +83,7 @@ + diff --git a/Wino.Server/ServerContext.cs b/Wino.Server/ServerContext.cs index 20f5ebd7..01d1cd32 100644 --- a/Wino.Server/ServerContext.cs +++ b/Wino.Server/ServerContext.cs @@ -49,14 +49,11 @@ public class ServerContext : { private const double MinimumSynchronizationIntervalMinutes = 1; - private readonly System.Timers.Timer _timer; + private readonly System.Timers.Timer _timer = new System.Timers.Timer(); private static object connectionLock = new object(); private AppServiceConnection connection = null; - private readonly IDatabaseService _databaseService; - private readonly IApplicationConfiguration _applicationFolderConfiguration; - private readonly ISynchronizerFactory _synchronizerFactory; private readonly IServerMessageHandlerFactory _serverMessageHandlerFactory; private readonly IAccountService _accountService; private readonly IPreferencesService _preferencesService; @@ -77,9 +74,6 @@ public class ServerContext : _timer.Elapsed += SynchronizationTimerTriggered; _preferencesService.PropertyChanged += PreferencesUpdated; - _databaseService = databaseService; - _applicationFolderConfiguration = applicationFolderConfiguration; - _synchronizerFactory = synchronizerFactory; _serverMessageHandlerFactory = serverMessageHandlerFactory; _accountService = accountService; diff --git a/Wino.Server/Wino.Server.csproj b/Wino.Server/Wino.Server.csproj index 8de38d83..6adf9d21 100644 --- a/Wino.Server/Wino.Server.csproj +++ b/Wino.Server/Wino.Server.csproj @@ -39,6 +39,7 @@ + diff --git a/Wino.Services/ApplicationConfiguration.cs b/Wino.Services/ApplicationConfiguration.cs index 749108d0..f98722e4 100644 --- a/Wino.Services/ApplicationConfiguration.cs +++ b/Wino.Services/ApplicationConfiguration.cs @@ -10,5 +10,5 @@ public class ApplicationConfiguration : IApplicationConfiguration public string PublisherSharedFolderPath { get; set; } public string ApplicationTempFolderPath { get; set; } - public string ApplicationInsightsInstrumentationKey => "a5a07c2f-6e24-4055-bfc9-88e87eef873a"; + public string SentryDNS => "https://81365d32d74c6f223a0674a2fb7bade5@o4509722249134080.ingest.de.sentry.io/4509722259095632"; } diff --git a/Wino.Services/Misc/WinoTelemetryConverter.cs b/Wino.Services/Misc/WinoTelemetryConverter.cs deleted file mode 100644 index 9316afbf..00000000 --- a/Wino.Services/Misc/WinoTelemetryConverter.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.ApplicationInsights.Channel; -using Microsoft.ApplicationInsights.DataContracts; -using Serilog.Events; -using Serilog.Sinks.ApplicationInsights.TelemetryConverters; - -namespace Wino.Services.Misc; - -internal class WinoTelemetryConverter : EventTelemetryConverter -{ - private readonly string _userDiagnosticId; - - public WinoTelemetryConverter(string userDiagnosticId) - { - _userDiagnosticId = userDiagnosticId; - } - - public override IEnumerable Convert(LogEvent logEvent, IFormatProvider formatProvider) - { - foreach (ITelemetry telemetry in base.Convert(logEvent, formatProvider)) - { - // Assign diagnostic id as user id. - telemetry.Context.User.Id = _userDiagnosticId; - - yield return telemetry; - } - } - - public override void ForwardPropertiesToTelemetryProperties(LogEvent logEvent, ISupportProperties telemetryProperties, IFormatProvider formatProvider) - { - ForwardPropertiesToTelemetryProperties(logEvent, telemetryProperties, formatProvider, - includeLogLevel: true, - includeRenderedMessage: true, - includeMessageTemplate: false); - } -} diff --git a/Wino.Services/Wino.Services.csproj b/Wino.Services/Wino.Services.csproj index 089e7eec..d0121c5e 100644 --- a/Wino.Services/Wino.Services.csproj +++ b/Wino.Services/Wino.Services.csproj @@ -9,15 +9,18 @@ + - + + + \ No newline at end of file diff --git a/Wino.Services/WinoLogger.cs b/Wino.Services/WinoLogger.cs index 9bafc7e3..719f4fc7 100644 --- a/Wino.Services/WinoLogger.cs +++ b/Wino.Services/WinoLogger.cs @@ -1,11 +1,9 @@ using System.Collections.Generic; -using Microsoft.ApplicationInsights; -using Microsoft.ApplicationInsights.Extensibility; +using Sentry; using Serilog; using Serilog.Core; using Serilog.Exceptions; using Wino.Core.Domain.Interfaces; -using Wino.Services.Misc; namespace Wino.Services; @@ -13,16 +11,12 @@ public class WinoLogger : IWinoLogger { private readonly LoggingLevelSwitch _levelSwitch = new LoggingLevelSwitch(); private readonly IPreferencesService _preferencesService; - private readonly TelemetryConfiguration _telemetryConfiguration; - - public TelemetryClient TelemetryClient { get; private set; } + private readonly IApplicationConfiguration _applicationConfiguration; public WinoLogger(IPreferencesService preferencesService, IApplicationConfiguration applicationConfiguration) { _preferencesService = preferencesService; - _telemetryConfiguration = new TelemetryConfiguration(applicationConfiguration.ApplicationInsightsInstrumentationKey); - - TelemetryClient = new TelemetryClient(_telemetryConfiguration); + _applicationConfiguration = applicationConfiguration; RefreshLoggingLevel(); } @@ -42,13 +36,34 @@ public class WinoLogger : IWinoLogger // This call seems weird, but it is necessary to make sure the diagnostic id is set. _preferencesService.DiagnosticId = _preferencesService.DiagnosticId; - var insightsTelemetryConverter = new WinoTelemetryConverter(_preferencesService.DiagnosticId); + // Initialize Sentry + SentrySdk.Init(options => + { + options.Dsn = _applicationConfiguration.SentryDNS; +#if DEBUG + options.Debug = false; +#else + options.Debug = true; +#endif + options.AutoSessionTracking = true; + + // Set user context + options.SetBeforeSend((sentryEvent, hint) => + { + sentryEvent.User = new SentryUser + { + Id = _preferencesService.DiagnosticId + }; + return sentryEvent; + }); + }); Log.Logger = new LoggerConfiguration() .MinimumLevel.ControlledBy(_levelSwitch) .WriteTo.File(fullLogFilePath, retainedFileCountLimit: 3, rollOnFileSizeLimit: true, rollingInterval: RollingInterval.Day) + .WriteTo.Sentry(minimumBreadcrumbLevel: Serilog.Events.LogEventLevel.Information, + minimumEventLevel: Serilog.Events.LogEventLevel.Error) .WriteTo.Debug() - .WriteTo.ApplicationInsights(TelemetryClient, insightsTelemetryConverter, restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Error) .Enrich.FromLogContext() .Enrich.WithExceptionDetails() .CreateLogger(); @@ -56,8 +71,17 @@ public class WinoLogger : IWinoLogger public void TrackEvent(string eventName, Dictionary properties = null) { - if (TelemetryClient == null) return; + SentrySdk.AddBreadcrumb(eventName, data: properties); - TelemetryClient.TrackEvent(eventName, properties); + SentrySdk.ConfigureScope(scope => + { + if (properties != null) + { + foreach (var prop in properties) + { + scope.SetTag(prop.Key, prop.Value); + } + } + }); } }