arrow_back

View application latency with Cloud Trace

登录 加入
访问 700 多个实验和课程

View application latency with Cloud Trace

实验 1 小时 15 分钟 universal_currency_alt 5 积分 show_chart 中级
info 此实验可能会提供 AI 工具来支持您学习。
访问 700 多个实验和课程

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. Navigation menu icon

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}')

The output looks like the following:

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

In the Google Cloud console, go to Navigation menu (The navigation menu icon.) View all products → Observability → Trace → Trace Explorer, where you’ll see the Span ID (If not, rerun the curl command, refresh, and wait for the Span ID to appear.).

You can execute the curl command multiple times to generate multiple traces, and the Span ID may take a few minutes to appear.

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 (The navigation menu icon.) 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.

准备工作

  1. 实验会创建一个 Google Cloud 项目和一些资源,供您使用限定的一段时间
  2. 实验有时间限制,并且没有暂停功能。如果您中途结束实验,则必须重新开始。
  3. 在屏幕左上角,点击开始实验即可开始

使用无痕浏览模式

  1. 复制系统为实验提供的用户名密码
  2. 在无痕浏览模式下,点击打开控制台

登录控制台

  1. 使用您的实验凭证登录。使用其他凭证可能会导致错误或产生费用。
  2. 接受条款,并跳过恢复资源页面
  3. 除非您已完成此实验或想要重新开始,否则请勿点击结束实验,因为点击后系统会清除您的工作并移除该项目

此内容目前不可用

一旦可用,我们会通过电子邮件告知您

太好了!

一旦可用,我们会通过电子邮件告知您

一次一个实验

确认结束所有现有实验并开始此实验

使用无痕浏览模式运行实验

请使用无痕模式或无痕式浏览器窗口运行此实验。这可以避免您的个人账号与学生账号之间发生冲突,这种冲突可能导致您的个人账号产生额外费用。