Introduction
Cloud trace is defined as a distributed tracing system that collects latency data from the applications and then displays it on the Google Cloud Console. It automatically analyzes all of the application's traces in order to generate in-depth latency reports for surfacing the application's traces. This blog will cover the basics of Cloud Trace.

Trace app latency
A user can learn how to use cloud trace by following the below-mentioned steps:
- A sample application must be deployed to the GKE cluster.
- By sending an HTTP request to the application, create a trace.
- View the latency information of the newly created trace using the Cloud Trace Interface.
Download and Deploy the application
Follow the below-mentioned steps to download and deploy the application:
- Click on the Activate Cloud Shell in the Google Cloud console toolbar to open a Cloud Shell.
- If you want to download the source code from GitHub, use the below-mentioned command
gcloud services enable container.googleapis.com
- If you want to enable the GKE API, use the below-mentioned command in the cloud shell:
gcloud services enable container.googleapis.com
- In order to create a GKE cluster with a name demo, use the below-mentioned command
gcloud container clusters create demo --zone us-west1-b
- To verify successful creation, use the below-mentioned kubectl command:
kubectl get nodes
- The cluster context can be set using the below-mentioned command:
gcloud container clusters get-credentials demo --zone us-west1-b
- By using the below command, deploy the same application:
cd python-docs-samples/trace/cloud-trace-demo-app && ./setup.sh
Create a trace
The time that is taken by an application to complete a single operation is described by a trace. A trace can consist of one or more spans. How long it takes to perform a complete sub-operation is described by span.
A trace can be created using the following command:
curl $(kubectl get svc cloud-trace-demo-c -ojsonpath='{.status.loadBalancer.ingress[0].ip}')
A HTTP GET request is generated by the curl command, and an issue to the request to service names cloud-trace-demo-c. Helloworl! It is printed to the shell when the request is completed.
View the trace data
Click on the Navigation Menu and then Select Trace to open the cloud trace interface.
Overview Window
It is the default view in the trace. It provides latency data and summary information along with an analysis report. If a new project is created, then the most interesting pane of the Overview window is the pane labeled as the Recent traces, it lists all of the most recent traces with their latency.
Trace list window
To open the trace list window, click on the trace list in the trace navigation pane. The trace list window displays a graph and a table, where each dot on the graph represents a trace. Every dot also corresponds to a row in the table. Select a dot in the graph or a row in the table if you want to view a trace in detail. This opens two panes that display the details of the selected trace. One pane displays the trace in a waterfall graph, and the pane shows its details. Every row corresponds to a span in the waterfall graph. If you want to view the details about a span, then click on the corresponding row in the waterfall graph.
About the application
The same application which we used earlier is present in the GitHub repository. It contains information on how to use the application in various environments.
Instrumentation
The necessary information regarding capturing and tracing data to the Google cloud project is in the app.py file in the GitHub repository.
- A middleware component is created by the application that uses Flask as the HTTP framework.
- Create a Flask middleware that uses the StackdriverExporter() in the application's main function.
How the application Works
The application creates three services which are named a,b, and c. it configures the service c to call the service b and the service b to call service a. When an HTTP request to service c is issued, the following command is used:
curl $(kubectl get svc cloud-trace-demo-c -ojsonpath='{.status.loadBalancer.ingress[0].ip}')
The curl command works in a below-mentioned way:
- The IP address of the service names cloud-trace-demo-c is fetched by kubectl.
- A HTTP request to service c is sent using the curl command.
- When service c receives the HTTP request, it sends a request to service b.
- When service b receives the HTTP request, it sends a request to service a.
- When the service receives the request, it returns the string Hello. The string Hello is a keyword passes as a default argument to this service.
- When service b receives the response from service a, it appends the string with string world and then returns Helloworld. The string world is a keyword that is passed as a default argument to this service.
- When service c receives the response from service b, it appends !, and then returns Helloworld!
- Finally, the response from the services c is printed in the Cloud Shell.
Clean up
Follow the below-mentioned steps if you want to avoid any incurring charger to your Google cloud account for the resources used.
-
If a new project was created for the quickstart, then delete the project to stop accruing charges. To delete the project, follow the below-mentioned steps:
- Click on the Navigation Menu and Select Home in the google cloud console.
- Click on Go to project settings in the Project info pane.
- Click on Shut down in the Settings window and complete the remaining steps.
- If a new project wasn't created for the quickstart, then delete the GKE cluster named as a demo using the below-mentioned command:
gcloud container clusters delete demo --zone us-west1-b