Checkpoints
Create Cloud PubSub Topic and Configure Subscription
/ 50
Deploy and Create Sink for Cloud Run Service
/ 50
Monitor Cloud Run with Datadog
- GSP1147
- Overview
- Setup and Requirements
- Task 1. Set up a Datadog trial account
- Task 2. Enable Google Cloud services
- Task 3. Set up the Google Cloud platform-level integration for Datadog
- Task 4. Configure Cloud Pub/Sub from Google Cloud to Datadog (for log forwarding)
- Task 5. Clone the repo
- Task 6. Observe tracing in Datadog
- Task 7. Explore Metrics in Datadog
- Task 8. Investigate Logs in Datadog
- Congratulations!
This lab was developed with our partner, Datadog. Your personal information may be shared with Datadog, the lab sponsor, if you have opted-in to receive product updates, announcements, and offers in your Account Profile.
GSP1147
Overview
Datadog is a monitoring and analytics platform for cloud-based applications, infrastructure, and networks. It provides real-time visibility into application performance, infrastructure health, and user experience.
The Datadog integration for Google Cloud Platform is a powerful way to get data into Datadog with minimal effort. It is agentless and pulls metadata at the Platform level from Google Cloud APIs. In addition, the new Datadog Cloud Run agent delivers official support for traces and custom metrics in managed Cloud Run instances.
In this lab, you'll explore how to connect Datadog to your Google Cloud project, and use it to monitor a Cloud Run app. You'll also explore the new APM/tracing capabilities offered by the new Datadog Cloud Run agent.
Objectives
You will learn how to:
- Set up the Datadog platform integration
- Configure log forwarding
- View tracing information collected by the new Datadog Cloud Run agent
- Explore Cloud Run metrics in Datadog
- Explore Cloud Run logs in Datadog
Setup and Requirements
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.
This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
How to start your lab and sign in to the Google Cloud console
-
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
-
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. -
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.
-
Click Next.
-
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.
-
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. -
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.
Activate Cloud Shell
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
- Click Activate Cloud Shell at the top of the Google Cloud console.
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
- (Optional) You can list the active account name with this command:
- Click Authorize.
Output:
- (Optional) You can list the project ID with this command:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
Task 1. Set up a Datadog trial account
If you already have a trial account set up, you can use that. It is recommended that you do not use your production Datadog account to avoid cluttering the environment with test and training assets.
-
Navigate to https://us5.datadoghq.com/signup and enter your name, email, company, and a password.
-
Next, select your software stack. For this lab, you will be using Google Cloud Platform. Click Next.
-
On the next page, you will see a list of available Agent installations. Click Kubernetes.
-
You can see two commands listed. You won't be using these for Cloud Run, but scroll over the first box to see the datadog.apiKey. Copy this to your clipboard. You might also want to leave this page open in a tab so that you can come back and grab the API key again if you need it later.
-
Back in the Cloud Console, navigate back to your Cloud Shell window. Run the following command, replacing
<YOUR_DATADOG_API_KEY>
with your API key in the appropriate slot:export DD_API_KEY=<YOUR_DATADOG_API_KEY> Note: If you close Cloud Shell, you'll lose the environment variable you just added. Keep it somewhere safe temporarily, or just leave the page open with the API key as mentioned above in case you need to add it again.
Task 2. Enable Google Cloud services
With Google Cloud, nothing is enabled by default to protect you from using a costly system by accident. Run the following in Cloud Shell to enable all the APIs needed for this lab:
Task 3. Set up the Google Cloud platform-level integration for Datadog
-
Navigate to the Google Cloud credentials page (Navigation menu -> APIs & Services -> Credentials) for you Google Cloud project.
-
Click Create credentials (near the top) and select Service account.
-
Give the service account a unique name and click Create.
-
Add the following roles (make sure to use these roles exactly as they are spelled out here! There are a lot of roles that look similar): Compute Viewer, Monitoring Viewer, and Cloud Asset Viewer. Click Done. If you get an error, try clicking Continue / Done again.
-
At the bottom of the page, find your Service Accounts and select the one you just created. On the Keys tab, click
Add Key -> Create new key
, and chooseJSON
as the type. Click Create. Take note of where this file is saved, as it is needed to complete the installation. -
Navigate to the Datadog Google Cloud Integration tile.
-
On the Configuration tab, select Upload Private Key File to integrate this project with Datadog.
-
Press Install Integration. If you get an error that says "Could not save your configuration due to a conflicting update. Please reload and try again.", go ahead and reload and it should show that the project was added successfully anyway.
Task 4. Configure Cloud Pub/Sub from Google Cloud to Datadog (for log forwarding)
Create a Cloud Pub/Sub
- Go to the Cloud Pub/Sub console in Google Cloud .
- Create a topic (the button is on the top).
- Give that topic the name
export-logs-to-datadog
(make sure to use this exact name for proper assessment.in this lab) and Save. The default options are fine. Make sure Add a default subscription is checked.
Forward Logs to Datadog
-
Go back to the Cloud Pub/Sub console in Google Cloud, and select Subscriptions in the left-hand navigation.
-
Create a subscription ID by selecting Create Subscription. Give it an appropriate name and select the topic you previously created (
export-logs-to-datadog
). -
Change the method to Push. For the endpoint, enter the following (make sure to replace the Datadog API key in this string):
https://gcp-intake.logs.datadoghq.com/api/v2/logs?dd-api-key=<DD_API_KEY>&dd-protocol=gcp
. Do NOT enable authentication.Note: Make sure you replace with your API key from before. You can also create an API key or pick an existing API key in Datadog Organization Settings -> API Keys -
Hit Create at the bottom.
🎉 The Cloud Pub/Sub is ready to receive logs from Google Cloud Logging and forward them to Datadog.
Click Check my progress to verify the objective.
Task 5. Clone the repo
- In Cloud Shell, run the following commands to clone the repo and build the container.
First, Clone the repo with a sample app:
Next, set the Project ID:
After that, build the Docker image
Nearly done! Now push the Docker image up to Google Cloud Registry
Finally, deploy to Google Cloud Run
If you get a message that says Allow unauthenticated invocations to [cloud-run-demo-go] (y/N)?
, it probably means you typed something wrong or the command wasn't copied properly. Ctrl-C and try again.
When this completes, you should see the URL for your running app:
It's very important that you now click the URL and visit the page to generate some traces! Refresh the page a few times for good measure.
Now make logs flow for Cloud Run:
-
Go to the Google Cloud Logging page and filter by Cloud Run Revision logs.
-
Click Create Sink (in the "More Actions" menu)and name the sink
datadog-cloudrun
(use this name exactly for proper assessment) -
Choose “Cloud Pub/Sub” as the destination and select the Pub/Sub that was created for that purpose.
Note: For future reference, the pub/sub can be located in a different project. -
In step 3, make sure the inclusion filter is
resource.type="cloud_run_revision"
-
Click Create Sink and wait for the confirmation message to show up.
🎉 Nice work! The Cloud Run app should now be running and sending metrics to Datadog.
Click Check my progress to verify the objective.
Task 6. Observe tracing in Datadog
Head over to your Datadog console. If you go to APM > Traces, you should see some traces from your Cloud Run app!
You can click on a trace to see more details:
Task 7. Explore Metrics in Datadog
Head over to your Datadog console. If you go to Metrics > Explorer, then add metric gcp.run.enhanced.cold_start
and gcp.run.enhanced.shutdown
you should see some metrics from your Cloud Run app!
Task 8. Investigate Logs in Datadog
You should also be able to head over to Logs in the Datadog console, select a log, and get more context.
Congratulations!
In this lab, you got hands-on experience using Datadog's new Google Cloud Run integration and Datadog's Google Cloud Platform-level integration which makes monitoring your workloads easy!
Next Steps / Learn More
Be sure to check out the following labs for more practice with Datadog:
- Datadog Docs
- Datadog Labs
- Datadog Learn
- Find Datadog in the Google Cloud Marketplace
Google Cloud training and certification
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated August 30, 2023
Lab Last Tested May 12, 2023
Copyright 2024 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.