Skip to content

Commit

Permalink
Added Appinsights Linux SF telemetry initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
ramon-tomas-c committed Oct 13, 2017
1 parent ace6112 commit dc98e6a
Show file tree
Hide file tree
Showing 40 changed files with 267 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<Parameter Name="BasketApi_InstanceCount" DefaultValue="-1" />
<Parameter Name="IdentityUrlExternal" DefaultValue="" />
<Parameter Name="PicBaseUrl" DefaultValue="" />
<Parameter Name="InstrumentationKey" DefaultValue="" />
</Parameters>
<!-- Import the ServiceManifest from the ServicePackage. The ServiceManifestName and ServiceManifestVersion
should match the Name and Version attributes of the ServiceManifest element defined in the
Expand All @@ -23,6 +24,7 @@
<!-- Override external urls depending on environment -->
<EnvironmentOverrides CodePackageRef="Code">
<EnvironmentVariable Name="IdentityUrlExternal" Value="[IdentityUrlExternal]"/>
<EnvironmentVariable Name="ApplicationInsights__InstrumentationKey" Value="[InstrumentationKey]"/>
</EnvironmentOverrides>
<Policies>
<ContainerHostPolicies CodePackageRef="Code">
Expand All @@ -34,6 +36,7 @@
<ServiceManifestRef ServiceManifestName="LocationsApiPkg" ServiceManifestVersion="1.0.0" />
<EnvironmentOverrides CodePackageRef="Code">
<EnvironmentVariable Name="IdentityUrlExternal" Value="[IdentityUrlExternal]"/>
<EnvironmentVariable Name="ApplicationInsights__InstrumentationKey" Value="[InstrumentationKey]"/>
</EnvironmentOverrides>
<Policies>
<ContainerHostPolicies CodePackageRef="Code">
Expand All @@ -43,7 +46,9 @@
</ServiceManifestImport>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="PaymentApiPkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
<EnvironmentOverrides CodePackageRef="Code">
<EnvironmentVariable Name="ApplicationInsights__InstrumentationKey" Value="[InstrumentationKey]"/>
</EnvironmentOverrides>
<Policies>
<ContainerHostPolicies CodePackageRef="Code">
<PortBinding ContainerPort="80" EndpointRef="PaymentApiTypeEndpoint"/>
Expand All @@ -54,6 +59,7 @@
<ServiceManifestRef ServiceManifestName="OrderingApiPkg" ServiceManifestVersion="1.0.0" />
<EnvironmentOverrides CodePackageRef="Code">
<EnvironmentVariable Name="IdentityUrlExternal" Value="[IdentityUrlExternal]"/>
<EnvironmentVariable Name="ApplicationInsights__InstrumentationKey" Value="[InstrumentationKey]"/>
</EnvironmentOverrides>
<Policies>
<ContainerHostPolicies CodePackageRef="Code">
Expand All @@ -65,6 +71,7 @@
<ServiceManifestRef ServiceManifestName="CatalogApiPkg" ServiceManifestVersion="1.0.0" />
<EnvironmentOverrides CodePackageRef="Code">
<EnvironmentVariable Name="PicBaseUrl" Value="[PicBaseUrl]"/>
<EnvironmentVariable Name="ApplicationInsights__InstrumentationKey" Value="[InstrumentationKey]"/>
</EnvironmentOverrides>
<Policies>
<ContainerHostPolicies CodePackageRef="Code">
Expand All @@ -76,6 +83,7 @@
<ServiceManifestRef ServiceManifestName="BasketApiPkg" ServiceManifestVersion="1.0.0" />
<EnvironmentOverrides CodePackageRef="Code">
<EnvironmentVariable Name="IdentityUrlExternal" Value="[IdentityUrlExternal]"/>
<EnvironmentVariable Name="ApplicationInsights__InstrumentationKey" Value="[InstrumentationKey]"/>
</EnvironmentOverrides>
<Policies>
<ContainerHostPolicies CodePackageRef="Code">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<EnvironmentVariable Name="IdentityUrlExternal" Value="http://#{your_sf_dns}#:5105"/>
<EnvironmentVariable Name="EventBusConnection" Value="rabbitmq.eshoponservicefabricbus"/>
<EnvironmentVariable Name="AzureServiceBusEnabled" Value="False"/>
<EnvironmentVariable Name="ApplicationInsights__InstrumentationKey" Value=""/>
<EnvironmentVariable Name="OrchestratorType" Value="SF"/>
</EnvironmentVariables>
</CodePackage>

