Deprecation of Application Insights for Sentry.IO (#723)
* Remove Application Insights implementation and implement new Sentry.IO SDK * Remove test exception.
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
<PackageVersion Include="Nito.AsyncEx" Version="5.1.2" />
|
||||
<PackageVersion Include="Nito.AsyncEx.Tasks" Version="5.1.2" />
|
||||
<PackageVersion Include="NodaTime" Version="3.2.2" />
|
||||
<PackageVersion Include="Sentry.Serilog" Version="5.12.0" />
|
||||
<PackageVersion Include="Serilog" Version="4.2.0" />
|
||||
<PackageVersion Include="Serilog.Exceptions" Version="8.4.0" />
|
||||
<PackageVersion Include="Serilog.Sinks.Debug" Version="3.0.0" />
|
||||
|
||||
@@ -9,11 +9,12 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.Diagnostics" />
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" />
|
||||
<PackageReference Include="Google.Apis.Auth" />
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" />
|
||||
<PackageReference Include="Google.Apis.Auth" />
|
||||
<PackageReference Include="Microsoft.Identity.Client" />
|
||||
<PackageReference Include="Microsoft.Identity.Client.Broker" />
|
||||
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" />
|
||||
<PackageReference Include="Microsoft.Identity.Client.Broker" />
|
||||
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" />
|
||||
<PackageReference Include="Sentry.Serilog" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Wino.Core.Domain\Wino.Core.Domain.csproj" />
|
||||
|
||||
@@ -27,5 +27,5 @@ public interface IApplicationConfiguration
|
||||
/// <summary>
|
||||
/// Application insights instrumentation key.
|
||||
/// </summary>
|
||||
string ApplicationInsightsInstrumentationKey { get; }
|
||||
string SentryDNS { get; }
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Identity.Client" />
|
||||
<PackageReference Include="Sentry.Serilog" />
|
||||
<PackageReference Include="System.Reactive" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
<PackageReference Include="morelinq" />
|
||||
<PackageReference Include="Nito.AsyncEx.Tasks" />
|
||||
<PackageReference Include="NodaTime" />
|
||||
<PackageReference Include="Sentry.Serilog" />
|
||||
<PackageReference Include="SkiaSharp" />
|
||||
<PackageReference Include="SqlKata" />
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" />
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="EmailValidation" />
|
||||
<PackageReference Include="Microsoft.Identity.Client" />
|
||||
<PackageReference Include="Sentry.Serilog" />
|
||||
<PackageReference Include="System.Reactive" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -83,6 +83,7 @@
|
||||
<PackageReference Include="Microsoft.UI.Xaml" />
|
||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed" />
|
||||
<PackageReference Include="Nito.AsyncEx" />
|
||||
<PackageReference Include="Sentry.Serilog" />
|
||||
|
||||
<PackageReference Include="sqlite-net-pcl" />
|
||||
<PackageReference Include="Win2D.uwp" />
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
<PackageReference Include="H.NotifyIcon.Wpf" />
|
||||
<PackageReference Include="CommunityToolkit.WinUI.Notifications" />
|
||||
<PackageReference Include="Microsoft.Identity.Client" />
|
||||
<PackageReference Include="Sentry.Serilog" />
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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<ITelemetry> 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);
|
||||
}
|
||||
}
|
||||
@@ -9,15 +9,18 @@
|
||||
<PackageReference Include="HtmlAgilityPack" />
|
||||
<PackageReference Include="Ical.Net" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
|
||||
<PackageReference Include="Sentry.Serilog" />
|
||||
<PackageReference Include="Serilog" />
|
||||
<PackageReference Include="Serilog.Sinks.Debug" />
|
||||
<PackageReference Include="Serilog.Sinks.File" />
|
||||
<PackageReference Include="Serilog.Exceptions" />
|
||||
<PackageReference Include="Serilog.Sinks.ApplicationInsights" />
|
||||
<PackageReference Include="SqlKata" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Wino.Core.Domain\Wino.Core.Domain.csproj" />
|
||||
<ProjectReference Include="..\Wino.Messages\Wino.Messaging.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Misc\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -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<string, string> 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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user