diff --git a/.props/Test.props b/.props/Test.props
index 38bffa770b..6d971f7b8f 100644
--- a/.props/Test.props
+++ b/.props/Test.props
@@ -35,4 +35,8 @@
false
+
+ $(NoWarn),CS0618
+
+
diff --git a/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/TelemetryConfigurationFactory.cs b/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/TelemetryConfigurationFactory.cs
index 004f10af65..d00d73a551 100644
--- a/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/TelemetryConfigurationFactory.cs
+++ b/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/TelemetryConfigurationFactory.cs
@@ -477,7 +477,9 @@ private static void SelectInstrumentationKey(TelemetryConfiguration configuratio
else if (PlatformSingleton.Current.TryGetEnvironmentVariable(InstrumentationKeyEnvironmentVariable, out string instrumentationKeyEnVar))
{
CoreEventSource.Log.TelemetryConfigurationFactoryFoundInstrumentationKeyEnvironmentVariable(variableName: InstrumentationKeyEnvironmentVariable);
+#pragma warning disable CS0618 // Type or member is obsolete
configuration.InstrumentationKey = instrumentationKeyEnVar;
+#pragma warning restore CS0618 // Type or member is obsolete
}
// SANITY CHECK - If Ikey is null, this means that neither the InstrumentationKey nor ConnectionString were set.
diff --git a/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Tracing/HeartbeatProvider.cs b/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Tracing/HeartbeatProvider.cs
index 2dfef202d3..c9cead3c61 100644
--- a/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Tracing/HeartbeatProvider.cs
+++ b/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Tracing/HeartbeatProvider.cs
@@ -103,7 +103,9 @@ public string InstrumentationKey
{
if (this.telemetryClient != null)
{
+#pragma warning disable CS0618 // Type or member is obsolete
this.telemetryClient.InstrumentationKey = value;
+#pragma warning restore CS0618 // Type or member is obsolete
}
}
}
diff --git a/BASE/src/Microsoft.ApplicationInsights/Extensibility/TelemetryConfiguration.cs b/BASE/src/Microsoft.ApplicationInsights/Extensibility/TelemetryConfiguration.cs
index 53d284b666..1de1e0a5b6 100644
--- a/BASE/src/Microsoft.ApplicationInsights/Extensibility/TelemetryConfiguration.cs
+++ b/BASE/src/Microsoft.ApplicationInsights/Extensibility/TelemetryConfiguration.cs
@@ -74,7 +74,9 @@ static TelemetryConfiguration()
/// Initializes a new instance of the TelemetryConfiguration class.
///
[EditorBrowsable(EditorBrowsableState.Never)]
+#pragma warning disable CS0618 // Type or member is obsolete
public TelemetryConfiguration() : this(string.Empty, null)
+#pragma warning restore CS0618 // Type or member is obsolete
{
}
@@ -82,6 +84,7 @@ public TelemetryConfiguration() : this(string.Empty, null)
/// Initializes a new instance of the TelemetryConfiguration class.
///
/// The instrumentation key this configuration instance will provide.
+ [Obsolete("InstrumentationKey based global ingestion is being deprecated. Use the default constructor and manually set TelemetryConfiguration.ConnectionString. See https://github.com/microsoft/ApplicationInsights-dotnet/issues/2560 for more details.")]
public TelemetryConfiguration(string instrumentationKey) : this(instrumentationKey, null)
{
}
@@ -91,6 +94,7 @@ public TelemetryConfiguration(string instrumentationKey) : this(instrumentationK
///
/// The instrumentation key this configuration instance will provide.
/// The telemetry channel to provide with this configuration instance.
+ [Obsolete("InstrumentationKey based global ingestion is being deprecated. Use the default constructor and manually set TelemetryConfiguration.ConnectionString. See https://github.com/microsoft/ApplicationInsights-dotnet/issues/2560 for more details.")]
public TelemetryConfiguration(string instrumentationKey, ITelemetryChannel channel)
{
this.instrumentationKey = instrumentationKey ?? throw new ArgumentNullException(nameof(instrumentationKey));
@@ -149,8 +153,9 @@ internal set
///
public string InstrumentationKey
{
- get { return this.instrumentationKey; }
+ get => this.instrumentationKey;
+ [Obsolete("InstrumentationKey based global ingestion is being deprecated. Use TelemetryConfiguration.ConnectionString. See https://github.com/microsoft/ApplicationInsights-dotnet/issues/2560 for more details.")]
set { this.instrumentationKey = value ?? throw new ArgumentNullException(nameof(this.InstrumentationKey)); }
}
@@ -296,7 +301,9 @@ public string ConnectionString
ConnectionString = value,
};
+#pragma warning disable CS0618 // Type or member is obsolete
this.InstrumentationKey = endpointProvider.GetInstrumentationKey();
+#pragma warning restore CS0618 // Type or member is obsolete
this.EndpointContainer = new EndpointContainer(endpointProvider);
diff --git a/BASE/src/Microsoft.ApplicationInsights/TelemetryClient.cs b/BASE/src/Microsoft.ApplicationInsights/TelemetryClient.cs
index 9218e60256..8cf1cf6720 100644
--- a/BASE/src/Microsoft.ApplicationInsights/TelemetryClient.cs
+++ b/BASE/src/Microsoft.ApplicationInsights/TelemetryClient.cs
@@ -79,7 +79,9 @@ public TelemetryContext Context
///
public string InstrumentationKey
{
- get { return this.Context.InstrumentationKey; }
+ get => this.Context.InstrumentationKey;
+
+ [Obsolete("InstrumentationKey based global ingestion is being deprecated. Recommended to set TelemetryConfiguration.ConnectionString. See https://github.com/microsoft/ApplicationInsights-dotnet/issues/2560 for more details.")]
set { this.Context.InstrumentationKey = value; }
}
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a34b915e20..e8dcc57261 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,8 @@
- [Added support for distributed tracing with Azure.Messaging.ServiceBus](https://github.com/microsoft/ApplicationInsights-dotnet/pull/2593)
- [Move internal type from `Shared` to `Microsoft` namespace](https://github.com/microsoft/ApplicationInsights-dotnet/pull/2442)
- [Extension methods to retrive specific operation details.](https://github.com/microsoft/ApplicationInsights-dotnet/issues/1350)
+- [Mark Instrumentation Key based APIs as Obsolete](https://github.com/microsoft/ApplicationInsights-dotnet/issues/2560).
+ - See also: https://docs.microsoft.com/azure/azure-monitor/app/migrate-from-instrumentation-keys-to-connection-strings
## Version 2.21.0-beta1
- [Support IPv6 in request headers](https://github.com/microsoft/ApplicationInsights-dotnet/issues/2521)
diff --git a/LOGGING/src/ILogger/ApplicationInsightsLoggingBuilderExtensions.cs b/LOGGING/src/ILogger/ApplicationInsightsLoggingBuilderExtensions.cs
index 2a3af65e0f..2b0e813aac 100644
--- a/LOGGING/src/ILogger/ApplicationInsightsLoggingBuilderExtensions.cs
+++ b/LOGGING/src/ILogger/ApplicationInsightsLoggingBuilderExtensions.cs
@@ -34,6 +34,7 @@ public static ILoggingBuilder AddApplicationInsights(this ILoggingBuilder builde
/// The to use.
/// Application insights instrumentation key.
/// Logging builder with Application Insights added to it.
+ [Obsolete("InstrumentationKey based global ingestion is being deprecated. Use the AddApplicationInsights() overload which accepts Action and set TelemetryConfiguration.ConnectionString. See https://github.com/microsoft/ApplicationInsights-dotnet/issues/2560 for more details.")]
public static ILoggingBuilder AddApplicationInsights(this ILoggingBuilder builder, string instrumentationKey)
{
if (builder == null)
@@ -53,6 +54,7 @@ public static ILoggingBuilder AddApplicationInsights(this ILoggingBuilder builde
/// Application insights instrumentation key.
/// Action to configure ApplicationInsights logger.
/// Logging builder with Application Insights added to it.
+ [Obsolete("InstrumentationKey based global ingestion is being deprecated. Use the AddApplicationInsights() overload which accepts Action and set TelemetryConfiguration.ConnectionString. See https://github.com/microsoft/ApplicationInsights-dotnet/issues/2560 for more details.")]
public static ILoggingBuilder AddApplicationInsights(
this ILoggingBuilder builder,
string instrumentationKey,
diff --git a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs
index 3a47ca39fd..75c43b6dec 100644
--- a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs
+++ b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs
@@ -43,6 +43,7 @@ public static IApplicationBuilder UseApplicationInsightsExceptionTelemetry(this
/// The instance.
/// Instrumentation key to use for telemetry.
/// The .
+ [Obsolete("InstrumentationKey based global ingestion is being deprecated. Use the AddApplicationInsightsTelemetry() overload which accepts Action and set ApplicationInsightsServiceOptions.ConnectionString. See https://github.com/microsoft/ApplicationInsights-dotnet/issues/2560 for more details.")]
public static IServiceCollection AddApplicationInsightsTelemetry(
this IServiceCollection services,
string instrumentationKey)
diff --git a/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs b/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs
index 4790a4e9d3..64776d38b4 100644
--- a/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs
+++ b/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs
@@ -21,6 +21,7 @@ public static partial class ApplicationInsightsExtensions
/// The instance.
/// Instrumentation key to use for telemetry.
/// The .
+ [Obsolete("InstrumentationKey based global ingestion is being deprecated. Use the AddApplicationInsightsTelemetryWorkerService() overload which accepts Action and set ApplicationInsightsServiceOptions.ConnectionString. See https://github.com/microsoft/ApplicationInsights-dotnet/issues/2560 for more details.")]
public static IServiceCollection AddApplicationInsightsTelemetryWorkerService(
this IServiceCollection services,
string instrumentationKey)
diff --git a/NETCORE/src/Shared/Extensions/ApplicationInsightsExtensions.cs b/NETCORE/src/Shared/Extensions/ApplicationInsightsExtensions.cs
index be490174a0..1c098c3a96 100644
--- a/NETCORE/src/Shared/Extensions/ApplicationInsightsExtensions.cs
+++ b/NETCORE/src/Shared/Extensions/ApplicationInsightsExtensions.cs
@@ -158,6 +158,7 @@ public static IServiceCollection ConfigureTelemetryModule(
/// Sets telemetry endpoint address.
/// Sets instrumentation key.
/// The .
+ [Obsolete("InstrumentationKey based global ingestion is being deprecated. Use the AddApplicationInsightsSettings() overload which accepts string ConnectionString. See https://github.com/microsoft/ApplicationInsights-dotnet/issues/2560 for more details.")]
[SuppressMessage("ApiDesign", "RS0026:Do not add multiple public overloads with optional parameters", Justification = "We made a mistake here, but we can't remove it from the public API now.")]
public static IConfigurationBuilder AddApplicationInsightsSettings(this IConfigurationBuilder configurationSourceRoot, bool? developerMode = null, string endpointAddress = null, string instrumentationKey = null)
=> configurationSourceRoot.AddApplicationInsightsSettings(connectionString: null, developerMode: developerMode, endpointAddress: endpointAddress, instrumentationKey: instrumentationKey);
@@ -246,7 +247,9 @@ internal static void AddTelemetryConfiguration(
if (config.TryGetValue(primaryKey: InstrumentationKeyForWebSites, backupKey: InstrumentationKeyFromConfig, value: out string instrumentationKey))
{
+#pragma warning disable CS0618 // Type or member is obsolete
serviceOptions.InstrumentationKey = instrumentationKey;
+#pragma warning restore CS0618 // Type or member is obsolete
}
if (config.TryGetValue(primaryKey: DeveloperModeForWebSites, backupKey: DeveloperModeFromConfig, value: out string developerModeValue))
diff --git a/NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs b/NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs
index 847ae032f7..ad9a67ea79 100644
--- a/NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs
+++ b/NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs
@@ -4,6 +4,7 @@ namespace Microsoft.ApplicationInsights.AspNetCore.Extensions
namespace Microsoft.ApplicationInsights.WorkerService
#endif
{
+ using System;
using System.Reflection;
using Microsoft.ApplicationInsights.DependencyCollector;
@@ -59,6 +60,7 @@ public class ApplicationInsightsServiceOptions
///
/// Gets or sets the default instrumentation key for the application.
///
+ [Obsolete("InstrumentationKey based global ingestion is being deprecated. Use ApplicationInsightsServiceOptions.ConnectionString. See https://github.com/microsoft/ApplicationInsights-dotnet/issues/2560 for more details.")]
public string InstrumentationKey { get; set; }
///
@@ -161,10 +163,12 @@ internal void CopyPropertiesTo(ApplicationInsightsServiceOptions target)
target.EndpointAddress = this.EndpointAddress;
}
+#pragma warning disable CS0618 // Type or member is obsolete
if (!string.IsNullOrEmpty(this.InstrumentationKey))
{
target.InstrumentationKey = this.InstrumentationKey;
}
+#pragma warning restore CS0618 // Type or member is obsolete
if (!string.IsNullOrEmpty(this.ConnectionString))
{
diff --git a/NETCORE/src/Shared/Implementation/TelemetryConfigurationOptionsSetup.cs b/NETCORE/src/Shared/Implementation/TelemetryConfigurationOptionsSetup.cs
index d8d707bcd6..2d98183921 100644
--- a/NETCORE/src/Shared/Implementation/TelemetryConfigurationOptionsSetup.cs
+++ b/NETCORE/src/Shared/Implementation/TelemetryConfigurationOptionsSetup.cs
@@ -72,10 +72,12 @@ public void Configure(TelemetryConfiguration configuration)
{
try
{
+#pragma warning disable CS0618 // Type or member is obsolete
if (this.applicationInsightsServiceOptions.InstrumentationKey != null)
{
configuration.InstrumentationKey = this.applicationInsightsServiceOptions.InstrumentationKey;
}
+#pragma warning restore CS0618 // Type or member is obsolete
if (this.telemetryModuleConfigurators.Any())
{
diff --git a/WEB/Src/WindowsServer/WindowsServer/UnhandledExceptionTelemetryModule.cs b/WEB/Src/WindowsServer/WindowsServer/UnhandledExceptionTelemetryModule.cs
index 6d7f2c0055..13db65b126 100644
--- a/WEB/Src/WindowsServer/WindowsServer/UnhandledExceptionTelemetryModule.cs
+++ b/WEB/Src/WindowsServer/WindowsServer/UnhandledExceptionTelemetryModule.cs
@@ -62,7 +62,9 @@ public void Dispose()
private static void CopyConfiguration(TelemetryConfiguration source, TelemetryConfiguration target)
{
- target.InstrumentationKey = source.InstrumentationKey;
+#pragma warning disable CS0618 // Type or member is obsolete
+ target.InstrumentationKey = source.InstrumentationKey;
+#pragma warning restore CS0618 // Type or member is obsolete
foreach (var telemetryInitializer in source.TelemetryInitializers)
{