Skip to content

Commit a04cef9

Browse files
committed
Added AppInsights service
1 parent 373bdd9 commit a04cef9

41 files changed

Lines changed: 188 additions & 24 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP=10.121.122.92
2323
#ESHOP_AZURE_STORAGE_MARKETING_KEY=<YourAzureStorageMarketingKey>
2424
#ESHOP_SERVICE_BUS_USERNAME=<ServiceBusUserName-OnlyUsedIfUsingRabbitMQUnderwindows>
2525
#ESHOP_SERVICE_BUS_PASSWORD=<ServiceBusUserPassword-OnlyUsedIfUsingRabbitMQUnderwindows>
26+
#INSTRUMENTATION_KEY=

docker-compose.override.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ services:
1919
- EventBusUserName=${ESHOP_SERVICE_BUS_USERNAME}
2020
- EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD}
2121
- AzureServiceBusEnabled=False
22+
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
2223
ports:
2324
- "5103:80"
2425

@@ -36,6 +37,7 @@ services:
3637
- UseCustomizationData=True
3738
- AzureServiceBusEnabled=False
3839
- AzureStorageEnabled=False
40+
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
3941
ports:
4042
- "5101:80"
4143

@@ -51,7 +53,8 @@ services:
5153
- MarketingApiClient=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5110
5254
- BasketApiClient=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5103
5355
- OrderingApiClient=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5102
54-
- UseCustomizationData=True
56+
- UseCustomizationData=True
57+
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
5558
ports:
5659
- "5105:80"
5760

@@ -69,6 +72,7 @@ services:
6972
- AzureServiceBusEnabled=False
7073
- CheckUpdateTime=30000
7174
- GracePeriodTime=1
75+
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
7276
ports:
7377
- "5102:80"
7478

@@ -90,6 +94,7 @@ services:
9094
- AzureStorageAccountKey=${ESHOP_AZURE_STORAGE_MARKETING_KEY}
9195
- AzureServiceBusEnabled=False
9296
- AzureStorageEnabled=False
97+
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
9398
ports:
9499
- "5110:80"
95100

@@ -110,6 +115,7 @@ services:
110115
- MarketingUrlHC=http://marketing.api/hc
111116
- PaymentUrlHC=http://payment.api/hc
112117
- UseCustomizationData=True
118+
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
113119
ports:
114120
- "5104:80"
115121

@@ -130,6 +136,7 @@ services:
130136
- MarketingUrlHC=http://marketing.api/hc
131137
- PaymentUrlHC=http://payment.api/hc
132138
- UseCustomizationData=True
139+
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
133140
ports:
134141
- "5100:80"
135142

@@ -146,6 +153,7 @@ services:
146153
- PaymentUrl=http://payment.api/hc
147154
- mvc=http://webmvc/hc
148155
- spa=http://webspa/hc
156+
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
149157
ports:
150158
- "5107:80"
151159

@@ -157,6 +165,7 @@ services:
157165
- EventBusUserName=${ESHOP_SERVICE_BUS_USERNAME}
158166
- EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD}
159167
- AzureServiceBusEnabled=False
168+
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
160169
ports:
161170
- "5108:80"
162171

@@ -172,6 +181,7 @@ services:
172181
- EventBusUserName=${ESHOP_SERVICE_BUS_USERNAME}
173182
- EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD}
174183
- AzureServiceBusEnabled=False
184+
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
175185
ports:
176186
- "5109:80"
177187

src/Services/Basket/Basket.API/Basket.API.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
</ItemGroup>
1717

1818
<ItemGroup>
19+
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
1920
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
2021
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
2122
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />

src/Services/Basket/Basket.API/Program.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.AspNetCore;
33
using Microsoft.AspNetCore.Builder;
44
using Microsoft.AspNetCore.Hosting;
5+
using Microsoft.Extensions.Configuration;
56
using Microsoft.Extensions.Logging;
67
using System.IO;
78

