Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mark Instrumentation Key APIs Obsolete #2592

Merged
merged 14 commits into from
May 24, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,17 @@ static TelemetryConfiguration()
/// Initializes a new instance of the TelemetryConfiguration class.
/// </summary>
[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
{
}

/// <summary>
/// Initializes a new instance of the TelemetryConfiguration class.
/// </summary>
/// <param name="instrumentationKey">The instrumentation key this configuration instance will provide.</param>
[Obsolete("InstrumentationKey based global ingestion is being deprecated. Transition to using connection strings for data ingestion. https://aka.ms/MigrateToConnectionString")]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cartersocha, need to review the messaging here

public TelemetryConfiguration(string instrumentationKey) : this(instrumentationKey, null)
{
}
Expand All @@ -91,6 +94,7 @@ public TelemetryConfiguration(string instrumentationKey) : this(instrumentationK
/// </summary>
/// <param name="instrumentationKey">The instrumentation key this configuration instance will provide.</param>
/// <param name="channel">The telemetry channel to provide with this configuration instance.</param>
[Obsolete("InstrumentationKey based global ingestion is being deprecated. Transition to using connection strings for data ingestion. https://aka.ms/MigrateToConnectionString")]
public TelemetryConfiguration(string instrumentationKey, ITelemetryChannel channel)
{
this.instrumentationKey = instrumentationKey ?? throw new ArgumentNullException(nameof(instrumentationKey));
Expand Down Expand Up @@ -149,8 +153,9 @@ internal set
/// </remarks>
public string InstrumentationKey
{
get { return this.instrumentationKey; }
get => this.instrumentationKey;

[Obsolete("InstrumentationKey based global ingestion is being deprecated. Transition to using connection strings for data ingestion. https://aka.ms/MigrateToConnectionString")]
set { this.instrumentationKey = value ?? throw new ArgumentNullException(nameof(this.InstrumentationKey)); }
}

Expand Down Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion BASE/src/Microsoft.ApplicationInsights/TelemetryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ public TelemetryContext Context
/// </summary>
public string InstrumentationKey
{
get { return this.Context.InstrumentationKey; }
get => this.Context.InstrumentationKey;

[Obsolete("InstrumentationKey based global ingestion is being deprecated. Transition to using connection strings for data ingestion. https://aka.ms/MigrateToConnectionString")]
set { this.Context.InstrumentationKey = value; }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static ILoggingBuilder AddApplicationInsights(this ILoggingBuilder builde
/// <param name="builder">The <see cref="ILoggingBuilder"/> to use.</param>
/// <param name="instrumentationKey">Application insights instrumentation key.</param>
/// <returns>Logging builder with Application Insights added to it.</returns>
[Obsolete("InstrumentationKey based global ingestion is being deprecated. Transition to using connection strings for data ingestion. https://aka.ms/MigrateToConnectionString")]
public static ILoggingBuilder AddApplicationInsights(this ILoggingBuilder builder, string instrumentationKey)
{
if (builder == null)
Expand All @@ -53,6 +54,7 @@ public static ILoggingBuilder AddApplicationInsights(this ILoggingBuilder builde
/// <param name="instrumentationKey">Application insights instrumentation key.</param>
/// <param name="configureApplicationInsightsLoggerOptions">Action to configure ApplicationInsights logger.</param>
/// <returns>Logging builder with Application Insights added to it.</returns>
[Obsolete("InstrumentationKey based global ingestion is being deprecated. Transition to using connection strings for data ingestion. https://aka.ms/MigrateToConnectionString")]
public static ILoggingBuilder AddApplicationInsights(
this ILoggingBuilder builder,
string instrumentationKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static IApplicationBuilder UseApplicationInsightsExceptionTelemetry(this
/// <param name="services">The <see cref="IServiceCollection"/> instance.</param>
/// <param name="instrumentationKey">Instrumentation key to use for telemetry.</param>
/// <returns>The <see cref="IServiceCollection"/>.</returns>
[Obsolete("InstrumentationKey based global ingestion is being deprecated. Transition to using connection strings for data ingestion. https://aka.ms/MigrateToConnectionString")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for an user of this API, this message is not telling how to migrate. The link is for an overall migration approach.

public static IServiceCollection AddApplicationInsightsTelemetry(
this IServiceCollection services,
string instrumentationKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static partial class ApplicationInsightsExtensions
/// <param name="services">The <see cref="IServiceCollection"/> instance.</param>
/// <param name="instrumentationKey">Instrumentation key to use for telemetry.</param>
/// <returns>The <see cref="IServiceCollection"/>.</returns>
[Obsolete("InstrumentationKey based global ingestion is being deprecated. Transition to using connection strings for data ingestion. https://aka.ms/MigrateToConnectionString")]
public static IServiceCollection AddApplicationInsightsTelemetryWorkerService(
this IServiceCollection services,
string instrumentationKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public static IServiceCollection ConfigureTelemetryModule<T>(
/// <param name="endpointAddress">Sets telemetry endpoint address.</param>
/// <param name="instrumentationKey">Sets instrumentation key.</param>
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
[Obsolete("InstrumentationKey based global ingestion is being deprecated. Transition to using connection strings for data ingestion. https://aka.ms/MigrateToConnectionString")]
[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);
Expand All @@ -173,6 +174,7 @@ public static IConfigurationBuilder AddApplicationInsightsSettings(this IConfigu
/// <param name="endpointAddress">Sets telemetry endpoint address.</param>
/// <param name="instrumentationKey">Sets instrumentation key.</param>
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
[Obsolete("InstrumentationKey based global ingestion is being deprecated. Transition to using connection strings for data ingestion. https://aka.ms/MigrateToConnectionString")]
[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,
Expand Down Expand Up @@ -248,7 +250,10 @@ internal static void AddTelemetryConfiguration(

if (config.TryGetValue(primaryKey: InstrumentationKeyForWebSites, backupKey: InstrumentationKeyFromConfig, value: out string instrumentationKey))
{
// TODO: CONSIDER WARNING ABOUT USING IKEY IN CONFIGURATION
#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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Microsoft.ApplicationInsights.AspNetCore.Extensions
namespace Microsoft.ApplicationInsights.WorkerService
#endif
{
using System;
using System.Reflection;
using Microsoft.ApplicationInsights.DependencyCollector;

Expand Down Expand Up @@ -59,6 +60,7 @@ public class ApplicationInsightsServiceOptions
/// <summary>
/// Gets or sets the default instrumentation key for the application.
/// </summary>
[Obsolete("InstrumentationKey based global ingestion is being deprecated. Transition to using connection strings for data ingestion. https://aka.ms/MigrateToConnectionString")]
public string InstrumentationKey { get; set; }

/// <summary>
Expand Down Expand Up @@ -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))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down