// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            // Deserialize telemetry options into object
            var telemetryOptions = new TelemetryOptions();

            Configuration.GetSection("Telemetry").Bind(telemetryOptions);

            // Infrastructure Dependencies - Message Bus
            services.AddInfrastructureMessageBus();

            if (IsAzure())
            {
                services.AddAzureMessageBus();
            }
            else
            {
                services.AddRabbitMQMessageBus();
            }

            // Configure telemetry.
            services.AddTelemetry(telemetryOptions);

            services.AddHostedService <ExpensesHistoryHostedService>();
        }
        public TelemetryServiceTest()
        {
            _principalAccessor           = Mock.Of <IPrincipalAccessor>();
            _principalAccessor.Principal = new GenericPrincipal(new GenericIdentity("username"), null);

            var moduleTable = new Mock <ModuleTable>();

            moduleTable
            .Setup(_ => _.GetModules())
            .Returns(new[] { new ShellModule("CMS", null, null) });

            _uiUserProviderMock = new Mock <UIUserProvider>();
            _uiUserProviderMock.Setup(x => x.GetUser("username"))
            .Returns(new FakeUser {
                CreationDate = new DateTime(2010, 1, 1)
            });

            _telemetryOptions = new TelemetryOptions {
                OptedIn = true
            };
            _licensingOptions = new LicensingOptions
            {
                LicenseKey = "LicenseKey"
            };
            _httpResponseMessage = new HttpResponseMessage
            {
                Content = new StringContent("{\"key\":true}")
            };
            _telemetryService = new TelemetryService(_telemetryOptions, _licensingOptions, _principalAccessor,
                                                     moduleTable.Object, new JsonObjectSerializer(), _uiUserProviderMock.Object)
            {
                GetRequestAsync = (string url) => Task.FromResult(_httpResponseMessage),
            };
        }
Exemple #3
0
        public void IsTelemetryEnabled_WhenIsDxcEnvironment_IsFalse_ShouldBeFalse()
        {
            var options = new TelemetryOptions
            {
                IsDxcEnvironment = false
            };

            Assert.False(options.IsTelemetryEnabled());
        }
Exemple #4
0
        public void IsTelemetryEnabled_WhenOptedIn_IsFalse_ShouldBeFalse()
        {
            var options = new TelemetryOptions
            {
                OptedIn = false
            };

            Assert.False(options.IsTelemetryEnabled());
        }
        public void Transform_WhenEnvironmentName_IsNull_ShouldSetIsDxcEnvironment_AsFalse()
        {
            var options  = new TelemetryOptions();
            var settings = new NameValueCollection();

            TelemetryOptionsTransform.Transform(options, settings);

            Assert.False(options.IsDxcEnvironment);
        }
Exemple #6
0
        public void IsTelemetryEnabled_WhenOptedInAndIsDxcEnvironment_AreTrue_ShouldBeTrue()
        {
            var options = new TelemetryOptions
            {
                IsDxcEnvironment = true,
                OptedIn          = true
            };

            Assert.True(options.IsTelemetryEnabled());
        }
        public void Transform_WhenEnvironmentName_IsNotNull_ShouldSetIsDxcEnvironment_AsTrue()
        {
            var options  = new TelemetryOptions();
            var settings = new NameValueCollection
            {
                { TelemetryOptionsTransform.EnvironmentNameConfigKey, "Production" }
            };

            TelemetryOptionsTransform.Transform(options, settings);

            Assert.True(options.IsDxcEnvironment);
        }
