From 18b6011147136d3fedbc58337e1c9693654eaccb Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 14 Nov 2023 08:06:47 +0100 Subject: [PATCH] chore: remove obsolete app insights functionality --- .../ContextProperties.cs | 7 +- .../Converters/CustomTelemetryConverter.cs | 18 ---- .../DependencyTelemetryConverter.cs | 8 -- .../Converters/EventTelemetryConverter.cs | 8 -- .../Converters/ExceptionTelemetryConverter.cs | 22 +---- .../Converters/MetricTelemetryConverter.cs | 8 -- .../Converters/OperationContextConverter.cs | 8 -- .../Converters/TraceTelemetryConverter.cs | 9 -- .../LoggerSinkConfigurationExtensions.cs | 96 ------------------- .../LoggerConfigurationExtensionsTests.cs | 48 ---------- 10 files changed, 2 insertions(+), 230 deletions(-) diff --git a/src/Arcus.Observability.Telemetry.Core/ContextProperties.cs b/src/Arcus.Observability.Telemetry.Core/ContextProperties.cs index cd9ae065..a19a0f14 100644 --- a/src/Arcus.Observability.Telemetry.Core/ContextProperties.cs +++ b/src/Arcus.Observability.Telemetry.Core/ContextProperties.cs @@ -1,6 +1,4 @@ -using System; - -#pragma warning disable 1591 +#pragma warning disable 1591 namespace Arcus.Observability.Telemetry.Core { public static class ContextProperties @@ -38,9 +36,6 @@ public static class EventTracking { public const string EventLogEntry = "Event"; public const string EventName = "EventName"; - - [Obsolete("Use " + nameof(ContextProperties) + "." + nameof(TelemetryContext) + " instead")] - public const string EventContext = "EventDescription"; } public static class General diff --git a/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/CustomTelemetryConverter.cs b/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/CustomTelemetryConverter.cs index 5ff18682..4756e912 100644 --- a/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/CustomTelemetryConverter.cs +++ b/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/CustomTelemetryConverter.cs @@ -20,14 +20,6 @@ public abstract class CustomTelemetryConverter : TelemetryConverterBase private readonly OperationContextConverter _operationContextConverter; private readonly CloudContextConverter _cloudContextConverter = new CloudContextConverter(); - /// - /// Initializes a new instance of the class. - /// - [Obsolete("Use the constructor overload with the Application Insights options instead")] - protected CustomTelemetryConverter() : this(new ApplicationInsightsSinkOptions()) - { - } - /// /// Initializes a new instance of the class. /// @@ -58,18 +50,12 @@ public override IEnumerable Convert(LogEvent logEvent, IFormatProvid TEntry telemetryEntry = CreateTelemetryEntry(logEvent, formatProvider); -#pragma warning disable 618 // Until we go to a new major. AssignTelemetryContextProperties(logEvent, telemetryEntry); -#pragma warning restore 618 _cloudContextConverter.EnrichWithAppInfo(logEvent, telemetryEntry); RemoveIntermediaryProperties(logEvent); logEvent.RemovePropertyIfPresent(ContextProperties.TelemetryContext); -#pragma warning disable 618 // Until we remove the obsolete 'EventDescription'. - logEvent.RemovePropertyIfPresent(ContextProperties.EventTracking.EventContext); -#pragma warning restore 618 - ForwardPropertiesToTelemetryProperties(logEvent, telemetryEntry, formatProvider); _operationContextConverter.EnrichWithCorrelationInfo(telemetryEntry); _operationContextConverter.EnrichWithOperationName(telemetryEntry); @@ -85,10 +71,6 @@ public override IEnumerable Convert(LogEvent logEvent, IFormatProvid protected void AssignTelemetryContextProperties(LogEvent logEvent, ISupportProperties telemetry) { AssignContextPropertiesFromDictionaryProperty(logEvent, telemetry, ContextProperties.TelemetryContext); - -#pragma warning disable 618 // Until we remove obsolete 'EventDescription'. - AssignContextPropertiesFromDictionaryProperty(logEvent, telemetry, ContextProperties.EventTracking.EventContext); -#pragma warning restore 618 } private static void AssignContextPropertiesFromDictionaryProperty(LogEvent logEvent, ISupportProperties telemetry, string propertyName) diff --git a/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/DependencyTelemetryConverter.cs b/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/DependencyTelemetryConverter.cs index 69d9879a..fda0fbb1 100644 --- a/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/DependencyTelemetryConverter.cs +++ b/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/DependencyTelemetryConverter.cs @@ -14,14 +14,6 @@ namespace Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights.Conver /// public class DependencyTelemetryConverter : CustomTelemetryConverter { - /// - /// Initializes a new instance of the class. - /// - [Obsolete("Use the constructor overload with the Application Insights options instead")] - public DependencyTelemetryConverter() - { - } - /// /// Initializes a new instance of the class. /// diff --git a/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/EventTelemetryConverter.cs b/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/EventTelemetryConverter.cs index c4923516..b8f81a33 100644 --- a/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/EventTelemetryConverter.cs +++ b/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/EventTelemetryConverter.cs @@ -14,14 +14,6 @@ namespace Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights.Conver /// public class EventTelemetryConverter : CustomTelemetryConverter { - /// - /// Initializes a new instance of the class. - /// - [Obsolete("Use the constructor overload with the Application Insights options instead")] - public EventTelemetryConverter() - { - } - /// /// Initializes a new instance of the class. /// diff --git a/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/ExceptionTelemetryConverter.cs b/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/ExceptionTelemetryConverter.cs index 27ccf57a..ba3bee02 100644 --- a/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/ExceptionTelemetryConverter.cs +++ b/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/ExceptionTelemetryConverter.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using System.Reflection; using Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights.Configuration; using GuardNet; @@ -13,20 +12,6 @@ namespace Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights.Conver /// public class ExceptionTelemetryConverter : CustomTelemetryConverter { - private readonly ApplicationInsightsSinkExceptionOptions _options; - - /// - /// Initializes a new instance of the class. - /// - /// The consumer-configurable options to influence how the exception should be tracked. - /// Thrown when the is null. - [Obsolete("Use the constructor overload with the Application Insights options instead")] - public ExceptionTelemetryConverter(ApplicationInsightsSinkExceptionOptions options) - { - Guard.NotNull(options, nameof(options), "Requires a set of user-configurable options to influence the behavior of how exceptions are tracked"); - _options = options; - } - /// /// Initializes a new instance of the class. /// @@ -50,7 +35,7 @@ protected override ExceptionTelemetry CreateTelemetryEntry(LogEvent logEvent, IF var exceptionTelemetry = new ExceptionTelemetry(logEvent.Exception); - if (Options?.Exception.IncludeProperties == true || _options?.IncludeProperties == true) + if (Options?.Exception.IncludeProperties == true) { EnrichWithExceptionProperties(logEvent, exceptionTelemetry); } @@ -80,11 +65,6 @@ private string DeterminePropertyFormat() return Options.Exception.PropertyFormat; } - if (_options != null) - { - return _options.PropertyFormat; - } - throw new InvalidOperationException( "Could not determine exception property format because the Application Insights exception converter was not initialized with any options"); } diff --git a/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/MetricTelemetryConverter.cs b/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/MetricTelemetryConverter.cs index bea4a291..16830669 100644 --- a/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/MetricTelemetryConverter.cs +++ b/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/MetricTelemetryConverter.cs @@ -14,14 +14,6 @@ namespace Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights.Conver /// public class MetricTelemetryConverter : CustomTelemetryConverter { - /// - /// Initializes a new instance of the class. - /// - [Obsolete("Use the constructor overload with the Application Insights options instead")] - public MetricTelemetryConverter() - { - } - /// /// Initializes a new instance of the class. /// diff --git a/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/OperationContextConverter.cs b/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/OperationContextConverter.cs index ed914cb5..70de39b3 100644 --- a/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/OperationContextConverter.cs +++ b/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/OperationContextConverter.cs @@ -15,14 +15,6 @@ public class OperationContextConverter { private readonly ApplicationInsightsSinkOptions _options; - /// - /// Initializes a new instance of the class. - /// - [Obsolete("Use the constructor overload with the Application Insights options instead")] - public OperationContextConverter() - { - } - /// /// Initializes a new instance of the class. /// diff --git a/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/TraceTelemetryConverter.cs b/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/TraceTelemetryConverter.cs index 7323d30a..57927467 100644 --- a/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/TraceTelemetryConverter.cs +++ b/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Converters/TraceTelemetryConverter.cs @@ -16,15 +16,6 @@ public class TraceTelemetryConverter : global::Serilog.Sinks.ApplicationInsights private readonly OperationContextConverter _operationContextConverter; private readonly CloudContextConverter _cloudContextConverter = new CloudContextConverter(); - /// - /// Initializes a new instance of the class. - /// - [Obsolete("Use the constructor overload with the Application Insights options instead")] - public TraceTelemetryConverter() - { - _operationContextConverter = new OperationContextConverter(); - } - /// /// Initializes a new instance of the class. /// diff --git a/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Extensions/LoggerSinkConfigurationExtensions.cs b/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Extensions/LoggerSinkConfigurationExtensions.cs index d44029e2..b23bded9 100644 --- a/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Extensions/LoggerSinkConfigurationExtensions.cs +++ b/src/Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights/Extensions/LoggerSinkConfigurationExtensions.cs @@ -15,102 +15,6 @@ namespace Serilog.Configuration /// public static class LoggerSinkConfigurationExtensions { - /// - /// Adds a Serilog sink that writes log events to Azure Application Insights. - /// See also synonym: - /// - /// - /// Supported telemetry types are Traces, Dependencies, Events, Requests and Metrics for which we provide extensions on . - /// - /// The logger configuration. - /// The required Application Insights key. - /// Thrown when the is null. - /// Thrown when the is blank. - [Obsolete("Use the " + nameof(AzureApplicationInsightsWithInstrumentationKey) + " overload instead")] - public static LoggerConfiguration AzureApplicationInsights( - this LoggerSinkConfiguration loggerSinkConfiguration, - string instrumentationKey) - { - Guard.NotNull(loggerSinkConfiguration, nameof(loggerSinkConfiguration), "Requires a logger configuration to add the Azure Application Insights sink to"); - Guard.NotNullOrWhitespace(instrumentationKey, nameof(instrumentationKey), "Requires an instrumentation key to authenticate with Azure Application Insights while sinking telemetry"); - - return AzureApplicationInsightsWithInstrumentationKey(loggerSinkConfiguration, instrumentationKey, configureOptions: null); - } - - /// - /// Adds a Serilog sink that writes log events to Azure Application Insights. - /// See also synonym: - /// - /// - /// Supported telemetry types are Traces, Dependencies, Events, Requests and Metrics for which we provide extensions on . - /// - /// The logger configuration. - /// The required Application Insights key. - /// The optional function to configure additional options to influence the behavior of how the telemetry is logged to Azure Application Insights. - /// Thrown when the is null. - /// Thrown when the is blank. - [Obsolete("Use the " + nameof(AzureApplicationInsightsWithInstrumentationKey) + " overload instead")] - public static LoggerConfiguration AzureApplicationInsights( - this LoggerSinkConfiguration loggerSinkConfiguration, - string instrumentationKey, - Action configureOptions) - { - Guard.NotNull(loggerSinkConfiguration, nameof(loggerSinkConfiguration), "Requires a logger configuration to add the Azure Application Insights sink to"); - Guard.NotNullOrWhitespace(instrumentationKey, nameof(instrumentationKey), "Requires an instrumentation key to authenticate with Azure Application Insights while sinking telemetry"); - - return AzureApplicationInsightsWithInstrumentationKey(loggerSinkConfiguration, instrumentationKey, LogEventLevel.Verbose, configureOptions); - } - - /// - /// Adds a Serilog sink that writes log events to Azure Application Insights. - /// See also synonym: - /// - /// - /// Supported telemetry types are Traces, Dependencies, Events, Requests and Metrics for which we provide extensions on . - /// - /// The logger configuration. - /// The required Application Insights key. - /// The minimum log event level required in order to write an event to the sink. - /// Thrown when the is null. - /// Thrown when the is blank. - [Obsolete("Use the " + nameof(AzureApplicationInsightsWithInstrumentationKey) + " overload instead")] - public static LoggerConfiguration AzureApplicationInsights( - this LoggerSinkConfiguration loggerSinkConfiguration, - string instrumentationKey, - LogEventLevel restrictedToMinimumLevel) - { - Guard.NotNull(loggerSinkConfiguration, nameof(loggerSinkConfiguration), "Requires a logger configuration to add the Azure Application Insights sink to"); - Guard.NotNullOrWhitespace(instrumentationKey, nameof(instrumentationKey), "Requires an instrumentation key to authenticate with Azure Application Insights while sinking telemetry"); - - return AzureApplicationInsightsWithInstrumentationKey(loggerSinkConfiguration, instrumentationKey, restrictedToMinimumLevel, configureOptions: null); - } - - /// - /// Adds a Serilog sink that writes log events to Azure Application Insights. - /// See also synonym: - /// - /// - /// Supported telemetry types are Traces, Dependencies, Events, Requests and Metrics for which we provide extensions on . - /// - /// The logger configuration. - /// The required Application Insights key. - /// The minimum log event level required in order to write an event to the sink. - /// The optional function to configure additional options to influence the behavior of how the telemetry is logged to Azure Application Insights. - /// Thrown when the is null. - /// Thrown when the is blank. - [Obsolete("Use the " + nameof(AzureApplicationInsightsWithInstrumentationKey) + " overload instead")] - public static LoggerConfiguration AzureApplicationInsights( - this LoggerSinkConfiguration loggerSinkConfiguration, - string instrumentationKey, - LogEventLevel restrictedToMinimumLevel, - Action configureOptions) - { - Guard.NotNull(loggerSinkConfiguration, nameof(loggerSinkConfiguration), "Requires a logger configuration to add the Azure Application Insights sink to"); - Guard.NotNullOrWhitespace(instrumentationKey, nameof(instrumentationKey), "Requires an instrumentation key to authenticate with Azure Application Insights while sinking telemetry"); - - return AzureApplicationInsightsWithInstrumentationKey(loggerSinkConfiguration, instrumentationKey, restrictedToMinimumLevel, configureOptions); - } - /// /// Adds a Serilog sink that writes log events to Azure Application Insights. /// diff --git a/src/Arcus.Observability.Tests.Unit/Serilog/Sinks/ApplicationInsights/LoggerConfigurationExtensionsTests.cs b/src/Arcus.Observability.Tests.Unit/Serilog/Sinks/ApplicationInsights/LoggerConfigurationExtensionsTests.cs index 300d8eac..be5feebc 100644 --- a/src/Arcus.Observability.Tests.Unit/Serilog/Sinks/ApplicationInsights/LoggerConfigurationExtensionsTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Serilog/Sinks/ApplicationInsights/LoggerConfigurationExtensionsTests.cs @@ -120,54 +120,6 @@ public void AzureApplicationInsightsWithConnectionStringWithLevelAndOptions_With () => config.WriteTo.AzureApplicationInsightsWithConnectionString(provider, "", level, options => { })); } - [Theory] - [ClassData(typeof(Blanks))] - public void AzureApplicationInsights_WithoutInstrumentationKey_Fails(string instrumentationKey) - { - // Arrange - var config = new LoggerConfiguration(); - - // Act / Assert - Assert.Throws( - () => config.WriteTo.AzureApplicationInsights(instrumentationKey)); - } - - [Theory] - [ClassData(typeof(Blanks))] - public void AzureApplicationInsightsWithConfigOptions_WithoutInstrumentationKey_Fails(string instrumentationKey) - { - // Arrange - var config = new LoggerConfiguration(); - - // Act / Assert - Assert.Throws( - () => config.WriteTo.AzureApplicationInsights(instrumentationKey, options => { })); - } - - [Theory] - [ClassData(typeof(Blanks))] - public void AzureApplicationInsightsWithMinLogLevel_WithoutInstrumentationKey_Fails(string instrumentationKey) - { - // Arrange - var config = new LoggerConfiguration(); - - // Act / Assert - Assert.Throws( - () => config.WriteTo.AzureApplicationInsights(instrumentationKey, LogEventLevel.Debug)); - } - - [Theory] - [ClassData(typeof(Blanks))] - public void AzureApplicationInsightsWithMinLogLevelWithConfigOptions_WithoutInstrumentationKey_Fails(string instrumentationKey) - { - // Arrange - var config = new LoggerConfiguration(); - - // Act / Assert - Assert.Throws( - () => config.WriteTo.AzureApplicationInsights(instrumentationKey, LogEventLevel.Debug, options => { })); - } - [Theory] [ClassData(typeof(Blanks))] public void AzureApplicationInsightsWithInstrumentationKey_WithoutInstrumentationKey_Fails(string instrumentationKey)