Expand All @@ -43,3 +45,4 @@
</Endpoints>
</Resources>
</ServiceManifest>

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<EnvironmentVariable Name="AzureStorageEnabled" Value="False"/>
<EnvironmentVariable Name="EventBusConnection" Value="rabbitmq.eshoponservicefabricbus"/>
<EnvironmentVariable Name="AzureServiceBusEnabled" Value="False"/>
<EnvironmentVariable Name="ApplicationInsights__InstrumentationKey" Value=""/>
<EnvironmentVariable Name="OrchestratorType" Value="SF"/>
</EnvironmentVariables>
</CodePackage>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
<EnvironmentVariable Name="identityUrl" Value="http://identityapi.eshoponservicefabric:5105"/>
<EnvironmentVariable Name="IdentityUrlExternal" Value=""/>
<EnvironmentVariable Name="EventBusConnection" Value="rabbitmq.eshoponservicefabricbus"/>
<EnvironmentVariable Name="AzureServiceBusEnabled" Value="False"/>
<EnvironmentVariable Name="AzureServiceBusEnabled" Value="False"/>
<EnvironmentVariable Name="ApplicationInsights__InstrumentationKey" Value=""/>
<EnvironmentVariable Name="OrchestratorType" Value="SF"/>
</EnvironmentVariables>
</CodePackage>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
<EnvironmentVariable Name="MongoConnectionString" Value="mongodb://mongodb.eshoponservicefabricnosql"/>
<EnvironmentVariable Name="MongoDatabase" Value="MarketingDb"/>
<EnvironmentVariable Name="identityUrl" Value="http://identityapi.eshoponservicefabric:5105"/>
<EnvironmentVariable Name="ApplicationInsights__InstrumentationKey" Value=""/>
<EnvironmentVariable Name="OrchestratorType" Value="SF"/>
</EnvironmentVariables>
</CodePackage>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<EnvironmentVariable Name="UseCustomizationData" Value="True"/>
<EnvironmentVariable Name="GracePeriodTime" Value="1"/>
<EnvironmentVariable Name="CheckUpdateTime" Value="30000"/>
<EnvironmentVariable Name="ApplicationInsights__InstrumentationKey" Value=""/>
<EnvironmentVariable Name="OrchestratorType" Value="SF"/>
</EnvironmentVariables>
</CodePackage>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
<EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value="Development"/>
<EnvironmentVariable Name="ASPNETCORE_URLS" Value="http://0.0.0.0:80"/>
<EnvironmentVariable Name="EventBusConnection" Value="rabbitmq.eshoponservicefabricbus"/>
<EnvironmentVariable Name="AzureServiceBusEnabled" Value="False"/>
<EnvironmentVariable Name="AzureServiceBusEnabled" Value="False"/>
<EnvironmentVariable Name="ApplicationInsights__InstrumentationKey" Value=""/>
<EnvironmentVariable Name="OrchestratorType" Value="SF"/>
</EnvironmentVariables>
</CodePackage>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
<Parameter Name="BasketApi_InstanceCount" Value="-1" />
<Parameter Name="IdentityUrlExternal" Value="http://#{your_sf_dns}#:5105" />
<Parameter Name="PicBaseUrl" Value="http://#{your_sf_dns}#:5101/api/v1/catalog/items/[0]/pic/" />
<Parameter Name="InstrumentationKey" Value="" />
</Parameters>
</Application>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<Parameter Name="MarketingApiClient" DefaultValue="" />
<Parameter Name="BasketApiClient" DefaultValue="" />
<Parameter Name="OrderingApiClient" DefaultValue="" />
<Parameter Name="InstrumentationKey" DefaultValue="" />
</Parameters>
<!-- Import the ServiceManifest from the ServicePackage. The ServiceManifestName and ServiceManifestVersion
should match the Name and Version attributes of the ServiceManifest element defined in the
Expand All @@ -28,6 +29,7 @@
<EnvironmentVariable Name="MarketingApiClient" Value="[MarketingApiClient]"/>
<EnvironmentVariable Name="BasketApiClient" Value="[BasketApiClient]"/>
<EnvironmentVariable Name="OrderingApiClient" Value="[OrderingApiClient]"/>
<EnvironmentVariable Name="ApplicationInsights__InstrumentationKey" Value="[InstrumentationKey]"/>
</EnvironmentOverrides>
<Policies>
<ContainerHostPolicies CodePackageRef="Code">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<EnvironmentVariable Name="BasketApiClient" Value=""/>
<EnvironmentVariable Name="OrderingApiClient" Value=""/>
<EnvironmentVariable Name="UseCustomizationData" Value="True"/>
<EnvironmentVariable Name="ApplicationInsights__InstrumentationKey" Value=""/>
<EnvironmentVariable Name="OrchestratorType" Value="SF"/>
</EnvironmentVariables>