Exemple #8
0
        public static void AddWebApiApplicationInsights(this IServiceCollection services, Action <TelemetryOptions> optionsSetup)
        {
            var options = new TelemetryOptions();

            optionsSetup(options);

            services.AddApplicationInsightsTelemetry(config =>
            {
                config.InstrumentationKey     = options.InstrumentationKey;
                config.EnableAdaptiveSampling = options.EnableAdaptiveSampling;

                config.RequestCollectionOptions.InjectResponseHeaders = true;
            });

            DiagnosticListener.AllListeners.Subscribe(new ServiceBusDiagnosticListener());
        }
 public static void AddTelemetry(this IServiceCollection services, TelemetryOptions telemetryOptions)
 {
     if (telemetryOptions.Enabled)
     {
         services.AddOpenTelemetry((sp, builder) =>
         {
             if (telemetryOptions.Jaeger.Enabled)
             {
                 builder
                 .UseJaeger(options =>
                 {
                     options.ServiceName = TracerServiceName;
                     options.AgentHost   = telemetryOptions.Jaeger.AgentHost;
                     options.AgentPort   = telemetryOptions.Jaeger.AgentPort;
                 });
             }
             else if (telemetryOptions.ApplicationInsights.Enabled)
             {
                 builder
                 .UseApplicationInsights(options =>
                 {
                     options.InstrumentationKey = telemetryOptions.ApplicationInsights.InstrumentationKey;
                 });
             }
             builder
             .SetSampler(new AlwaysOnSampler())
             .AddRequestAdapter()
             .AddDependencyAdapter(config =>
             {
                 config.SetHttpFlavor = true;
             })
             .AddAdapter((tracer) => new RabbitMQInstrumentation(tracer))
             .SetResource(new Resource(new Dictionary <string, object>
             {
                 { "service.name", TracerServiceName }
             }));
         });
     }
 }
Exemple #10
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            // Deserialize telemetry options into object
            var telemetryOptions = new TelemetryOptions();

            Configuration.GetSection("Telemetry").Bind(telemetryOptions);

            // Application AutoMapper extension
            services.AddApplicationAutoMapper();

            // Application Dependencies - Command Handlers only
            services.AddApplicationCommandHandlers();
            services.AddScoped <INotificationHandler <InvoiceCreatedEvent>, StatementCreatorEventHandler>();

            // Infrastructure Dependencies - Database
            services.AddInfrastructureDatabase();

            // Infrastructure Dependencies - Message Bus
            services.AddInfrastructureMessageBus();

            if (IsAzure())
            {
                services.AddAzureMessageBus();
            }
            else
            {
                services.AddRabbitMQMessageBus();
            }

            // Configure telemetry.
            services.AddTelemetry(telemetryOptions);

            services.AddHostedService <StatementCreatorHostedService>();
        }
Exemple #11
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services
            .AddControllers()
            .SetCompatibilityVersion(CompatibilityVersion.Latest)
            .AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
            });

            services.AddCors(options =>
            {
                options.AddPolicy(CORS_POLICY,
                                  builder =>
                {
                    builder
                    .WithOrigins("http://localhost:4200")
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });
            // Deserialize auth options into object
            var authOptions = new AuthOptions();

            Configuration.GetSection("Auth0").Bind(authOptions);

            // Deserialize telemetry options into object
            var telemetryOptions = new TelemetryOptions();

            Configuration.GetSection("Telemetry").Bind(telemetryOptions);

            // Register the Swagger generator, defining one or more Swagger documents
            services.AddSwagger(authOptions);

            // Application AutoMapper extension
            services.AddApplicationAutoMapper();

            // Application Dependencies
            services.AddApplicationDependencies();

            // Infrastructure Dependencies - Database
            services.AddInfrastructureDatabase();

            // Infrastructure Dependencies - Message Bus
            services.AddInfrastructureMessageBus();

            if (IsAzure())
            {
                services.AddAzureMessageBus();
            }
            else
            {
                services.AddRabbitMQMessageBus();
            }

            // Add Authentication Services
            services.AddCustomAuthentication(authOptions);

            // Configure authorization.
            services.AddCustomAuthorization(authOptions);

            // Configure telemetry.
            services.AddTelemetry(telemetryOptions);
        }
 public static void Transform(TelemetryOptions options)
 => Transform(options, ConfigurationManager.AppSettings);
        internal static void Transform(TelemetryOptions options, NameValueCollection settings)
        {
            var environmentName = settings.Get(EnvironmentNameConfigKey);

            options.IsDxcEnvironment = environmentName != null;
        }