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:
@@ -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