</CodePackage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
<Parameter Name="MarketingApiClient" Value="http://#{your_sf_dns}#:5110" />
<Parameter Name="BasketApiClient" Value="http://#{your_sf_dns}#:5103" />
<Parameter Name="OrderingApiClient" Value="http://#{your_sf_dns}#:5102" />
<Parameter Name="InstrumentationKey" Value="" />
</Parameters>
</Application>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<Parameters>
<Parameter Name="WebMVC_InstanceCount" DefaultValue="-1" />
<Parameter Name="IdentityUrl" DefaultValue="" />
<Parameter Name="InstrumentationKey" DefaultValue="" />
</Parameters>
<!-- Import the ServiceManifest from the ServicePackage. The ServiceManifestName and ServiceManifestVersion
should match the Name and Version attributes of the ServiceManifest element defined in the
Expand All @@ -15,7 +16,8 @@
<ServiceManifestRef ServiceManifestName="WebMVCPkg" ServiceManifestVersion="1.0.0" />
<!-- Override external urls depending on environment -->
<EnvironmentOverrides CodePackageRef="Code">
<EnvironmentVariable Name="IdentityUrl" Value="[IdentityUrl]"/>
<EnvironmentVariable Name="IdentityUrl" Value="[IdentityUrl]"/>
<EnvironmentVariable Name="ApplicationInsights__InstrumentationKey" Value="[InstrumentationKey]"/>
</EnvironmentOverrides>
<Policies>
<ContainerHostPolicies CodePackageRef="Code">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
<EnvironmentVariable Name="IdentityUrl" Value=""/>
<EnvironmentVariable Name="MarketingUrl" Value="http://marketingapi.eshoponservicefabric:5110"/>
<EnvironmentVariable Name="LocationsUrl" Value="http://locationsapi.eshoponservicefabric:5109"/>
<EnvironmentVariable Name="ApplicationInsights__InstrumentationKey" Value=""/>
<EnvironmentVariable Name="OrchestratorType" Value="SF"/>
</EnvironmentVariables>
</CodePackage>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<Parameters>
<Parameter Name="WebMVC_InstanceCount" Value="-1" />
<Parameter Name="IdentityUrl" Value="http://#{your_sf_dns}#:5105" />
<Parameter Name="InstrumentationKey" Value="" />
</Parameters>
</Application>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<Parameter Name="BasketUrl" DefaultValue="" />
<Parameter Name="MarketingUrl" DefaultValue="" />
<Parameter Name="IdentityUrl" DefaultValue="" />
<Parameter Name="InstrumentationKey" DefaultValue="" />
</Parameters>
<!-- Import the ServiceManifest from the ServicePackage. The ServiceManifestName and ServiceManifestVersion
should match the Name and Version attributes of the ServiceManifest element defined in the
Expand All @@ -24,6 +25,7 @@
<EnvironmentVariable Name="BasketUrl" Value="[BasketUrl]"/>
<EnvironmentVariable Name="MarketingUrl" Value="[MarketingUrl]"/>
<EnvironmentVariable Name="IdentityUrl" Value="[IdentityUrl]"/>
<EnvironmentVariable Name="ApplicationInsights__InstrumentationKey" Value="[InstrumentationKey]"/>
</EnvironmentOverrides>
<Policies>
<ContainerHostPolicies CodePackageRef="Code">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
<EnvironmentVariable Name="BasketUrlHC" Value="http://basketapi.eshoponservicefabric:5103/hc"/>
<EnvironmentVariable Name="MarketingUrlHC" Value="http://marketingapi.eshoponservicefabric:5110/hc"/>
<EnvironmentVariable Name="UseCustomizationData" Value="True"/>
<EnvironmentVariable Name="ApplicationInsights__InstrumentationKey" Value=""/>
<EnvironmentVariable Name="OrchestratorType" Value="SF"/>
</EnvironmentVariables>
</CodePackage>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<Parameter Name="BasketUrl" Value="http://#{your_sf_dns}#:5103" />
<Parameter Name="MarketingUrl" Value="http://#{your_sf_dns}#:5110" />
<Parameter Name="IdentityUrl" Value="http://#{your_sf_dns}#:5105" />
<Parameter Name="InstrumentationKey" Value="" />
</Parameters>
</Application>
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Parameters>
<Parameter Name="WebStatus_InstanceCount" DefaultValue="-1" />
<Parameter Name="InstrumentationKey" DefaultValue="" />
</Parameters>
<!-- Import the ServiceManifest from the ServicePackage. The ServiceManifestName and ServiceManifestVersion
should match the Name and Version attributes of the ServiceManifest element defined in the
ServiceManifest.xml file. -->
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="WebStatusPkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
<EnvironmentOverrides CodePackageRef="Code">
<EnvironmentVariable Name="ApplicationInsights__InstrumentationKey" Value="[InstrumentationKey]"/>
</EnvironmentOverrides>
<Policies>
<ContainerHostPolicies CodePackageRef="Code">
<PortBinding ContainerPort="80" EndpointRef="WebStatusTypeEndpoint"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<EnvironmentVariable Name="LocationsUrl" Value="http://locationsapi.eshoponservicefabric:5109"/>
<EnvironmentVariable Name="mvc" Value="http://webmvc.eshoponservicefabric:5100"/>
<EnvironmentVariable Name="spa" Value="http://webspa.eshoponservicefabric:5104"/>
<EnvironmentVariable Name="ApplicationInsights__InstrumentationKey" Value=""/>
<EnvironmentVariable Name="OrchestratorType" Value="SF"/>
</EnvironmentVariables>
</CodePackage>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<Application Name="fabric:/eShopOnServiceFabricWebStatus" xmlns="http://schemas.microsoft.com/2011/01/fabric" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Parameters>
<Parameter Name="WebStatus_InstanceCount" Value="-1" />
<Parameter Name="InstrumentationKey" Value="" />
</Parameters>
</Application>
1 change: 1 addition & 0 deletions src/Services/Basket/Basket.API/Basket.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.4.1" />
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.0.0-beta1" />
<PackageReference Include="Microsoft.ApplicationInsights.ServiceFabric" Version="2.0.0-beta1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
Expand Down
39 changes: 26 additions & 13 deletions src/Services/Basket/Basket.API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Basket.API.Infrastructure.Filters;
using Basket.API.IntegrationEvents.EventHandling;
using Basket.API.IntegrationEvents.Events;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.ServiceFabric;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
Expand Down Expand Up @@ -44,7 +46,7 @@ public Startup(IConfiguration configuration)
// This method gets called by the runtime. Use this method to add services to the container.
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry(Configuration);
RegisterAppInsights(services);

