Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOp
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.Credential.get -> Azure.Core.TokenCredential
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.Credential.set -> void
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.DependencyCollectionOptions.get -> Microsoft.ApplicationInsights.AspNetCore.Extensions.DependencyCollectionOptions
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.DeveloperMode.get -> bool?
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.DeveloperMode.set -> void
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableActiveTelemetryConfigurationSetup.get -> bool
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableActiveTelemetryConfigurationSetup.set -> void
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableAdaptiveSampling.get -> bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.Co
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.Credential.get -> Azure.Core.TokenCredential
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.Credential.set -> void
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.DependencyCollectionOptions.get -> Microsoft.ApplicationInsights.WorkerService.DependencyCollectionOptions
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.DeveloperMode.get -> bool?
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.DeveloperMode.set -> void
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableAdaptiveSampling.get -> bool
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableAdaptiveSampling.set -> void
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableDebugLogger.get -> bool
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased
### Added
- [Automatic configuration binding from "ApplicationInsights" section in appsettings.json for both AspNetCore and WorkerService packages with configuration precedence: environment variables > explicit configuration > appsettings.json](https://github.com/microsoft/ApplicationInsights-dotnet/pull/3064)
- [Added support for Entra ID (Azure Active Directory) authentication using Azure.Core.TokenCredential](https://github.com/microsoft/ApplicationInsights-dotnet/pull/3054)

## Version 3.0.0-beta1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ public static IServiceCollection AddApplicationInsightsTelemetry(this IServiceCo
{
if (!IsApplicationInsightsAdded(services))
{
// Register the default configuration options to automatically read from appsettings.json
services.AddOptions<ApplicationInsightsServiceOptions>()
.Configure<IConfiguration>((options, config) =>
{
AddTelemetryConfiguration(config, options);
});

services.AddOpenTelemetry()
.WithApplicationInsights()
.UseApplicationInsightsTelemetry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ public static IServiceCollection AddApplicationInsightsTelemetryWorkerService(th
{
if (!IsApplicationInsightsAdded(services))
{
// Register the default configuration options to automatically read from appsettings.json
services.AddOptions<ApplicationInsightsServiceOptions>()
.Configure<IConfiguration>((options, config) =>
{
AddTelemetryConfiguration(config, options);
});

services.AddOpenTelemetry()
.WithApplicationInsights()
.UseApplicationInsightsTelemetry();
Expand Down Expand Up @@ -187,10 +194,7 @@ internal static IOpenTelemetryBuilder UseApplicationInsightsTelemetry(this IOpen
exporterOptions.SamplingRatio = 1.0F;
}

if (serviceOptions.EnableQuickPulseMetricStream)
{
exporterOptions.EnableLiveMetrics = true;
}
exporterOptions.EnableLiveMetrics = serviceOptions.EnableQuickPulseMetricStream;
});

builder.UseAzureMonitorExporter();
Expand Down
19 changes: 0 additions & 19 deletions NETCORE/src/Shared/Extensions/ApplicationInsightsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,10 @@ public static partial class ApplicationInsightsExtensions
{
private const string VersionKeyFromConfig = "version";
private const string ConnectionStringFromConfig = "ApplicationInsights:ConnectionString";
private const string DeveloperModeFromConfig = "ApplicationInsights:TelemetryChannel:DeveloperMode";
private const string EndpointAddressFromConfig = "ApplicationInsights:TelemetryChannel:EndpointAddress";

private const string ConnectionStringEnvironmentVariable = "APPLICATIONINSIGHTS_CONNECTION_STRING";
private const string DeveloperModeForWebSites = "APPINSIGHTS_DEVELOPER_MODE";
private const string EndpointAddressForWebSites = "APPINSIGHTS_ENDPOINTADDRESS";

private const string ApplicationInsightsSectionFromConfig = "ApplicationInsights";
private const string TelemetryChannelSectionFromConfig = "ApplicationInsights:TelemetryChannel";

/// <summary>
/// Read configuration from appSettings.json, appsettings.{env.EnvironmentName}.json,
Expand All @@ -54,26 +49,12 @@ internal static void AddTelemetryConfiguration(
try
{
config.GetSection(ApplicationInsightsSectionFromConfig).Bind(serviceOptions);
config.GetSection(TelemetryChannelSectionFromConfig).Bind(serviceOptions);

if (config.TryGetValue(primaryKey: ConnectionStringEnvironmentVariable, backupKey: ConnectionStringFromConfig, value: out string connectionStringValue))
{
serviceOptions.ConnectionString = connectionStringValue;
}

if (config.TryGetValue(primaryKey: DeveloperModeForWebSites, backupKey: DeveloperModeFromConfig, value: out string developerModeValue))
{
if (bool.TryParse(developerModeValue, out bool developerMode))
{
serviceOptions.DeveloperMode = developerMode;
}
}

if (config.TryGetValue(primaryKey: EndpointAddressForWebSites, backupKey: EndpointAddressFromConfig, value: out string endpointAddress))
{
serviceOptions.EndpointAddress = endpointAddress;
}

if (config.TryGetValue(primaryKey: VersionKeyFromConfig, value: out string version))
{
serviceOptions.ApplicationVersion = version;
Expand Down
10 changes: 0 additions & 10 deletions NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ public class ApplicationInsightsServiceOptions
/// </summary>
public string ApplicationVersion { get; set; } = Assembly.GetEntryAssembly()?.GetName().Version.ToString();

/// <summary>
/// Gets or sets a value indicating whether telemetry channel should be set to developer mode.
/// </summary>
public bool? DeveloperMode { get; set; }

/// <summary>
/// Gets or sets the endpoint address of the channel.
/// </summary>
Expand Down Expand Up @@ -117,11 +112,6 @@ public class ApplicationInsightsServiceOptions
/// <param name="target">Target instance to copy properties to.</param>
internal void CopyPropertiesTo(ApplicationInsightsServiceOptions target)
{
if (this.DeveloperMode != null)
{
target.DeveloperMode = this.DeveloperMode;
}

if (!string.IsNullOrEmpty(this.EndpointAddress))
{
target.EndpointAddress = this.EndpointAddress;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
namespace Microsoft.ApplicationInsights.WorkerService
#if AI_ASPNETCORE_WEB
namespace Microsoft.AspNetCore.Hosting
#else
namespace Microsoft.ApplicationInsights.WorkerService
#endif
{
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
#if AI_ASPNETCORE_WEB
using Microsoft.ApplicationInsights.AspNetCore.Extensions;
#endif
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

/// <summary>
/// <see cref="IConfigureOptions&lt;ApplicationInsightsServiceOptions&gt;"/> implementation that reads options from provided IConfiguration.
/// <see cref="IConfigureOptions{ApplicationInsightsServiceOptions}"/> implementation that reads options from provided IConfiguration.
/// </summary>
[SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "This class is instantiated by Dependency Injection.")]
internal class DefaultApplicationInsightsServiceConfigureOptions : IConfigureOptions<ApplicationInsightsServiceOptions>
{
private readonly IConfiguration configuration;
Expand All @@ -30,11 +35,6 @@ public void Configure(ApplicationInsightsServiceOptions options)
{
ApplicationInsightsExtensions.AddTelemetryConfiguration(this.configuration, options);
}

if (Debugger.IsAttached)
{
options.DeveloperMode = true;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PropertyGroup>
<!-- TargetFrameworks are defined in Test.props, but can be overridden here if needed. -->
<TargetFrameworks>net10.0;net9.0;net8.0;</TargetFrameworks>
<DefineConstants>$(DefineConstants);AI_ASPNETCORE_WEB</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand All @@ -28,10 +29,17 @@
<ProjectReference Include="..\IntegrationTests.WebApp\IntegrationTests.WebApp.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\Shared\ConfigurationTests.cs" Link="ConfigurationTests.cs" />
</ItemGroup>

<ItemGroup>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="content\**">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=11111111-2222-3333-4444-555555555555;IngestionEndpoint=http://testendpoint",
"EnableAdaptiveSampling": false,
"EnableQuickPulseMetricStream": true,
"ApplicationVersion": "Version",
"RequestCollectionOptions": {
"InjectResponseHeaders": true,
"TrackExceptions": false
},
"DependencyCollectionOptions": {
"EnableLegacyCorrelationHeadersInjection": false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=22222222-2222-3333-4444-555555555555",
"EnableAdaptiveSampling": false,
"EnableQuickPulseMetricStream": false,
"RequestCollectionOptions": {
"InjectResponseHeaders": false,
"TrackExceptions": false
},
"DependencyCollectionOptions": {
"EnableLegacyCorrelationHeadersInjection": false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=22222222-2222-3333-4444-555555555555",
"EnableAdaptiveSampling": true,
"EnableQuickPulseMetricStream": true,
"ApplicationVersion": "1.0.0",
"RequestCollectionOptions": {
"InjectResponseHeaders": true,
"TrackExceptions": true
},
"DependencyCollectionOptions": {
"EnableLegacyCorrelationHeadersInjection": true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=11111111-2222-3333-4444-555555555555;IngestionEndpoint=http://127.0.0.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"ApplicationInsights": {
"RequestCollectionOptions": {
"InjectResponseHeaders": false,
"TrackExceptions": false,
"EnableW3CDistributedTracing": false
},
"DependencyCollectionOptions": {
"EnableLegacyCorrelationHeadersInjection": false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"ApplicationInsights": {
"RequestCollectionOptions": {
"InjectResponseHeaders": true,
"TrackExceptions": true,
"EnableW3CDistributedTracing": true
},
"DependencyCollectionOptions": {
"EnableLegacyCorrelationHeadersInjection": true
}
}
}
Loading
Loading