arrow_back

Monitor Cloud Run with Datadog

Sign in Join
Test and share your knowledge with our community!
done
Get access to over 700 hands-on labs, skill badges, and courses

Monitor Cloud Run with Datadog

Lab 1 hour universal_currency_alt 1 Credit show_chart Introductory
Test and share your knowledge with our community!
done
Get access to over 700 hands-on labs, skill badges, and courses

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

Google Cloud self-paced labs logo

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).
Note: 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.
  • Time to complete the lab---remember, once you start, you cannot pause a lab.
Note: If you already have your own personal Google Cloud account or project, do not use it for this lab to avoid extra charges to your account.

How to start your lab and sign in to the Google Cloud console

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

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.

  1. Click Activate Cloud Shell Activate Cloud Shell icon 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, . The output contains a line that declares the Project_ID for this session:

Your Cloud Platform project in this session is set to {{{project_0.project_id | "PROJECT_ID"}}}

gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

  1. (Optional) You can list the active account name with this command:
gcloud auth list
  1. Click Authorize.

Output:

ACTIVE: * ACCOUNT: {{{user_0.username | "ACCOUNT"}}} To set the active account, run: $ gcloud config set account `ACCOUNT`
  1. (Optional) You can list the project ID with this command:
gcloud config list project

Output:

[core] project = {{{project_0.project_id | "PROJECT_ID"}}} Note: For full documentation of 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.

  1. Navigate to https://us5.datadoghq.com/signup and enter your name, email, company, and a password.

  2. Next, select your software stack. For this lab, you will be using Google Cloud Platform. Click Next.

  3. On the next page, you will see a list of available Agent installations. Click Kubernetes.

  4. 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.

    kubernetes startup api key

  5. 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:

gcloud services enable \ run.googleapis.com \ cloudbilling.googleapis.com \ compute.googleapis.com \ cloudasset.googleapis.com \ monitoring.googleapis.com

Task 3. Set up the Google Cloud platform-level integration for Datadog

  1. Navigate to the Google Cloud credentials page (Navigation menu -> APIs & Services -> Credentials) for you Google Cloud project.

  2. Click Create credentials (near the top) and select Service account.

    create service account button

  3. Give the service account a unique name and click Create.

  4. 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.

Note: You must be a Service Account Key Admin to select Compute Engine and Cloud Asset roles. All selected roles allow Datadog to collect metrics, tags, events, and user labels on your behalf.
  1. 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 choose JSON as the type. Click Create. Take note of where this file is saved, as it is needed to complete the installation.

    service account keys tab

  2. Navigate to the Datadog Google Cloud Integration tile.

  3. On the Configuration tab, select Upload Private Key File to integrate this project with Datadog.

    configuration tab for Data Dog integration

  4. 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.

    integration installed

Task 4. Configure Cloud Pub/Sub from Google Cloud to Datadog (for log forwarding)

Create a Cloud Pub/Sub

  1. Go to the Cloud Pub/Sub console in Google Cloud .
  2. Create a topic (the button is on the top).
  3. 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

  1. Go back to the Cloud Pub/Sub console in Google Cloud, and select Subscriptions in the left-hand navigation.

  2. Create a subscription ID by selecting Create Subscription. Give it an appropriate name and select the topic you previously created (export-logs-to-datadog).

  3. 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
  4. 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. Create Cloud PubSub Topic and Configure Subscription

Task 5. Clone the repo

  1. In Cloud Shell, run the following commands to clone the repo and build the container.

First, Clone the repo with a sample app:

git clone https://github.com/DataDog/crpb.git

Next, set the Project ID:

export PROJECT_ID={{{project_0.default_project_id | Project ID}}}

After that, build the Docker image

docker build -t gcr.io/$PROJECT_ID/cloud-run-demo-go:v1 crpb/go

Nearly done! Now push the Docker image up to Google Cloud Registry

docker push gcr.io/$PROJECT_ID/cloud-run-demo-go:v1

Finally, deploy to Google Cloud Run

gcloud run deploy cloud-run-demo-go\ --project=$PROJECT_ID\ --platform=managed\ --region={{{project_0.default_region|DEFAULT_REGION}}}\ --image=gcr.io/$PROJECT_ID/cloud-run-demo-go:v1\ --port=80\ --update-env-vars=DD_API_KEY=$DD_API_KEY\ --allow-unauthenticated\ --memory=512Mi\ --cpu=1\ --no-use-http2

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: running url

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:

  1. Go to the Google Cloud Logging page and filter by Cloud Run Revision logs.

    button create sink

  2. Click Create Sink (in the "More Actions" menu)and name the sink datadog-cloudrun (use this name exactly for proper assessment)

  3. 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.
  4. In step 3, make sure the inclusion filter is resource.type="cloud_run_revision"

    sink creation

  5. 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. Deploy App and Create Sink for Cloud Run Service

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!

datadog traces

You can click on a trace to see more details:

datadog trace detail

Not seeing your traces? Hit your app endpoint a view times (just refresh the Hello World page). You can also try changing the time period located at the top right of the Datadog UI

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!

datadog metrics

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.

datadog logs

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:

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.