= Application tracing using Jaeger
:toc:
:linkcss:
:imagesdir: images

This section will explain how to use http://jaeger.readthedocs.io/en/latest/[Jaeger] to perform distributed tracing on applications deployed on Kubernetes.
Jaeger, inspired by Dapper and OpenZipkin, is a distributed tracing system released as open source by Uber Technologies.
It can be used for monitoring microservice-based architectures and supports the following features:

   * Distributed context propagation
   * Distributed transaction monitoring
   * Root cause analysis
   * Service dependency analysis
   * Performance / latency optimization

In September 2017, Jaeger became a member of the link:https://www.cncf.io/[CNCF].

== Pre-requisites

A 3 master nodes and 5 worker nodes cluster as explained at link:../cluster-install#multi-master-multi-node-multi-az-gossip-based-cluster[] is used for this chapter.

We will use the Istio service mesh sample application, so follow these steps to link:../../service-mesh#install-istio[install istio] and link:../../service-mesh#deploying-the-sample-application[deploy the sample application].
Check that you can see the BookInfo product page in your browser, as seen below.

image::bookinfo.png[]

== Deploy Jaeger

Jaeger can be deployed in two ways:

* a production setup which uses persistent storage for storing the application traces
* an all-in-one setup which uses in-memory storage. Not suitable for production use

We will use the all-in-one setup, which will deploy the Jaeger agent, collector and query service as a single pod.

Deploy the Jaeger all-in-one pod into your cluster:

    kubectl apply -n istio-system -f https://raw.githubusercontent.com/jaegertracing/jaeger-kubernetes/master/all-in-one/jaeger-all-in-one-template.yml

    $ kubectl apply -n istio-system -f https://raw.githubusercontent.com/jaegertracing/jaeger-kubernetes/master/all-in-one/jaeger-all-in-one-template.yml
    deployment "jaeger-deployment" created
    service "jaeger-query" created
    service "jaeger-collector" created
    service "jaeger-agent" created
    service "zipkin" created

If all components were installed successfully, you should be able to see the Jaeger console. Use the shortcut below to
open the Jaeger console. This may take a minute or two, first for the Ingress to be created, and secondly for the Ingress
to hook up with the services it exposes. Just keep refreshing the browser until the Jaeger console appears.

    JAEGER_INGRESS=$(kubectl get svc jaeger-query -n istio-system -o jsonpath="{.status.loadBalancer.ingress[0].*}")
    open http://$JAEGER_INGRESS

You should see the Jaeger console.

image::jaeger-console.png[]

In the Jaeger console, select 'productpage' from the Services drop down, and click 'Find Traces'.
If there are no Services in the drop down (i.e. you only see a '-'), go to the BookInfo application in your browser and refresh the product page.
This will send an HTTP request to the BookInfo application. The HTTP trace will be captured by Jaeger and be visible in the Jaeger console. You'll need to
refresh the Jaeger console page in order to see the list of Services.

image::jaeger-spans.png[]

For each trace (you may only have one), you'll see the total time required by the call, and the number of spans involved (in this case, 11).
In one of the traces, click 'productpage'. You'll see various spans showing the tracing of your request through the BookInfo application,
with the time taken for each call. As the BookInfo application is using Istio for pod-to-pod communication, you can also see the small
overhead Istio introduces into each of the calls.

image::jaeger-trace.png[]

Jaeger can also show you the path taken by a request after it enters via your endpoint. Click on 'Dependencies' in the menu,
then the 'DAG' tab. Jaeger will show you the different microservices invoked by your request.

image::jaeger-dag.png[]

== Cleanup
	$ kubectl delete -n istio-system -f https://raw.githubusercontent.com/jaegertracing/jaeger-kubernetes/master/all-in-one/jaeger-all-in-one-template.yml
