Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Commit

Permalink
Provide easy way to turnoff built-in modules, and an ikey read fix. (#…
Browse files Browse the repository at this point in the history
…990)

* Fix 988 989
  • Loading branch information
cijothomas authored Sep 25, 2019
1 parent f328f94 commit 1387908
Show file tree
Hide file tree
Showing 9 changed files with 435 additions and 105 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## Version 2.12.0-beta1
- Skipping version numbers to keep in sync with Base SDK.

- [Fix Null/Empty Ikey from ApplicationInsightsServiceOptions overrding one from appsettings.json](https://github.com/microsoft/ApplicationInsights-aspnetcore/issues/989)
- [Provide ApplicationInsightsServiceOptions for easy disabling of any default TelemetryModules](https://github.com/microsoft/ApplicationInsights-aspnetcore/issues/988)

## Version 2.8.0
- Updated Bask SDK/Web SDK/Logging Adaptor SDK to 2.11.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Shared.Implementation;

/// <summary>
/// Extension methods for <see cref="IServiceCollection"/> that allow adding Application Insights services to application.
Expand Down Expand Up @@ -109,19 +110,7 @@ public static IServiceCollection AddApplicationInsightsTelemetry(
ApplicationInsightsServiceOptions options)
{
services.AddApplicationInsightsTelemetry();
services.Configure((ApplicationInsightsServiceOptions o) =>
{
o.ApplicationVersion = options.ApplicationVersion;
o.DeveloperMode = options.DeveloperMode;
o.EnableAdaptiveSampling = options.EnableAdaptiveSampling;
o.EnableAuthenticationTrackingJavaScript = options.EnableAuthenticationTrackingJavaScript;
o.EnableDebugLogger = options.EnableDebugLogger;
o.EnableQuickPulseMetricStream = options.EnableQuickPulseMetricStream;
o.EndpointAddress = options.EndpointAddress;
o.InstrumentationKey = options.InstrumentationKey;
o.EnableHeartbeat = options.EnableHeartbeat;
o.AddAutoCollectedMetricExtractor = options.AddAutoCollectedMetricExtractor;
});
ConfigureAiServiceOption(services, options);
return services;
}

Expand All @@ -143,10 +132,27 @@ public static IServiceCollection AddApplicationInsightsTelemetry(this IServiceCo
AddCommonInitializers(services);

// Request Tracking.
services.AddSingleton<ITelemetryModule, RequestTrackingTelemetryModule>();
services.AddSingleton<ITelemetryModule>(provider =>
{
var options = provider.GetRequiredService<IOptions<ApplicationInsightsServiceOptions>>().Value;
var appIdProvider = provider.GetService<IApplicationIdProvider>();

if (options.EnableRequestTrackingTelemetryModule)
{
return new RequestTrackingTelemetryModule(appIdProvider);
}
else
{
return new NoOpTelemetryModule();
}
});

services.ConfigureTelemetryModule<RequestTrackingTelemetryModule>((module, options) =>
{
module.CollectionOptions = options.RequestCollectionOptions;
if(options.EnableRequestTrackingTelemetryModule)
{
module.CollectionOptions = options.RequestCollectionOptions;
}
});

AddCommonTelemetryModules(services);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,7 @@ public static IServiceCollection AddApplicationInsightsTelemetryWorkerService(
ApplicationInsightsServiceOptions options)
{
services.AddApplicationInsightsTelemetryWorkerService();
services.Configure((ApplicationInsightsServiceOptions o) =>
{
o.ApplicationVersion = options.ApplicationVersion;
o.DeveloperMode = options.DeveloperMode;
o.EnableAdaptiveSampling = options.EnableAdaptiveSampling;
o.EnableAuthenticationTrackingJavaScript = options.EnableAuthenticationTrackingJavaScript;
o.EnableDebugLogger = options.EnableDebugLogger;
o.EnableQuickPulseMetricStream = options.EnableQuickPulseMetricStream;
o.EndpointAddress = options.EndpointAddress;
o.InstrumentationKey = options.InstrumentationKey;
o.EnableHeartbeat = options.EnableHeartbeat;
o.AddAutoCollectedMetricExtractor = options.AddAutoCollectedMetricExtractor;
});
ConfigureAiServiceOption(services, options);
return services;
}

Expand Down
Loading

0 comments on commit 1387908

Please sign in to comment.