public static ITelemetryTransport Create(
     TelemetrySettings telemetrySettings,
     ImmutableExporterSettings exporterSettings)
 {
     var requestFactory = telemetrySettings switch
     {
         { Agentless : { } a } => TelemetryTransportStrategy.GetDirectIntakeFactory(a.AgentlessUri, a.ApiKey),
Exemplo n.º 2
0
        public void WhenNoUrlOrApiKeyIsProvided_UsesAgentBasedUrl()
        {
            var source = new NameValueConfigurationSource(new NameValueCollection
            {
                { ConfigurationKeys.Telemetry.Enabled, "1" }
            });

            var settings = new TelemetrySettings(source, _tracerSettings);

            settings.TelemetryUri.Should().Be(_defaultAgentUrl);
        }
Exemplo n.º 3
0
        public void WhenOnlyApiKeyIsProvided_UsesIntakeUrl()
        {
            var source = new NameValueConfigurationSource(new NameValueCollection
            {
                { ConfigurationKeys.Telemetry.Enabled, "1" },
                { ConfigurationKeys.ApiKey, "some_key" },
            });

            var settings = new TelemetrySettings(source, _tracerSettings);

            settings.TelemetryUri.Should().Be(_defaultIntakeUrl);
        }
Exemplo n.º 4
0
        public void SetsTelemetryEnabledBasedOnApiKeyAndEnabledSettings(string apiKey, string enabledSetting, bool enabled)
        {
            var source = new NameValueConfigurationSource(new NameValueCollection
            {
                { ConfigurationKeys.Telemetry.Enabled, enabledSetting },
                { ConfigurationKeys.ApiKey, apiKey },
            });

            var settings = new TelemetrySettings(source, _tracerSettings);

            settings.TelemetryEnabled.Should().Be(enabled);
        }
Exemplo n.º 5
0
        public void WhenInvalidUrlApiIsProvided_AndNoApiKey_UsesDefaultAgentUrl()
        {
            var url    = "https://sometest::";
            var source = new NameValueConfigurationSource(new NameValueCollection
            {
                { ConfigurationKeys.Telemetry.Enabled, "1" },
                { ConfigurationKeys.Telemetry.Uri, url },
            });

            var settings = new TelemetrySettings(source, _tracerSettings);

            settings.TelemetryUri.Should().Be(_defaultAgentUrl);
        }
Exemplo n.º 6
0
        public void WhenValidUrlIsProvided_AppendsSlashToPath(string url, string expected)
        {
            var source = new NameValueConfigurationSource(new NameValueCollection
            {
                { ConfigurationKeys.Telemetry.Enabled, "1" },
                { ConfigurationKeys.Telemetry.Uri, url },
                { ConfigurationKeys.ApiKey, "some_key" },
            });

            var settings = new TelemetrySettings(source, _tracerSettings);

            settings.TelemetryUri.Should().Be(expected);
        }
Exemplo n.º 7
0
        public void WhenInvalidUrlIsProvided_AndHasApiKey_UsesDefaultIntakeUrl(string url)
        {
            var source = new NameValueConfigurationSource(new NameValueCollection
            {
                { ConfigurationKeys.Telemetry.Enabled, "1" },
                { ConfigurationKeys.Telemetry.Uri, url },
                { ConfigurationKeys.ApiKey, "some_key" },
            });

            var settings = new TelemetrySettings(source, _tracerSettings);

            settings.TelemetryUri.Should().Be(_defaultIntakeUrl);
        }
        public void AddBotRuntimeTelemetryEnabled()
        {
            // Setup
            IServiceCollection services = new ServiceCollection();

            var telemetrySettings = new TelemetrySettings()
            {
                Options = new ApplicationInsightsServiceOptions()
                {
                    ConnectionString = Guid.NewGuid().ToString()
                }
            };
            IConfiguration configuration = new ConfigurationBuilder().AddRuntimeSettings(new RuntimeSettings()
            {
                Telemetry = telemetrySettings
            }).Build();

            services.AddTransient <IHttpContextAccessor, HttpContextAccessor>();
#if NETCOREAPP2_1
            services.AddTransient <IHostingEnvironment, HostingEnvironment>();
#elif NETCOREAPP3_1
            services.AddTransient <IHostingEnvironment, TestHostingEnvironment>();
#endif

            // Test
            services.AddBotRuntimeTelemetry(configuration);

            // Assert
            IServiceProvider provider = services.BuildServiceProvider();

            Assertions.AssertService <IMiddleware, TelemetryInitializerMiddleware>(services, provider, ServiceLifetime.Singleton);

            Assertions.AssertService <ITelemetryInitializer, OperationCorrelationTelemetryInitializer>(
                services,
                provider,
                ServiceLifetime.Singleton,
                searchOptions: ServiceDescriptorSearchOptions
                .SearchByImplementationType <OperationCorrelationTelemetryInitializer>());

            Assertions.AssertService <ITelemetryInitializer, TelemetryBotIdInitializer>(
                services,
                provider,
                ServiceLifetime.Singleton,
                searchOptions: ServiceDescriptorSearchOptions
                .SearchByImplementationType <TelemetryBotIdInitializer>());

            Assertions.AssertService <IBotTelemetryClient, BotTelemetryClient>(
                services,
                provider,
                ServiceLifetime.Singleton);
        }
Exemplo n.º 9
0
        public void WhenApiKeyAndDdSiteIsProvided_UsesDdSiteDomain()
        {
            var domain = "my-domain.net";
            var source = new NameValueConfigurationSource(new NameValueCollection
            {
                { ConfigurationKeys.Telemetry.Enabled, "1" },
                { ConfigurationKeys.ApiKey, "some_key" },
                { ConfigurationKeys.Site, domain },
            });

            var settings = new TelemetrySettings(source, _tracerSettings);

            settings.TelemetryUri.Should().Be($"https://instrumentation-telemetry-intake.{domain}/");
        }
        internal static void AddBotRuntimeTelemetry(this IServiceCollection services, TelemetrySettings telemetrySettings = null)
        {
            if (string.IsNullOrEmpty(telemetrySettings?.InstrumentationKey))
            {
                services.AddSingleton <IBotTelemetryClient, NullBotTelemetryClient>();
            }
            else
            {
                services.AddApplicationInsightsTelemetry(telemetrySettings.InstrumentationKey);
                services.AddSingleton <IBotTelemetryClient, BotTelemetryClient>();

                services.AddTransient <IHttpContextAccessor, HttpContextAccessor>();
                services.AddSingleton <ITelemetryInitializer, OperationCorrelationTelemetryInitializer>();
                services.AddSingleton <ITelemetryInitializer, TelemetryBotIdInitializer>();

                services.AddSingleton <IMiddleware>(sp =>
                {
                    var botTelemetryClient  = sp.GetService <IBotTelemetryClient>();
                    var httpContextAccessor = sp.GetRequiredService <IHttpContextAccessor>();

                    return(new TelemetryInitializerMiddleware(
                               httpContextAccessor: httpContextAccessor,
                               telemetryLoggerMiddleware: new TelemetryLoggerMiddleware(
                                   telemetryClient: botTelemetryClient,
                                   logPersonalInformation: telemetrySettings.LogPersonalInformation),
                               logActivityTelemetry: telemetrySettings.LogActivities));
                });
            }
        }