@@ -23,6 +24,10 @@ public static IWebHost BuildWebHost(string[] args) =>
2324
.UseHealthChecks("/hc")
2425
.UseContentRoot(Directory.GetCurrentDirectory())
2526
.UseStartup<Startup>()
27+
.ConfigureAppConfiguration((builderContext, config) =>
28+
{
29+
config.AddEnvironmentVariables();
30+
})
2631
.ConfigureLogging((hostingContext, builder) =>
2732
{
2833
builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));

src/Services/Basket/Basket.API/Startup.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public Startup(IConfiguration configuration)
4343

4444
// This method gets called by the runtime. Use this method to add services to the container.
4545
public IServiceProvider ConfigureServices(IServiceCollection services)
46-
{
46+
{
47+
services.AddApplicationInsightsTelemetry(Configuration);
48+
4749
// Add framework services.
4850
services.AddMvc(options =>
4951
{
@@ -167,14 +169,17 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
167169

168170

169171
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
170-
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
172+
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
171173
{
174+
loggerFactory.AddAzureWebAppDiagnostics();
175+
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
172176

173177
var pathBase = Configuration["PATH_BASE"];
174178
if (!string.IsNullOrEmpty(pathBase))
175179
{
176180
app.UsePathBase(pathBase);
177-
}
181+
}
182+
178183
app.UseStaticFiles();
179184
app.UseCors("CorsPolicy");
180185

src/Services/Basket/Basket.API/appsettings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
"IdentityUrl": "http://localhost:5105",
1111
"ConnectionString": "127.0.0.1",
1212
"AzureServiceBusEnabled": false,
13-
"SubscriptionClientName": "Basket"
13+
"SubscriptionClientName": "Basket",
14+
"ApplicationInsights": {
15+
"InstrumentationKey": ""
16+
}
1417
}

src/Services/Catalog/Catalog.API/Catalog.API.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
<ItemGroup>
3737
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
38+
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
3839
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
3940
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
4041
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />

src/Services/Catalog/Catalog.API/Program.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.AspNetCore.Hosting;
33
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF;
44
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
5+
using Microsoft.Extensions.Configuration;
56
using Microsoft.Extensions.DependencyInjection;
67
using Microsoft.Extensions.Logging;
78
using Microsoft.Extensions.Options;
@@ -32,14 +33,19 @@ public static IWebHost BuildWebHost(string[] args) =>
3233
WebHost.CreateDefaultBuilder(args)
3334
.UseStartup<Startup>()
3435
.UseHealthChecks("/hc")
35-
.UseContentRoot(Directory.GetCurrentDirectory())
36+
.UseContentRoot(Directory.GetCurrentDirectory())
3637
.UseWebRoot("Pics")
38+
.ConfigureAppConfiguration((builderContext, config) =>
39+
{
40+
config.AddEnvironmentVariables();
41+
})
3742
.ConfigureLogging((hostingContext, builder) =>
3843
{
3944
builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
4045
builder.AddConsole();
4146
builder.AddDebug();
4247
})
48+
.UseApplicationInsights()
4349
.Build();
4450
}
4551
}

src/Services/Catalog/Catalog.API/Startup.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
4141
{
4242
// Add framework services.
4343

44+
services.AddApplicationInsightsTelemetry(Configuration);
45+
4446
services.AddHealthChecks(checks =>
4547
{
4648
var minutes = 1;
@@ -160,6 +162,8 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
160162

161163
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
162164
loggerFactory.AddDebug();
165+
loggerFactory.AddAzureWebAppDiagnostics();
166+
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
163167

164168
var pathBase = Configuration["PATH_BASE"];
165169
if (!string.IsNullOrEmpty(pathBase))

src/Services/Catalog/Catalog.API/appsettings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212
},
1313
"AzureServiceBusEnabled": false,
1414
"AzureStorageEnabled": false,
15-
"SubscriptionClientName": "Catalog"
15+
"SubscriptionClientName": "Catalog",
16+
"ApplicationInsights": {
17+
"InstrumentationKey": ""
18+
}
1619
}

0 commit comments

Comments
 (0)