public ApplicationInsightsLoggerTests()
        {
            _functionCategoryName = LogCategories.CreateFunctionUserCategory(_functionShortName);
            _endTime   = _startTime.AddMilliseconds(_durationMs);
            _arguments = new Dictionary <string, string>
            {
                ["queueMessage"] = "my message",
                ["anotherParam"] = "some value"
            };

            TelemetryConfiguration config = new TelemetryConfiguration
            {
                TelemetryChannel   = _channel,
                InstrumentationKey = "some key"
            };

            // Add the same initializers that we use in the product code
            DefaultTelemetryClientFactory.AddInitializers(config);

            _client = new TelemetryClient(config);

            var descriptor = new FunctionDescriptor
            {
                FullName  = _functionFullName,
                ShortName = _functionShortName
            };

            _functionInstance = new FunctionInstance(_invocationId, null, ExecutionReason.AutomaticTrigger, null, null, descriptor);
        }
Exemple #2
0
        /// <summary>
        /// Registers an <see cref="ApplicationInsightsLoggerProvider"/> with an <see cref="ILoggerFactory"/>.
        /// </summary>
        /// <param name="loggerFactory">The factory.</param>
        /// <param name="instrumentationKey">The Application Insights instrumentation key.</param>
        /// <param name="filter">A filter that returns true if a message with the specified <see cref="LogLevel"/>
        /// and category should be logged. You can use <see cref="LogCategoryFilter.Filter(string, LogLevel)"/>
        /// or write a custom filter.</param>
        /// <returns>A <see cref="ILoggerFactory"/> for chaining additional operations.</returns>
        public static ILoggerFactory AddApplicationInsights(
            this ILoggerFactory loggerFactory,
            string instrumentationKey,
            Func <string, LogLevel, bool> filter)
        {
            ITelemetryClientFactory defaultFactory = new DefaultTelemetryClientFactory(instrumentationKey, new SamplingPercentageEstimatorSettings());

            return(AddApplicationInsights(loggerFactory, defaultFactory, filter));
        }
Exemple #3
0
        public TelemetryClient Create(string instrumentationKey, SamplingPercentageEstimatorSettings samplingSettings)
        {
            ITelemetryClientFactory defaultFactory = new DefaultTelemetryClientFactory();
            TelemetryClient         client         = defaultFactory.Create(instrumentationKey, samplingSettings);

            string assemblyVersion = ScriptHost.GetAssemblyFileVersion(typeof(ScriptHost).Assembly);

            client.Context.GetInternalContext().SdkVersion = $"azurefunctions: {assemblyVersion}";

            return(client);
        }
        public void InitializeConfiguguration_Configures()
        {
            var factory = new DefaultTelemetryClientFactory(string.Empty, null);
            var config  = factory.InitializeConfiguration();

            // Verify Initializers
            Assert.Equal(2, config.TelemetryInitializers.Count);
            // These will throw if there are not exactly one
            config.TelemetryInitializers.OfType <AzureWebAppRoleEnvironmentTelemetryInitializer>().Single();
            config.TelemetryInitializers.OfType <WebJobsTelemetryInitializer>().Single();

            // Verify Channel
            Assert.IsType <ServerTelemetryChannel>(config.TelemetryChannel);
        }
Exemple #5
0
        public ApplicationInsightsLoggerTests()
        {
            _endTime   = _startTime.AddMilliseconds(durationMs);
            _arguments = new Dictionary <string, string>
            {
                ["queueMessage"] = "my message",
                ["anotherParam"] = "some value"
            };

            TelemetryConfiguration config = new TelemetryConfiguration
            {
                TelemetryChannel   = _channel,
                InstrumentationKey = "some key"
            };

            // Add the same initializers that we use in the product code
            DefaultTelemetryClientFactory.AddInitializers(config);

            _client = new TelemetryClient(config);
        }