// Add framework services.
services.AddMvc(options =>
Expand All @@ -63,13 +65,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
);
});

services.Configure<BasketSettings>(Configuration);

if(Configuration.GetValue<string>("OrchestratorType").Equals("K8S"))
{
// Enable K8s telemetry initializer
services.EnableKubernetes();
}
services.Configure<BasketSettings>(Configuration);

//By connecting here we are making sure that our service
//cannot start until redis is ready. This might slow down startup,
Expand All @@ -80,7 +76,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
services.AddSingleton<ConnectionMultiplexer>(sp =>
{
var settings = sp.GetRequiredService<IOptions<BasketSettings>>().Value;
var configuration = ConfigurationOptions.Parse(settings.ConnectionString, true);
var configuration = ConfigurationOptions.Parse(settings.ConnectionString, true);

configuration.ResolveDns = true;

Expand Down Expand Up @@ -111,7 +107,8 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
HostName = Configuration["EventBusConnection"]
};

if (!string.IsNullOrEmpty(Configuration["EventBusUserName"])) {
if (!string.IsNullOrEmpty(Configuration["EventBusUserName"]))
{
factory.UserName = Configuration["EventBusUserName"];
}

Expand Down Expand Up @@ -169,16 +166,15 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddTransient<IBasketRepository, RedisBasketRepository>();
services.AddTransient<IIdentityService, IdentityService>();

services.AddOptions();

var container = new ContainerBuilder();
container.Populate(services);

return new AutofacServiceProvider(container.Build());
}




// 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)
Expand Down Expand Up @@ -210,6 +206,23 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF

}

private void RegisterAppInsights(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry(Configuration);

if (Configuration.GetValue<string>("OrchestratorType").Equals("K8S"))
{
// Enable K8s telemetry initializer
services.EnableKubernetes();
}
if (Configuration.GetValue<string>("OrchestratorType").Equals("SF"))
{
// Enable SF telemetry initializer
services.AddSingleton<ITelemetryInitializer>((serviceProvider) =>
new FabricTelemetryInitializer());
}
}

private void ConfigureAuthService(IServiceCollection services)
{
// prevent from mapping "sub" claim to nameidentifier.
Expand Down
1 change: 1 addition & 0 deletions src/Services/Catalog/Catalog.API/Catalog.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.4.1" />
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.0.0-beta1" />
<PackageReference Include="Microsoft.ApplicationInsights.ServiceFabric" Version="2.0.0-beta1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
Expand Down
Loading

0 comments on commit dc98e6a

Please sign in to comment.