arrow_back

View application latency with Cloud Trace

Sign in Join
Get access to 700+ labs and courses

View application latency with Cloud Trace

Lab 1 hour 15 minutes universal_currency_alt 5 Credits show_chart Intermediate
info This lab may incorporate AI tools to support your learning.
Get access to 700+ labs and courses

Overview

In this lab, you learn how to use Cloud Trace by sending an HTTP request to the sample application.

Objectives

Learn how to use Trace by doing the following:

  • Deploy a sample application to a Google Kubernetes Engine (GKE) cluster.
  • Create a trace by sending an HTTP request to the sample application.
  • Use the Trace interface to view the latency information of the trace you created.

Setup and requirements

For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.

  1. Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:

    • The Open Google Cloud console button
    • Time remaining
    • The temporary credentials that you must use for this lab
    • Other information, if needed, to step through this lab
  2. Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).

    The lab spins up resources, and then opens another tab that shows the Sign in page.

    Tip: Arrange the tabs in separate windows, side-by-side.

    Note: If you see the Choose an account dialog, click Use Another Account.
  3. If necessary, copy the Username below and paste it into the Sign in dialog.

    {{{user_0.username | "Username"}}}

    You can also find the Username in the Lab Details panel.

  4. Click Next.

  5. Copy the Password below and paste it into the Welcome dialog.

    {{{user_0.password | "Password"}}}

    You can also find the Password in the Lab Details panel.

  6. Click Next.

    Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges.
  7. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Google Cloud console opens in this tab.

Note: To view a menu with a list of Google Cloud products and services, click the Navigation menu at the top-left, or type the service or product name in the Search field.

Task 1. Download and deploy your application

In this task, you download a sample application from GitHub, enable the Google Kubernetes Engine API, create a GKE cluster, update cluster credentials, verify access, and deploy the application's three services.

To download and deploy the sample application, do the following:

  1. To open the Cloud Shell, click Activate Cloud Shell in the Google Cloud console toolbar. If prompted, click Continue.

After a few moments, a Cloud Shell session opens inside the Google Cloud console.

  1. To download the source code from GitHub, run the following command:
git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
  1. Enable the Google Kubernetes Engine API by using the following command. If prompted, click Authorize.
gcloud services enable container.googleapis.com
  1. To create the GKE cluster named cloud-trace-demo in the zone, run the following commands in the Cloud Shell:
ZONE={{{project_0.default_zone|place_holder_text}}} gcloud container clusters create cloud-trace-demo \ --zone $ZONE

This command takes a few minutes to complete. After it completes successfully, your Google Cloud project contains the GKE cluster named cloud-trace-demo. You must have permission to create clusters that have external access in your Google Cloud project.

  1. Update your GKE cluster credentials by running the following command:
gcloud container clusters get-credentials cloud-trace-demo --zone $ZONE
  1. Verify access to the cluster by running the following command:
kubectl get nodes

A sample output of this command is:

NAME STATUS ROLES AGE VERSION gke-cloud-trace-demo-default-pool-063c0416-113s Ready 78s v1.22.12-gke.2300 gke-cloud-trace-demo-default-pool-063c0416-1n27 Ready 79s v1.22.12-gke.2300 gke-cloud-trace-demo-default-pool-063c0416-frkd Ready 78s v1.22.12-gke.2300
  1. Deploy the sample application by running the following command:
cd python-docs-samples/trace/cloud-trace-demo-app-opentelemetry && ./setup.sh

The script setup.sh configures three services of the application using a pre-built image. The workloads are named cloud-trace-demo-a, cloud-trace-demo-b, and cloud-trace-demo-c. The setup script waits for all resources to be provisioned, so the configuration might take several minutes to complete.

A sample output of this command is:

deployment.apps/cloud-trace-demo-a is created service/cloud-trace-demo-a is created deployment.apps/cloud-trace-demo-b is created service/cloud-trace-demo-b is created deployment.apps/cloud-trace-demo-c is created service/cloud-trace-demo-c is created

Click Check my progress to verify the objective. Create a cluster and deploy the sample application

Task 2. Create a trace

In this task, you generate traces by sending curl requests cloud-trace-demo-a and then view the trace data in Trace.

  1. To create a trace by sending a curl request to cloud-trace-demo-a, use the following command:
curl $(kubectl get svc -o=jsonpath='{.items[?(@.metadata.name=="cloud-trace-demo-a")].status.loadBalancer.ingress[0].ip}')

You can execute the curl command multiple times to generate multiple traces.

The output looks like the following:

Hello, I am service A And I am service B Hello, I am service C

Click Check my progress to verify the objective. Create a cloud trace

View the trace data

  1. In the Google Cloud console, in the Navigation menu () click View all products > Observability > Trace.

Trace shows distributed traces for analysis. It displays a heatmap of span durations over time, along with a table of individual spans, filterable by service name, span name, status, duration, and kind. The interface allows users to investigate performance issues and understand request flow within a distributed system.

The chart view displays the duration of spans over time using a heatmap. Each colored block represents a span, and its color intensity indicates its duration. This allows you to quickly identify slow spans or trends in latency.

  1. In the chart view, click one of the darker span blocks.

  2. In the Spans table, click any Span ID. A detailed breakdown of the specific trace is displayed. Each horizontal bar represents the duration of each span within the trace. The length of the bar corresponds to the span's duration.

This section of the trace provides a detailed view of a single request's journey through the system, breaking it down into individual operations (spans) and showing their timing and relationships. It helps pinpoint performance bottlenecks and understand the sequence of events.

  1. To view details about a span, click one of the span bars.

Additional details about each span are shown in the details pane below.

Congratulations!

In this lab, you performed the following tasks:

  • Deployed a sample application to a Google Kubernetes Engine (GKE) cluster.
  • Created a trace by sending an HTTP request to the sample application.
  • Used the Trace interface to view the latency information of the trace you created.

Good job.

End your lab

When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.

You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.

The number of stars indicates the following:

  • 1 star = Very dissatisfied
  • 2 stars = Dissatisfied
  • 3 stars = Neutral
  • 4 stars = Satisfied
  • 5 stars = Very satisfied

You can close the dialog box if you don't want to provide feedback.

For feedback, suggestions, or corrections, please use the Support tab.

Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.

Before you begin

  1. Labs create a Google Cloud project and resources for a fixed time
  2. Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
  3. On the top left of your screen, click Start lab to begin

This content is not currently available

We will notify you via email when it becomes available

Great!

We will contact you via email if it becomes available

One lab at a time

Confirm to end all existing labs and start this one

Use private browsing to run the lab

Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.