Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
9d47ff7
Merge pull request #1819 from microsoft/develop
rajkumar-rangaraj Apr 28, 2020
4ab6b71
Reads configuration from all defined sources from app along with all …
rajkumar-rangaraj Apr 28, 2020
c61a7ad
Added test cases and changed configuration binding.
rajkumar-rangaraj May 1, 2020
9548b0c
Merge branch 'develop' into rajrang/aspnetconfiguration
rajkumar-rangaraj May 1, 2020
6f26997
Modified test appSettings.json
rajkumar-rangaraj May 1, 2020
d9ed086
Added support to NET46 test case.
rajkumar-rangaraj May 3, 2020
4e41c7e
Modified test names
rajkumar-rangaraj May 4, 2020
b3c2ffb
Modified ChangeLog
rajkumar-rangaraj May 4, 2020
b9848bc
Merge branch 'develop' into rajrang/aspnetconfiguration
rajkumar-rangaraj May 4, 2020
916393b
Merge branch 'develop' into rajrang/aspnetconfiguration
May 4, 2020
433cf53
refactor static super class into abstract base class - tests pass
May 5, 2020
22203ae
refactor AddApplicationInsightsSettings - test pass
May 5, 2020
47a1c30
refactor super class and addApplicationInsightsTelemetry - tests pass
May 5, 2020
96171d8
move class - test pass
May 5, 2020
01d8877
rafactor usings
May 5, 2020
0f2a998
cleanup
May 5, 2020
2c87691
Remove TelemetryConfiguration.Active
May 6, 2020
72bdd3b
fixing internal reference
May 7, 2020
5c33a0a
fix module count
May 7, 2020
ebb85e7
fixing heartbeat initialization
May 8, 2020
8be254d
Merge branch 'develop' into rajrang/aspnetconfiguration
May 8, 2020
3e41354
merge from raj's branch
May 8, 2020
1661182
Merge branch 'tilee/refactor_tests+raj' into tilee/netcore_remove_act…
May 8, 2020
0a612fd
merge develop
Jun 2, 2020
a5a58de
fix merge conflict
Jun 2, 2020
691f80c
fix merge conflict
Jun 2, 2020
9eb1755
cleanup
Jun 2, 2020
a947aab
Merge branch 'develop' into tilee/netcore_active
Jun 3, 2020
2c3c446
merge develop
Jun 5, 2020
49b7628
fix merge conflict
Jun 5, 2020
394f4c0
cleanup
Jun 5, 2020
031a266
adding EnableDiagnosticsTelemetryModule
Jun 5, 2020
db4ef1d
Merge branch 'develop' into tilee/netcore_active
Jun 5, 2020
3791642
update public api
Jun 5, 2020
72b57fe
fix
Jun 5, 2020
6efc7aa
fix for test failure
Jun 9, 2020
e05f36f
Merge branch 'develop' into tilee/netcore_active
Jun 16, 2020
6a29604
Merge branch 'tilee/netcore_active' of https://github.com/microsoft/A…
Jun 17, 2020
3e30aa2
Merge branch 'develop' into tilee/netcore_active
Jun 17, 2020
5ec1092
Merge branch 'tilee/netcore_active' of https://github.com/microsoft/A…
Jun 17, 2020
4e85bd5
fix public api
Jun 17, 2020
95046a7
fix public api for real
Jun 17, 2020
47bdeb2
backwards compat for .Active and some tests
Jun 18, 2020
26085e5
cleanup
Jun 18, 2020
39196bc
fix compile error
Jun 18, 2020
1f2c30e
testing fix for tests
Jun 19, 2020
221838a
testing fix for GetEntryAssembly
Jun 19, 2020
e4ddf76
add new test for BackwardsCompat
Jun 19, 2020
0580086
tests
Jun 20, 2020
a74fc2d
cleanup
Jun 20, 2020
5c2d0b5
cleanup
Jun 22, 2020
622f576
fix for failing tests
Jun 23, 2020
8a512f7
cleanup the AddSingleton
Jun 24, 2020
b081d9d
pushing work in progress for Cijo
Jun 26, 2020
e34d467
incorporating Cijo's feedback.
Jun 30, 2020
4a07f2c
merge develop
Jun 30, 2020
9d594aa
cleanup
Jun 30, 2020
df6d2f7
rename EnableActiveTelemetryConfigurationSetup
Jun 30, 2020
7cc750b
Merge branch 'develop' into tilee/netcore_active
Jun 30, 2020
1f6c080
remove backcompat TC.Active from WorkerService
Jun 30, 2020
1c50885
fix enable settings
Jul 1, 2020
73beae3
Merge branch 'develop' into tilee/netcore_active
Jul 1, 2020
e19e30c
cleanup
Jul 1, 2020
a7506d2
adding tests for suggested changes and fixed compile issues
Jul 2, 2020
e040742
cleanup
Jul 2, 2020
4036ef6
Merge branch 'develop' into tilee/netcore_active
Jul 2, 2020
7c0f857
comment
Jul 2, 2020
7c4cd62
last tests
Jul 2, 2020
d61ba47
fix worker service test
Jul 2, 2020
739c266
cleanup
Jul 2, 2020
ebfa752
merge develop
Jul 2, 2020
f9d8b5e
revert changes to ApplicationNameProvider
Jul 2, 2020
4acda76
revert
Jul 2, 2020
a288c52
clean
Jul 2, 2020
8f0e7a5
code review comments
Jul 6, 2020
a600d03
Merge branch 'develop' into tilee/netcore_active
Jul 6, 2020
13e4c9c
changelog
Jul 6, 2020
aee2453
code review comments
Jul 7, 2020
182d3ea
fix comments
Jul 7, 2020
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
28 changes: 6 additions & 22 deletions NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ namespace Microsoft.ApplicationInsights.WorkerService
/// </summary>
public class ApplicationInsightsServiceOptions
{
private bool enableAppServicesHeartbeatTelemetryModule = true;
private bool enableAzureInstanceMetadataTelemetryModule = true;
private bool enableHeartbeat = true;

/// <summary>
/// Gets or sets a value indicating whether QuickPulseTelemetryModule and QuickPulseTelemetryProcessor are registered with the configuration.
/// Setting EnableQuickPulseMetricStream to <value>false</value>, will disable the default quick pulse metric stream. Defaults to <value>true</value>.
Expand All @@ -31,24 +27,16 @@ public class ApplicationInsightsServiceOptions
/// <summary>
/// Gets or sets a value indicating whether AppServicesHeartbeatTelemetryModule should be enabled.
/// Defaults to <value>true</value>.
/// IMPORTANT: This setting will be disabled if <see cref="EnableDiagnosticsTelemetryModule"/> is set to false.
/// IMPORTANT: This setting will be ignored if <see cref="EnableDiagnosticsTelemetryModule"/> is set to false.
/// </summary>
public bool EnableAppServicesHeartbeatTelemetryModule
{
get => this.enableAppServicesHeartbeatTelemetryModule && this.EnableDiagnosticsTelemetryModule;
set => this.enableAppServicesHeartbeatTelemetryModule = value;
}
public bool EnableAppServicesHeartbeatTelemetryModule { get; set; } = true;

/// <summary>
/// Gets or sets a value indicating whether AzureInstanceMetadataTelemetryModule should be enabled.
/// Defaults to <value>true</value>.
/// IMPORTANT: This setting will be disabled if <see cref="EnableDiagnosticsTelemetryModule"/> is set to false.
/// IMPORTANT: This setting will be ignored if <see cref="EnableDiagnosticsTelemetryModule"/> is set to false.
/// </summary>
public bool EnableAzureInstanceMetadataTelemetryModule
{
get => this.enableAzureInstanceMetadataTelemetryModule && this.EnableDiagnosticsTelemetryModule;
set => this.enableAzureInstanceMetadataTelemetryModule = value;
}
public bool EnableAzureInstanceMetadataTelemetryModule { get; set; } = true;

/// <summary>
/// Gets or sets a value indicating whether DependencyTrackingTelemetryModule should be enabled.
Expand Down Expand Up @@ -102,13 +90,9 @@ public bool EnableAzureInstanceMetadataTelemetryModule

/// <summary>
/// Gets or sets a value indicating whether heartbeats are enabled.
/// IMPORTANT: This setting will be disabled if <see cref="EnableDiagnosticsTelemetryModule"/> is set to false.
/// IMPORTANT: This setting will be ignored if <see cref="EnableDiagnosticsTelemetryModule"/> is set to false.
/// </summary>
public bool EnableHeartbeat
{
get => this.enableHeartbeat && this.EnableDiagnosticsTelemetryModule;
set => this.enableHeartbeat = value;
}
public bool EnableHeartbeat { get; set; } = true;

/// <summary>
/// Gets or sets a value indicating whether AutoCollectedMetricExtractors are added or not.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,12 @@ public void Configure(TelemetryConfiguration configuration)
}
catch (Exception ex)
{
throw new Exception($"Failed to initialize module '{module.GetType()}'", ex);
var tempEx = new Exception($"Failed to initialize module '{module.GetType()}'", ex);
#if AI_ASPNETCORE_WEB
AspNetCoreEventSource.Instance.TelemetryConfigurationSetupFailure(tempEx.ToInvariantString());
#else
WorkerServiceEventSource.Instance.TelemetryConfigurationSetupFailure(tempEx.ToInvariantString());
#endif
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;

using Microsoft.ApplicationInsights.AspNetCore.Extensions;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.DependencyCollector;
using Microsoft.ApplicationInsights.Extensibility;
#if NETCOREAPP
Expand Down Expand Up @@ -38,7 +39,7 @@ namespace Microsoft.ApplicationInsights.AspNetCore.Tests.Extensions
/// </remarks>
public class ApplicationInsightsServiceOptionsTests
{
private static IServiceProvider TestShim(string configType, bool isEnabled, Action<ApplicationInsightsServiceOptions, bool> testConfig)
private static IServiceProvider TestShim(string configType, bool isEnabled, Action<ApplicationInsightsServiceOptions, bool> testConfig, Action<IServiceCollection> servicesConfig = null)
{
// ARRANGE
Action<ApplicationInsightsServiceOptions> serviceOptions = null;
Expand All @@ -56,6 +57,7 @@ private static IServiceProvider TestShim(string configType, bool isEnabled, Acti
var services = CreateServicesAndAddApplicationinsightsWorker(
jsonPath: filePath,
serviceOptions: serviceOptions,
servicesConfig: servicesConfig,
useDefaultConfig: configType == "DefaultConfiguration" ? true : false);

IServiceProvider serviceProvider = services.BuildServiceProvider();
Expand All @@ -70,7 +72,7 @@ private static IServiceProvider TestShim(string configType, bool isEnabled, Acti
return serviceProvider;
}

private static ServiceCollection CreateServicesAndAddApplicationinsightsWorker(string jsonPath, Action<ApplicationInsightsServiceOptions> serviceOptions = null, bool useDefaultConfig = true)
private static ServiceCollection CreateServicesAndAddApplicationinsightsWorker(string jsonPath, Action<ApplicationInsightsServiceOptions> serviceOptions = null, Action<IServiceCollection> servicesConfig = null, bool useDefaultConfig = true)
{
IConfigurationRoot config;
var services = new ServiceCollection()
Expand Down Expand Up @@ -113,6 +115,8 @@ private static ServiceCollection CreateServicesAndAddApplicationinsightsWorker(s
}
#endif

servicesConfig?.Invoke(services);

if (serviceOptions != null)
{
services.Configure(serviceOptions);
Expand Down Expand Up @@ -147,19 +151,37 @@ public static void UserCanEnableAndDisableTelemetryConfigurationActive(string co

// IMPORTANT: This is the same ikey specified in the config files that will be used for this test.
string testString = "22222222-2222-3333-4444-555555555555";
var testTelemetryInitializer = new FakeTelemetryInitializer();

IServiceProvider serviceProvider = TestShim(configType: configType, isEnabled: isEnable,
testConfig: (o, b) => {
IServiceProvider serviceProvider = TestShim(
configType: configType,
isEnabled: isEnable,
testConfig: (o, b) =>
{
o.EnableActiveTelemetryConfigurationSetup = b;
o.InstrumentationKey = testString;
});
},
servicesConfig: (services) => services.AddSingleton<ITelemetryInitializer>(testTelemetryInitializer)
);

// TelemetryConfiguration from DI should have custom set InstrumentationKey
// TelemetryConfiguration from DI should have custom set InstrumentationKey and TelemetryInitializer
var telemetryConfiguration = serviceProvider.GetTelemetryConfiguration();
Assert.Equal(testString, telemetryConfiguration.InstrumentationKey);
Assert.Same(testTelemetryInitializer, telemetryConfiguration.TelemetryInitializers.OfType<FakeTelemetryInitializer>().Single());

// TelemetryConfiguration.Active will only have custom set InstrumentationKey if BackwardsCompat was enabled.
// TelemetryConfiguration.Active will only have custom set InstrumentationKey if .Active was enabled.
Assert.Equal(testString.Equals(TelemetryConfiguration.Active.InstrumentationKey), isEnable);

// TelemetryConfiguration.Active will only have custom TelemetryInitializer if .Active was enabled
var activeTelemetryInitializer = TelemetryConfiguration.Active.TelemetryInitializers.OfType<FakeTelemetryInitializer>().SingleOrDefault();
if (isEnable)
{
Assert.Same(testTelemetryInitializer, activeTelemetryInitializer);
}
else
{
Assert.Null(activeTelemetryInitializer);
}

#pragma warning restore CS0618 // Type or member is obsolete
}
Expand Down Expand Up @@ -357,36 +379,5 @@ public static void UserCanEnableAndDisableHeartbeatFeature(string configType, bo
Assert.True(module.IsInitialized, "module was not initialized");
Assert.Equal(isEnable, module.IsHeartbeatEnabled);
}

[Fact]
public static void VerifyCouplingOfHeartbeatSettingsWithDiagnosticTelemetryModule()
{
var options = new ApplicationInsightsServiceOptions();

// Verify default values
Assert.True(options.EnableHeartbeat);
Assert.True(options.EnableAzureInstanceMetadataTelemetryModule);
Assert.True(options.EnableAppServicesHeartbeatTelemetryModule);
Assert.True(options.EnableDiagnosticsTelemetryModule);

// Verify disabling DiagnosticsTelemetryModule also disables all heartbeat settings
options.EnableDiagnosticsTelemetryModule = false;
Assert.False(options.EnableHeartbeat);
Assert.False(options.EnableAzureInstanceMetadataTelemetryModule);
Assert.False(options.EnableAppServicesHeartbeatTelemetryModule);
Assert.False(options.EnableDiagnosticsTelemetryModule);

// Verify that heartbeat can be disabled but DiagnosticsTelemetryModule will remain enabled.
options = new ApplicationInsightsServiceOptions
{
EnableHeartbeat = false,
EnableAzureInstanceMetadataTelemetryModule = false,
EnableAppServicesHeartbeatTelemetryModule = false,
};
Assert.False(options.EnableHeartbeat);
Assert.False(options.EnableAzureInstanceMetadataTelemetryModule);
Assert.False(options.EnableAppServicesHeartbeatTelemetryModule);
Assert.True(options.EnableDiagnosticsTelemetryModule);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
using System;
using System.Collections.Generic;
using System.ComponentModel;

using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.Extensibility.Implementation;
using Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing;
Expand Down Expand Up @@ -48,6 +50,7 @@ public AppServicesHeartbeatTelemetryModule() : this(null)
/// <remarks>
/// This is expected to be an instance of <see cref="DiagnosticsTelemetryModule"/>.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public IHeartbeatPropertyManager HeartbeatPropertyManager
{
get
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Microsoft.ApplicationInsights.WindowsServer
{
using System;
using System.ComponentModel;
using System.Threading.Tasks;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.Extensibility.Implementation;
Expand Down Expand Up @@ -30,6 +31,7 @@ public AzureInstanceMetadataTelemetryModule() : this(null)
/// <remarks>
/// This is expected to be an instance of <see cref="DiagnosticsTelemetryModule"/>.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public IHeartbeatPropertyManager HeartbeatPropertyManager
{
get
Expand Down