@@ -18,14 +18,18 @@ public static partial class ApplicationInsightsExtensions
1818 /// Enables Application Insights for Kubernetes on the Default TelemetryConfiguration in the dependency injection container with custom options.
1919 /// </summary>
2020 /// <param name="services">Collection of service descriptors.</param>
21- /// <param name="applyOptions">Action to customize the configuration of Application Insights for Kubernetes.</param>
2221 /// <param name="diagnosticLogLevel">Sets the diagnostics log levels for the enricher.</param>
22+ /// <param name="disableBackgroundService">If true, the Application Insights enricher library will not use any background (hosted) services,
23+ /// and Kubernetes information will not be fetched automatically. Hosted services are not allowed in some environments, e.g. Azure Function.
24+ /// For more information see https://github.com/Azure/azure-functions-host/issues/5447#issuecomment-575368316</param>
25+ /// <param name="applyOptions">Action to customize the configuration of Application Insights for Kubernetes.</param>
2326 /// <param name="clusterCheck">Provides a custom implementation to check whether it is inside kubernetes cluster or not.</param>
2427 /// <returns>The service collection for chaining the next operation.</returns>
2528 public static IServiceCollection AddApplicationInsightsKubernetesEnricher (
2629 this IServiceCollection services ,
27- Action < AppInsightsForKubernetesOptions > ? applyOptions = default ,
2830 LogLevel ? diagnosticLogLevel = LogLevel . None ,
31+ bool disableBackgroundService = false ,
32+ Action < AppInsightsForKubernetesOptions > ? applyOptions = default ,
2933 IClusterEnvironmentCheck ? clusterCheck = default )
3034 {
3135 diagnosticLogLevel ??= LogLevel . None ; // Default to None.
@@ -37,7 +41,7 @@ public static IServiceCollection AddApplicationInsightsKubernetesEnricher(
3741
3842 if ( ! KubernetesTelemetryInitializerExists ( services ) )
3943 {
40- services . ConfigureKubernetesTelemetryInitializer ( applyOptions , clusterCheck ) ;
44+ services . ConfigureKubernetesTelemetryInitializer ( applyOptions , clusterCheck , disableBackgroundService ) ;
4145 }
4246 return services ;
4347 }
@@ -48,7 +52,7 @@ public static IServiceCollection AddApplicationInsightsKubernetesEnricher(
4852 public static void StartApplicationInsightsKubernetesEnricher ( this IServiceProvider serviceProvider )
4953 {
5054 IK8sInfoBootstrap ? k8sInfoBootstrap = serviceProvider . GetService < IK8sInfoBootstrap > ( ) ;
51- if ( k8sInfoBootstrap is null )
55+ if ( k8sInfoBootstrap is null )
5256 {
5357 _logger . LogInformation ( "No service registered by type {0}. Either not running in a Kubernetes cluster or `{1}()` wasn't called on the service collection." , nameof ( IK8sInfoBootstrap ) , nameof ( AddApplicationInsightsKubernetesEnricher ) ) ;
5458 return ;
@@ -69,9 +73,10 @@ private static bool KubernetesTelemetryInitializerExists(IServiceCollection serv
6973 internal static void ConfigureKubernetesTelemetryInitializer (
7074 this IServiceCollection services ,
7175 Action < AppInsightsForKubernetesOptions > ? overwriteOptions ,
72- IClusterEnvironmentCheck ? clusterCheck )
76+ IClusterEnvironmentCheck ? clusterCheck ,
77+ bool skipRegisterBackendService = false )
7378 {
74- IKubernetesServiceCollectionBuilder kubernetesServiceCollectionBuilder = new KubernetesServiceCollectionBuilder ( overwriteOptions , clusterCheck ) ;
79+ IKubernetesServiceCollectionBuilder kubernetesServiceCollectionBuilder = new KubernetesServiceCollectionBuilder ( overwriteOptions , clusterCheck , skipRegisterBackendService ) ;
7580 _ = kubernetesServiceCollectionBuilder . RegisterServices ( services ) ;
7681 }
7782 }
0 commit comments