From a04cef97ef3d2c3ca60faa5e112977f2737f27a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Tom=C3=A1s?= Date: Wed, 11 Oct 2017 16:26:44 +0200 Subject: [PATCH] Added AppInsights service --- .env | 1 + docker-compose.override.yml | 12 +++++++++++- src/Services/Basket/Basket.API/Basket.API.csproj | 1 + src/Services/Basket/Basket.API/Program.cs | 5 +++++ src/Services/Basket/Basket.API/Startup.cs | 11 ++++++++--- src/Services/Basket/Basket.API/appsettings.json | 5 ++++- src/Services/Catalog/Catalog.API/Catalog.API.csproj | 1 + src/Services/Catalog/Catalog.API/Program.cs | 8 +++++++- src/Services/Catalog/Catalog.API/Startup.cs | 4 ++++ src/Services/Catalog/Catalog.API/appsettings.json | 5 ++++- .../Identity/Identity.API/Identity.API.csproj | 1 + src/Services/Identity/Identity.API/Program.cs | 5 +++++ src/Services/Identity/Identity.API/Startup.cs | 6 +++++- src/Services/Identity/Identity.API/appsettings.json | 3 +++ .../Location/Locations.API/Locations.API.csproj | 1 + src/Services/Location/Locations.API/Program.cs | 9 ++++++++- src/Services/Location/Locations.API/Startup.cs | 5 +++++ src/Services/Location/Locations.API/appsettings.json | 5 ++++- .../Marketing/Marketing.API/Marketing.API.csproj | 8 ++++++++ src/Services/Marketing/Marketing.API/Program.cs | 10 +++++++++- src/Services/Marketing/Marketing.API/Startup.cs | 5 +++++ .../Marketing/Marketing.API/appsettings.json | 10 ++++++---- .../Ordering/Ordering.API/Ordering.API.csproj | 1 + src/Services/Ordering/Ordering.API/Program.cs | 9 ++++++++- src/Services/Ordering/Ordering.API/Startup.cs | 6 +++++- src/Services/Ordering/Ordering.API/settings.json | 5 ++++- src/Services/Payment/Payment.API/Payment.API.csproj | 1 + src/Services/Payment/Payment.API/Program.cs | 9 ++++++++- src/Services/Payment/Payment.API/appsettings.json | 5 ++++- src/Web/WebMVC/Program.cs | 9 ++++++++- src/Web/WebMVC/Startup.cs | 4 ++++ src/Web/WebMVC/WebMVC.csproj | 1 + src/Web/WebMVC/appsettings.json | 3 +++ src/Web/WebSPA/Program.cs | 6 ++++++ src/Web/WebSPA/Startup.cs | 6 ++++++ src/Web/WebSPA/WebSPA.csproj | 1 + src/Web/WebSPA/appsettings.json | 3 +++ src/Web/WebStatus/Program.cs | 9 ++++++++- src/Web/WebStatus/Startup.cs | 7 ++++++- src/Web/WebStatus/WebStatus.csproj | 1 + src/Web/WebStatus/appsettings.json | 5 ++++- 41 files changed, 188 insertions(+), 24 deletions(-) diff --git a/.env b/.env index 797e5fc5c..a1c927e77 100644 --- a/.env +++ b/.env @@ -23,3 +23,4 @@ ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP=10.121.122.92 #ESHOP_AZURE_STORAGE_MARKETING_KEY= #ESHOP_SERVICE_BUS_USERNAME= #ESHOP_SERVICE_BUS_PASSWORD= +#INSTRUMENTATION_KEY= diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 39110c1be..ece9c804b 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -19,6 +19,7 @@ services: - EventBusUserName=${ESHOP_SERVICE_BUS_USERNAME} - EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD} - AzureServiceBusEnabled=False + - ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY} ports: - "5103:80" @@ -36,6 +37,7 @@ services: - UseCustomizationData=True - AzureServiceBusEnabled=False - AzureStorageEnabled=False + - ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY} ports: - "5101:80" @@ -51,7 +53,8 @@ services: - MarketingApiClient=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5110 - BasketApiClient=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5103 - OrderingApiClient=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5102 - - UseCustomizationData=True + - UseCustomizationData=True + - ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY} ports: - "5105:80" @@ -69,6 +72,7 @@ services: - AzureServiceBusEnabled=False - CheckUpdateTime=30000 - GracePeriodTime=1 + - ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY} ports: - "5102:80" @@ -90,6 +94,7 @@ services: - AzureStorageAccountKey=${ESHOP_AZURE_STORAGE_MARKETING_KEY} - AzureServiceBusEnabled=False - AzureStorageEnabled=False + - ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY} ports: - "5110:80" @@ -110,6 +115,7 @@ services: - MarketingUrlHC=http://marketing.api/hc - PaymentUrlHC=http://payment.api/hc - UseCustomizationData=True + - ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY} ports: - "5104:80" @@ -130,6 +136,7 @@ services: - MarketingUrlHC=http://marketing.api/hc - PaymentUrlHC=http://payment.api/hc - UseCustomizationData=True + - ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY} ports: - "5100:80" @@ -146,6 +153,7 @@ services: - PaymentUrl=http://payment.api/hc - mvc=http://webmvc/hc - spa=http://webspa/hc + - ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY} ports: - "5107:80" @@ -157,6 +165,7 @@ services: - EventBusUserName=${ESHOP_SERVICE_BUS_USERNAME} - EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD} - AzureServiceBusEnabled=False + - ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY} ports: - "5108:80" @@ -172,6 +181,7 @@ services: - EventBusUserName=${ESHOP_SERVICE_BUS_USERNAME} - EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD} - AzureServiceBusEnabled=False + - ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY} ports: - "5109:80" diff --git a/src/Services/Basket/Basket.API/Basket.API.csproj b/src/Services/Basket/Basket.API/Basket.API.csproj index 8864c9d06..4943faf19 100644 --- a/src/Services/Basket/Basket.API/Basket.API.csproj +++ b/src/Services/Basket/Basket.API/Basket.API.csproj @@ -16,6 +16,7 @@ + diff --git a/src/Services/Basket/Basket.API/Program.cs b/src/Services/Basket/Basket.API/Program.cs index 53b6f311f..2ae9b47b2 100644 --- a/src/Services/Basket/Basket.API/Program.cs +++ b/src/Services/Basket/Basket.API/Program.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using System.IO; @@ -23,6 +24,10 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API .UseHealthChecks("/hc") .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup() + .ConfigureAppConfiguration((builderContext, config) => + { + config.AddEnvironmentVariables(); + }) .ConfigureLogging((hostingContext, builder) => { builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); diff --git a/src/Services/Basket/Basket.API/Startup.cs b/src/Services/Basket/Basket.API/Startup.cs index b82a912d8..e7f3c1276 100644 --- a/src/Services/Basket/Basket.API/Startup.cs +++ b/src/Services/Basket/Basket.API/Startup.cs @@ -43,7 +43,9 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API // This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) - { + { + services.AddApplicationInsightsTelemetry(Configuration); + // Add framework services. services.AddMvc(options => { @@ -167,14 +169,17 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { + loggerFactory.AddAzureWebAppDiagnostics(); + loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); var pathBase = Configuration["PATH_BASE"]; if (!string.IsNullOrEmpty(pathBase)) { app.UsePathBase(pathBase); - } + } + app.UseStaticFiles(); app.UseCors("CorsPolicy"); diff --git a/src/Services/Basket/Basket.API/appsettings.json b/src/Services/Basket/Basket.API/appsettings.json index f062f76d7..027fe9d23 100644 --- a/src/Services/Basket/Basket.API/appsettings.json +++ b/src/Services/Basket/Basket.API/appsettings.json @@ -10,5 +10,8 @@ "IdentityUrl": "http://localhost:5105", "ConnectionString": "127.0.0.1", "AzureServiceBusEnabled": false, - "SubscriptionClientName": "Basket" + "SubscriptionClientName": "Basket", + "ApplicationInsights": { + "InstrumentationKey": "" + } } \ No newline at end of file diff --git a/src/Services/Catalog/Catalog.API/Catalog.API.csproj b/src/Services/Catalog/Catalog.API/Catalog.API.csproj index 0d8c77efd..a2a4baad9 100644 --- a/src/Services/Catalog/Catalog.API/Catalog.API.csproj +++ b/src/Services/Catalog/Catalog.API/Catalog.API.csproj @@ -35,6 +35,7 @@ + diff --git a/src/Services/Catalog/Catalog.API/Program.cs b/src/Services/Catalog/Catalog.API/Program.cs index 1eeeeb5ec..7d18e2e66 100644 --- a/src/Services/Catalog/Catalog.API/Program.cs +++ b/src/Services/Catalog/Catalog.API/Program.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF; using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -32,14 +33,19 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API WebHost.CreateDefaultBuilder(args) .UseStartup() .UseHealthChecks("/hc") - .UseContentRoot(Directory.GetCurrentDirectory()) + .UseContentRoot(Directory.GetCurrentDirectory()) .UseWebRoot("Pics") + .ConfigureAppConfiguration((builderContext, config) => + { + config.AddEnvironmentVariables(); + }) .ConfigureLogging((hostingContext, builder) => { builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); builder.AddConsole(); builder.AddDebug(); }) + .UseApplicationInsights() .Build(); } } \ No newline at end of file diff --git a/src/Services/Catalog/Catalog.API/Startup.cs b/src/Services/Catalog/Catalog.API/Startup.cs index befe82828..34b80526b 100644 --- a/src/Services/Catalog/Catalog.API/Startup.cs +++ b/src/Services/Catalog/Catalog.API/Startup.cs @@ -41,6 +41,8 @@ { // Add framework services. + services.AddApplicationInsightsTelemetry(Configuration); + services.AddHealthChecks(checks => { var minutes = 1; @@ -160,6 +162,8 @@ loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); + loggerFactory.AddAzureWebAppDiagnostics(); + loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); var pathBase = Configuration["PATH_BASE"]; if (!string.IsNullOrEmpty(pathBase)) diff --git a/src/Services/Catalog/Catalog.API/appsettings.json b/src/Services/Catalog/Catalog.API/appsettings.json index dafeca845..dc4e0aa5c 100644 --- a/src/Services/Catalog/Catalog.API/appsettings.json +++ b/src/Services/Catalog/Catalog.API/appsettings.json @@ -12,5 +12,8 @@ }, "AzureServiceBusEnabled": false, "AzureStorageEnabled": false, - "SubscriptionClientName": "Catalog" + "SubscriptionClientName": "Catalog", + "ApplicationInsights": { + "InstrumentationKey": "" + } } diff --git a/src/Services/Identity/Identity.API/Identity.API.csproj b/src/Services/Identity/Identity.API/Identity.API.csproj index cee95b94f..a84d21d55 100644 --- a/src/Services/Identity/Identity.API/Identity.API.csproj +++ b/src/Services/Identity/Identity.API/Identity.API.csproj @@ -16,6 +16,7 @@ + diff --git a/src/Services/Identity/Identity.API/Program.cs b/src/Services/Identity/Identity.API/Program.cs index 0b32b4549..7b73838e6 100644 --- a/src/Services/Identity/Identity.API/Program.cs +++ b/src/Services/Identity/Identity.API/Program.cs @@ -43,12 +43,17 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup() + .ConfigureAppConfiguration((builderContext, config) => + { + config.AddEnvironmentVariables(); + }) .ConfigureLogging((hostingContext, builder) => { builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); builder.AddConsole(); builder.AddDebug(); }) + .UseApplicationInsights() .Build(); } } diff --git a/src/Services/Identity/Identity.API/Startup.cs b/src/Services/Identity/Identity.API/Startup.cs index ea5e49102..11e946da6 100644 --- a/src/Services/Identity/Identity.API/Startup.cs +++ b/src/Services/Identity/Identity.API/Startup.cs @@ -31,6 +31,8 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API // This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { + services.AddApplicationInsightsTelemetry(Configuration); + // Add framework services. services.AddDbContext(options => options.UseSqlServer(Configuration["ConnectionString"], @@ -114,7 +116,9 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); - + loggerFactory.AddAzureWebAppDiagnostics(); + loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); + if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); diff --git a/src/Services/Identity/Identity.API/appsettings.json b/src/Services/Identity/Identity.API/appsettings.json index 5633c1022..05e06c441 100644 --- a/src/Services/Identity/Identity.API/appsettings.json +++ b/src/Services/Identity/Identity.API/appsettings.json @@ -12,5 +12,8 @@ "System": "Information", "Microsoft": "Information" } + }, + "ApplicationInsights": { + "InstrumentationKey": "" } } diff --git a/src/Services/Location/Locations.API/Locations.API.csproj b/src/Services/Location/Locations.API/Locations.API.csproj index b1b322708..3d94cdd33 100644 --- a/src/Services/Location/Locations.API/Locations.API.csproj +++ b/src/Services/Location/Locations.API/Locations.API.csproj @@ -11,6 +11,7 @@ + diff --git a/src/Services/Location/Locations.API/Program.cs b/src/Services/Location/Locations.API/Program.cs index 7ebc0ab8a..85f3191cc 100644 --- a/src/Services/Location/Locations.API/Program.cs +++ b/src/Services/Location/Locations.API/Program.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using System.IO; @@ -18,11 +19,17 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API .UseHealthChecks("/hc") .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup() + .ConfigureAppConfiguration((builderContext, config) => + { + config.AddEnvironmentVariables(); + }) .ConfigureLogging((hostingContext, builder) => { builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); builder.AddConsole(); builder.AddDebug(); - }).Build(); + }) + .UseApplicationInsights() + .Build(); } } diff --git a/src/Services/Location/Locations.API/Startup.cs b/src/Services/Location/Locations.API/Startup.cs index 442210216..47cf592f7 100644 --- a/src/Services/Location/Locations.API/Startup.cs +++ b/src/Services/Location/Locations.API/Startup.cs @@ -37,6 +37,8 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API public IServiceProvider ConfigureServices(IServiceCollection services) { + services.AddApplicationInsightsTelemetry(Configuration); + services.AddMvc(options => { options.Filters.Add(typeof(HttpGlobalExceptionFilter)); @@ -142,6 +144,9 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { + loggerFactory.AddAzureWebAppDiagnostics(); + loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); + var pathBase = Configuration["PATH_BASE"]; if (!string.IsNullOrEmpty(pathBase)) { diff --git a/src/Services/Location/Locations.API/appsettings.json b/src/Services/Location/Locations.API/appsettings.json index 511bb5c6a..0064466af 100644 --- a/src/Services/Location/Locations.API/appsettings.json +++ b/src/Services/Location/Locations.API/appsettings.json @@ -11,5 +11,8 @@ } }, "AzureServiceBusEnabled": false, - "SubscriptionClientName": "Locations" + "SubscriptionClientName": "Locations", + "ApplicationInsights": { + "InstrumentationKey": "" + } } \ No newline at end of file diff --git a/src/Services/Marketing/Marketing.API/Marketing.API.csproj b/src/Services/Marketing/Marketing.API/Marketing.API.csproj index 2afba2204..9b29871f8 100644 --- a/src/Services/Marketing/Marketing.API/Marketing.API.csproj +++ b/src/Services/Marketing/Marketing.API/Marketing.API.csproj @@ -7,9 +7,12 @@ $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; aspnet-Marketing.API-20161122013619 + /subscriptions/6c22bb55-0221-4ce4-9bf1-3c4a10a7294c/resourcegroups/eshop-log/providers/microsoft.insights/components/eshopappinsights + /subscriptions/6c22bb55-0221-4ce4-9bf1-3c4a10a7294c/resourcegroups/eshop-log/providers/microsoft.insights/components/eshopappinsights + PreserveNewest @@ -18,6 +21,7 @@ + @@ -45,4 +49,8 @@ PreserveNewest + + + + diff --git a/src/Services/Marketing/Marketing.API/Program.cs b/src/Services/Marketing/Marketing.API/Program.cs index 32852073c..70b2362e1 100644 --- a/src/Services/Marketing/Marketing.API/Program.cs +++ b/src/Services/Marketing/Marketing.API/Program.cs @@ -3,6 +3,7 @@ using AspNetCore.Hosting; using Microsoft.AspNetCore; using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure; + using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using System.IO; @@ -25,15 +26,22 @@ public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) + .UseApplicationInsights() .UseHealthChecks("/hc") .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup() .UseWebRoot("Pics") + .ConfigureAppConfiguration((builderContext, config) => + { + config.AddEnvironmentVariables(); + }) .ConfigureLogging((hostingContext, builder) => { builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); builder.AddConsole(); builder.AddDebug(); - }).Build(); + }) + .UseApplicationInsights() + .Build(); } } diff --git a/src/Services/Marketing/Marketing.API/Startup.cs b/src/Services/Marketing/Marketing.API/Startup.cs index 0df0285d8..321bf93c7 100644 --- a/src/Services/Marketing/Marketing.API/Startup.cs +++ b/src/Services/Marketing/Marketing.API/Startup.cs @@ -44,6 +44,8 @@ // This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { + services.AddApplicationInsightsTelemetry(Configuration); + // Add framework services. services.AddMvc(options => { @@ -172,6 +174,9 @@ // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env,ILoggerFactory loggerFactory) { + loggerFactory.AddAzureWebAppDiagnostics(); + loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); + var pathBase = Configuration["PATH_BASE"]; if (!string.IsNullOrEmpty(pathBase)) diff --git a/src/Services/Marketing/Marketing.API/appsettings.json b/src/Services/Marketing/Marketing.API/appsettings.json index 21aae065a..cc55a4052 100644 --- a/src/Services/Marketing/Marketing.API/appsettings.json +++ b/src/Services/Marketing/Marketing.API/appsettings.json @@ -1,4 +1,4 @@ -{ +{ "Logging": { "IncludeScopes": false, "LogLevel": { @@ -12,6 +12,8 @@ "PicBaseUrl": "http://localhost:5110/api/v1/campaigns/[0]/pic/", "AzureServiceBusEnabled": false, "SubscriptionClientName": "Marketing", - "AzureStorageEnabled": false - -} + "AzureStorageEnabled": false, + "ApplicationInsights": { + "InstrumentationKey": "" + } +} \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Ordering.API.csproj b/src/Services/Ordering/Ordering.API/Ordering.API.csproj index 123f9e838..d4ebd294a 100644 --- a/src/Services/Ordering/Ordering.API/Ordering.API.csproj +++ b/src/Services/Ordering/Ordering.API/Ordering.API.csproj @@ -37,6 +37,7 @@ + diff --git a/src/Services/Ordering/Ordering.API/Program.cs b/src/Services/Ordering/Ordering.API/Program.cs index 46221b42c..011f3004f 100644 --- a/src/Services/Ordering/Ordering.API/Program.cs +++ b/src/Services/Ordering/Ordering.API/Program.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF; using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure; using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -30,16 +31,22 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API } public static IWebHost BuildWebHost(string[] args) => - WebHost.CreateDefaultBuilder(args) + WebHost.CreateDefaultBuilder(args) .UseStartup() .UseHealthChecks("/hc") .UseContentRoot(Directory.GetCurrentDirectory()) + .ConfigureAppConfiguration((builderContext, config) => + { + config.AddJsonFile("settings.json"); + config.AddEnvironmentVariables(); + }) .ConfigureLogging((hostingContext, builder) => { builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); builder.AddConsole(); builder.AddDebug(); }) + .UseApplicationInsights() .Build(); } } diff --git a/src/Services/Ordering/Ordering.API/Startup.cs b/src/Services/Ordering/Ordering.API/Startup.cs index 1a32a97c4..a4b5d1e1f 100644 --- a/src/Services/Ordering/Ordering.API/Startup.cs +++ b/src/Services/Ordering/Ordering.API/Startup.cs @@ -46,6 +46,8 @@ public IServiceProvider ConfigureServices(IServiceCollection services) { + services.AddApplicationInsightsTelemetry(Configuration); + // Add framework services. services.AddMvc(options => { @@ -196,6 +198,8 @@ { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); + loggerFactory.AddAzureWebAppDiagnostics(); + loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); var pathBase = Configuration["PATH_BASE"]; if (!string.IsNullOrEmpty(pathBase)) @@ -203,7 +207,7 @@ loggerFactory.CreateLogger("init").LogDebug($"Using PATH BASE '{pathBase}'"); app.UsePathBase(pathBase); } - + app.UseCors("CorsPolicy"); ConfigureAuth(app); diff --git a/src/Services/Ordering/Ordering.API/settings.json b/src/Services/Ordering/Ordering.API/settings.json index d2068fcab..f20261e31 100644 --- a/src/Services/Ordering/Ordering.API/settings.json +++ b/src/Services/Ordering/Ordering.API/settings.json @@ -13,5 +13,8 @@ "AzureServiceBusEnabled": false, "SubscriptionClientName": "Ordering", "GracePeriodTime": "1", - "CheckUpdateTime": "30000" + "CheckUpdateTime": "30000", + "ApplicationInsights": { + "InstrumentationKey": "" + } } diff --git a/src/Services/Payment/Payment.API/Payment.API.csproj b/src/Services/Payment/Payment.API/Payment.API.csproj index ab28a210d..736d13d7a 100644 --- a/src/Services/Payment/Payment.API/Payment.API.csproj +++ b/src/Services/Payment/Payment.API/Payment.API.csproj @@ -8,6 +8,7 @@ + diff --git a/src/Services/Payment/Payment.API/Program.cs b/src/Services/Payment/Payment.API/Program.cs index a373e2695..aff7bf359 100644 --- a/src/Services/Payment/Payment.API/Program.cs +++ b/src/Services/Payment/Payment.API/Program.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using System.IO; @@ -18,11 +19,17 @@ namespace Payment.API .UseHealthChecks("/hc") .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup() + .ConfigureAppConfiguration((builderContext, config) => + { + config.AddEnvironmentVariables(); + }) .ConfigureLogging((hostingContext, builder) => { builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); builder.AddConsole(); builder.AddDebug(); - }).Build(); + }) + .UseApplicationInsights() + .Build(); } } diff --git a/src/Services/Payment/Payment.API/appsettings.json b/src/Services/Payment/Payment.API/appsettings.json index 9aef99a14..ad668a388 100644 --- a/src/Services/Payment/Payment.API/appsettings.json +++ b/src/Services/Payment/Payment.API/appsettings.json @@ -7,5 +7,8 @@ }, "PaymentSucceded": true, "AzureServiceBusEnabled": false, - "SubscriptionClientName": "Payment" + "SubscriptionClientName": "Payment", + "ApplicationInsights": { + "InstrumentationKey": "" + } } diff --git a/src/Web/WebMVC/Program.cs b/src/Web/WebMVC/Program.cs index ec711b2ae..07332a02a 100644 --- a/src/Web/WebMVC/Program.cs +++ b/src/Web/WebMVC/Program.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using System.IO; @@ -17,11 +18,17 @@ namespace Microsoft.eShopOnContainers.WebMVC .UseContentRoot(Directory.GetCurrentDirectory()) .UseHealthChecks("/hc") .UseStartup() + .ConfigureAppConfiguration((builderContext, config) => + { + config.AddEnvironmentVariables(); + }) .ConfigureLogging((hostingContext, builder) => { builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); builder.AddConsole(); builder.AddDebug(); - }).Build(); + }) + .UseApplicationInsights() + .Build(); } } diff --git a/src/Web/WebMVC/Startup.cs b/src/Web/WebMVC/Startup.cs index a5b690296..6208b4c06 100644 --- a/src/Web/WebMVC/Startup.cs +++ b/src/Web/WebMVC/Startup.cs @@ -31,6 +31,8 @@ namespace Microsoft.eShopOnContainers.WebMVC // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + services.AddApplicationInsightsTelemetry(Configuration); + services.AddMvc(); services.AddSession(); @@ -115,6 +117,8 @@ namespace Microsoft.eShopOnContainers.WebMVC loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); + loggerFactory.AddAzureWebAppDiagnostics(); + loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); if (env.IsDevelopment()) { diff --git a/src/Web/WebMVC/WebMVC.csproj b/src/Web/WebMVC/WebMVC.csproj index e8cdbc528..5b086a904 100644 --- a/src/Web/WebMVC/WebMVC.csproj +++ b/src/Web/WebMVC/WebMVC.csproj @@ -36,6 +36,7 @@ --> + diff --git a/src/Web/WebMVC/appsettings.json b/src/Web/WebMVC/appsettings.json index a9a73120f..b68e719dd 100644 --- a/src/Web/WebMVC/appsettings.json +++ b/src/Web/WebMVC/appsettings.json @@ -18,5 +18,8 @@ "System": "Information", "Microsoft": "Information" } + }, + "ApplicationInsights": { + "InstrumentationKey": "" } } \ No newline at end of file diff --git a/src/Web/WebSPA/Program.cs b/src/Web/WebSPA/Program.cs index 92a6af2da..c1a7da269 100644 --- a/src/Web/WebSPA/Program.cs +++ b/src/Web/WebSPA/Program.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Hosting; using System.IO; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Configuration; namespace eShopConContainers.WebSPA { @@ -17,12 +18,17 @@ namespace eShopConContainers.WebSPA .UseStartup() .UseHealthChecks("/hc") .UseContentRoot(Directory.GetCurrentDirectory()) + .ConfigureAppConfiguration((builderContext, config) => + { + config.AddEnvironmentVariables(); + }) .ConfigureLogging((hostingContext, builder) => { builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); builder.AddConsole(); builder.AddDebug(); }) + .UseApplicationInsights() .Build(); } } diff --git a/src/Web/WebSPA/Startup.cs b/src/Web/WebSPA/Startup.cs index 0e9585c8c..0960d68e1 100644 --- a/src/Web/WebSPA/Startup.cs +++ b/src/Web/WebSPA/Startup.cs @@ -36,6 +36,8 @@ namespace eShopConContainers.WebSPA // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { + services.AddApplicationInsightsTelemetry(Configuration); + services.AddHealthChecks(checks => { var minutes = 1; @@ -76,6 +78,10 @@ namespace eShopConContainers.WebSPA // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IAntiforgery antiforgery) { + + loggerFactory.AddAzureWebAppDiagnostics(); + loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); + if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); diff --git a/src/Web/WebSPA/WebSPA.csproj b/src/Web/WebSPA/WebSPA.csproj index 1efcb89e6..40ab683fe 100644 --- a/src/Web/WebSPA/WebSPA.csproj +++ b/src/Web/WebSPA/WebSPA.csproj @@ -27,6 +27,7 @@ + diff --git a/src/Web/WebSPA/appsettings.json b/src/Web/WebSPA/appsettings.json index 7f8a004f8..7b1930f84 100644 --- a/src/Web/WebSPA/appsettings.json +++ b/src/Web/WebSPA/appsettings.json @@ -15,5 +15,8 @@ "System": "Information", "Microsoft": "Information" } + }, + "ApplicationInsights": { + "InstrumentationKey": "" } } \ No newline at end of file diff --git a/src/Web/WebStatus/Program.cs b/src/Web/WebStatus/Program.cs index 6a895f9e7..adab0e6b3 100644 --- a/src/Web/WebStatus/Program.cs +++ b/src/Web/WebStatus/Program.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using System.IO; @@ -16,11 +17,17 @@ namespace WebStatus WebHost.CreateDefaultBuilder(args) .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup() + .ConfigureAppConfiguration((builderContext, config) => + { + config.AddEnvironmentVariables(); + }) .ConfigureLogging((hostingContext, builder) => { builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); builder.AddConsole(); builder.AddDebug(); - }).Build(); + }) + .UseApplicationInsights() + .Build(); } } diff --git a/src/Web/WebStatus/Startup.cs b/src/Web/WebStatus/Startup.cs index acbe9edcb..0b7271238 100644 --- a/src/Web/WebStatus/Startup.cs +++ b/src/Web/WebStatus/Startup.cs @@ -23,6 +23,8 @@ namespace WebStatus // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + services.AddApplicationInsightsTelemetry(Configuration); + services.AddOptions(); // Add framework services. @@ -49,8 +51,11 @@ namespace WebStatus } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { + loggerFactory.AddAzureWebAppDiagnostics(); + loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); + if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); diff --git a/src/Web/WebStatus/WebStatus.csproj b/src/Web/WebStatus/WebStatus.csproj index 7939b146a..603db6850 100644 --- a/src/Web/WebStatus/WebStatus.csproj +++ b/src/Web/WebStatus/WebStatus.csproj @@ -5,6 +5,7 @@ ..\..\..\docker-compose.dcproj + diff --git a/src/Web/WebStatus/appsettings.json b/src/Web/WebStatus/appsettings.json index e8d5a9f60..bf413fcbf 100644 --- a/src/Web/WebStatus/appsettings.json +++ b/src/Web/WebStatus/appsettings.json @@ -13,5 +13,8 @@ "IdentityUrl": "http://localhost:5105/hc", "MarketingUrl": "http://localhost:5110/hc", "LocationsUrl": "http://localhost:5109/hc", - "PaymentUrl": "http://localhost:5108/hc" + "PaymentUrl": "http://localhost:5108/hc", + "ApplicationInsights": { + "InstrumentationKey": "" + } }