Our goal in this exercise is to introduce Distributed Tracing
Upon completion of this lab we will have built up a hierarchy of our application dependencies and be able to view how requests flow through the application.
In this exercise we'll add our OpenCensus integration to our bootcamp-store frontend application. We start by deploying a Zipkin server to our foundation that will serve as a landing spot for our distributed traces. Note, this landing spot can be one of a number of different tools, both on and off platform. We then continue on to configure our applications to output their traces to the deployed Zipkin server.
- Navigate to the zipkin folder at the root of this repository.
- Edit the manifest.yml file and exchange the initial placeholder for your initials.
- You are now ready to deploy your Zipkin server, with the
cf push
command. Note: We're showing a little bit of Java love in this .NET workshop :-)
-
Return back to your
bootcamp-store
project root and find the project file. We will add the following nuget package:dotnet add package Steeltoe.Management.TracingCore --version 2.4.4 dotnet add package Steeltoe.Management.ExporterCore --version 2.4.4
-
Navigate to the Startup class and make the following edits:
-
Set the following using statements:
using Steeltoe.Management.Exporter.Tracing; using Steeltoe.Management.Tracing;
-
In the ConfigureServices method add the following lines to add the Distributed Tracing and the Zipkin Exporter to the Service Container.
services.AddDistributedTracing(Configuration); services.AddZipkinExporter(Configuration);
-
In the Configure method add the following line to add the Tracing and Exporter to the middleware pipeline.
app.UseTracingExporter();
-
-
In the root directory navigate to the appsettings.json file and add an entry for tracing like the below snippet. Ensure this entry is inside the management object. These settings tell the exporter where to forward are tracing data. Also take note of the route of the zipkin endpoint and substitute your Zipkin application name Cloud Foundry domain respectively.
"management": { "endpoints": { "actuator":{ "exposure": { "include": [ "*" ] } } }, "tracing": { "alwaysSample": true, "egressIgnorePattern": "/api/v2/spans|/v2/apps/.*/permissions|/eureka/.*|/oauth/.*", "useShortTraceIds ": true, "exporter": { "zipkin": { "endpoint": "http://zipkin-{initials}.apps.{cloud-foundry-domain}/api/v2/spans", "validateCertificates": false, "useShortTraceIds ": true } } } }
-
Run the cf push command to build, stage and run your application on PCF. Ensure you are in the same directory as your manifest file and type
cf push
. -
Once the command has completed, navigate to the url to once again see the home page with products listed. From there go to the Zipkin server and observe traces as you navigate and exercise your web store application.
-
Return back to your
bootcamp-webapi
project root and find the project file. We will add the following nuget package:dotnet add package Steeltoe.Management.TracingCore --version 2.4.4 dotnet add package Steeltoe.Management.ExporterCore --version 2.4.4
-
Navigate to the Startup class and make the following edits:
-
Set the following using statements:
using Steeltoe.Management.Exporter.Tracing; using Steeltoe.Management.Tracing;
-
In the ConfigureServices method add the following lines to add the Distributed Tracing and the Zipkin Exporter to the Service Container.
services.AddDistributedTracing(Configuration); services.AddZipkinExporter(Configuration);
-
In the Configure method add the following line to add the Tracing and Exporter to the middleware pipeline.
app.UseTracingExporter();
-
-
In the root directory navigate to the appsettings.json file and add an entry for tracing like the below snippet. Ensure this entry is inside the management object. These settings tell the exporter where to forward are tracing data. Also take note of the route of the zipkin endpoint and substitute your Zipkin application name Cloud Foundry domain respectively.
"management": { "endpoints": { "actuator":{ "exposure": { "include": [ "*" ] } } }, "tracing": { "alwaysSample": true, "egressIgnorePattern": "/api/v2/spans|/v2/apps/.*/permissions|/eureka/.*|/oauth/.*", "useShortTraceIds ": true, "exporter": { "zipkin": { "endpoint": "http://zipkin-{initials}.apps.{cloud-foundry-domain}/api/v2/spans", "validateCertificates": false, "useShortTraceIds ": true } } } }
-
We will once again publish our application using the Dotnet Core CLI.
dotnet publish -o .\publish
-
Run the cf push command to build, stage and run your application on PCF. Ensure you are in the same directory as your manifest file and type
cf push
. -
Once the command has completed, navigate to the url to once again see the home page with products listed. From there go to the Zipkin server and observe traces as you navigate and exercise your web store application.