예제 #1
0
        internal static void ConfigureApplicationInsights(HostBuilderContext context, ILoggingBuilder builder)
        {
            string appInsightsInstrumentationKey = context.Configuration[EnvironmentSettingNames.AppInsightsInstrumentationKey];
            string appInsightsConnectionString   = context.Configuration[EnvironmentSettingNames.AppInsightsConnectionString];

            // Initializing AppInsights services during placeholder mode as well to avoid the cost of JITting these objects during specialization
            if (!string.IsNullOrEmpty(appInsightsInstrumentationKey) || !string.IsNullOrEmpty(appInsightsConnectionString) || SystemEnvironment.Instance.IsPlaceholderModeEnabled())
            {
                builder.AddApplicationInsightsWebJobs(o =>
                {
                    o.InstrumentationKey = appInsightsInstrumentationKey;
                    o.ConnectionString   = appInsightsConnectionString;
                });

                builder.Services.ConfigureOptions <ApplicationInsightsLoggerOptionsSetup>();

                builder.Services.AddSingleton <ISdkVersionProvider, FunctionsSdkVersionProvider>();

                builder.Services.AddSingleton <ITelemetryInitializer, ScriptTelemetryInitializer>();

                if (SystemEnvironment.Instance.IsPlaceholderModeEnabled())
                {
                    // Disable auto-http and dependency tracking when in placeholder mode.
                    builder.Services.Configure <ApplicationInsightsLoggerOptions>(o =>
                    {
                        o.HttpAutoCollectionOptions.EnableHttpTriggerExtendedInfoCollection = false;
                        o.EnableDependencyTracking = false;
                    });
                }
            }
        }
예제 #2
0
        internal static void ConfigureApplicationInsights(HostBuilderContext context, ILoggingBuilder builder)
        {
            string appInsightsKey = context.Configuration[EnvironmentSettingNames.AppInsightsInstrumentationKey];

            // Initializing AppInsights services during placeholder mode as well to avoid the cost of JITting these objects during specialization
            if (!string.IsNullOrEmpty(appInsightsKey) || SystemEnvironment.Instance.IsPlaceholderModeEnabled())
            {
                builder.AddApplicationInsightsWebJobs(o => o.InstrumentationKey = appInsightsKey);
                builder.Services.ConfigureOptions <ApplicationInsightsLoggerOptionsSetup>();

                builder.Services.AddSingleton <ISdkVersionProvider, FunctionsSdkVersionProvider>();

                builder.Services.AddSingleton <ITelemetryInitializer, ScriptTelemetryInitializer>();

                if (SystemEnvironment.Instance.IsPlaceholderModeEnabled())
                {
                    for (int i = 0; i < builder.Services.Count; i++)
                    {
                        // This is to avoid possible race condition during specialization when disposing old AI listeners created during placeholder mode.
                        if (builder.Services[i].ServiceType == typeof(ITelemetryModule) && builder.Services[i].ImplementationFactory?.Method.ReturnType == typeof(DependencyTrackingTelemetryModule))
                        {
                            builder.Services.RemoveAt(i);
                            break;
                        }
                    }

                    // Disable auto-http tracking when in placeholder mode.
                    builder.Services.Configure <ApplicationInsightsLoggerOptions>(o =>
                    {
                        o.HttpAutoCollectionOptions.EnableHttpTriggerExtendedInfoCollection = false;
                    });
                }
            }
        }
예제 #3
0
 /// <summary>
 /// Registers Application Insights and <see cref="ApplicationInsightsLoggerProvider"/> with an <see cref="ILoggingBuilder"/>.
 /// </summary>
 public static ILoggingBuilder AddApplicationInsightsWebJobs(
     this ILoggingBuilder builder)
 {
     return(builder.AddApplicationInsightsWebJobs(null));
 }
예제 #4
0
 private void ConfigureLogger(ILoggingBuilder builder, IConfiguration config)
 {
     builder.AddConfiguration(config.GetSection("Logging"));
     builder.AddApplicationInsightsWebJobs();
 }