• Home
  • Deploy Dynatrace
  • Set up Dynatrace on cloud platforms
  • Google Cloud Platform
  • Integrations
  • Monitor Google Cloud Run managed

Monitor Google Cloud Run managed

Google Cloud Run managed is a compute platform for running containers in a serverless environment. To monitor services running on Google Cloud Run managed using Dynatrace, you need to integrate OneAgent within your containerized application.

Note: Support for Cloud Run managed in the first generation and second generation execution environments is currently limited to Java only.

Integrate Dynatrace into your containers

There are several ways to build and deploy containers to Cloud Run, such as with Cloud Build.

While the instructions to integrate Dynatrace may differ depending on the technology stack used to build and deploy, the integration of Dynatrace independently follows the same approach:

  1. Add necessary OneAgent binaries to your container image (for example, by either downloading from REST API or copying from the OneAgent image layer).
  2. Configure OneAgent with the necessary connection parameters and additional options such as custom tags.
  3. Enable process injection for automatic instrumentation of your workloads.

Prerequisites

Before you begin, you need to take care of the following:

  • Get an access token to download the Dynatrace OneAgent with InstallerDownload scope. For details on access tokens, see Dynatrace API - Tokens and authentication.

    Important: in the procedures that follow, replace <DT_TOKEN> with your actual access token.

  • Get the environment ID. For details on environment IDs, see Environment ID.

    Important: in the procedures that follow, replace <DT_ENV_ID> with your actual environment ID.

  • Get your Dynatrace API endpoint as defined by your Environment URL or alternatively an ActiveGate address.

    Important: in the procedures that follow, replace <DT_ENV_FQDN> with the actual Dynatrace API endpoint.

  • Install gcloud CLI

After you have completed the above prerequisites, follow one of these procedures (select a tab) to integrate Dynatrace into your containers.

Integrate into cloud built with cloudbuild.yaml

Add OneAgent installer

Configure Cloud Build

Build and deploy

Add the OneAgent installer to a Docker image

Requires Docker version 17.05+

Open your Dockerfile and add the following lines to the application image after the last FROM.

Dockerfile
ARG DT_API_URL="<DT_ENV_FQDN>/api" ARG DT_API_TOKEN="<DT_TOKEN>" ARG DT_ONEAGENT_OPTIONS="flavor=default&include=java" ENV DT_HOME="/opt/dynatrace/oneagent" RUN apt-get update && \ apt-get install -y wget && \ apt-get install unzip && \ mkdir -p "$DT_HOME" && \ wget -O "$DT_HOME/oneagent.zip" "$DT_API_URL/v1/deployment/installer/agent/unix/paas/latest?Api-Token=$DT_API_TOKEN&$DT_ONEAGENT_OPTIONS" && \ unzip -d "$DT_HOME" "$DT_HOME/oneagent.zip" && \ rm "$DT_HOME/oneagent.zip" ENV LD_PRELOAD /opt/dynatrace/oneagent/agent/lib64/liboneagentproc.so # Run the web service on container startup. ENTRYPOINT ["java", "-jar", "/hello-world.jar"]

Make sure to substitute the placeholders with your actual values.

  • <DT_ENV_FQDN> is your actual Dynatrace API endpoint as described in the Prerequisites.
  • <DT_TOKEN> is your actual token as described in the Prerequisites.

Notes:

  • Technology support is enabled via include parameters. For Alpine Linux–based environments, use flavor=musl&include=java.
  • The wget and unzip commands above might fail if they aren't provided by the base image.
Example

A sample Dockerfile as provided by Google via the Getting Started guide on Google Cloud Run with Java, adapted with the instructions provided above.

Dockerfile
# Use the official maven/Java 11 image to create a build artifact. # https://hub.docker.com/_/maven FROM maven:3-jdk-11-slim AS build-env # Set the working directory to /app WORKDIR /app # Copy the pom.xml file to download dependencies COPY pom.xml . # Copy local code to the container image. COPY src ./src # Download dependencies and build a release artifact. RUN mvn package -DskipTests # Use OpenJDK for base image. # https://hub.docker.com/_/openjdk # https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds FROM openjdk:11-jre-slim # Copy the jar to the production image from the builder stage. COPY --from=build-env /app/target/hello-world-*.jar /hello-world.jar # Get and enable Dynatrace ARG DT_API_URL="<DT_ENV_FQDN>/api" ARG DT_API_TOKEN="<DT_TOKEN>" ARG DT_ONEAGENT_OPTIONS="flavor=default&include=java" ENV DT_HOME="/opt/dynatrace/oneagent" RUN apt-get update && \ apt-get install -y wget && \ apt-get install unzip && \ mkdir -p "$DT_HOME" && \ wget -O "$DT_HOME/oneagent.zip" "$DT_API_URL/v1/deployment/installer/agent/unix/paas/latest?Api-Token=$DT_API_TOKEN&$DT_ONEAGENT_OPTIONS" && \ unzip -d "$DT_HOME" "$DT_HOME/oneagent.zip" && \ rm "$DT_HOME/oneagent.zip" ENV LD_PRELOAD /opt/dynatrace/oneagent/agent/lib64/liboneagentproc.so # Run the web service on container startup. ENTRYPOINT ["java", "-jar", "/hello-world.jar"]

Adjust your Google Cloud Build configuration file

Open your cloudbuild.yaml file and add the following environment variables and bash commands to the build step:

yaml
# Build the container image - name: 'gcr.io/cloud-builders/docker' args: ['build', '-t', 'gcr.io/<GCP_PROJECT_ID>/<YOUR_IMAGE_NAME_AND_TAG>', '.'] # Push the container image to Container Registry - name: 'gcr.io/cloud-builders/docker' args: ['push', 'gcr.io/<GCP_PROJECT_ID>/<YOUR_IMAGE_NAME_AND_TAG>']

Add the following lines to your args in your deploy step:

yaml
# Deploy container image to Cloud Run - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk' entrypoint: gcloud args: - beta - run - deploy - $_SERVICE_NAME - --allow-unauthenticated - --image=gcr.io/<GCP_PROJECT_ID>/<YOUR_IMAGE_NAME_AND_TAG> - --region=$_GCP_REGION - --execution-environment=<ENVIRONMENT> - --project=$_PROJECT - --set-env-vars= DT_TAGS=$_SERVICE_NAME, DT_LOGLEVELCON=debug

Make sure to substitute the placeholders with your actual values.

  • <GCP_PROJECT_ID> is the name of your Google Cloud project
  • <YOUR_IMAGE_NAME_AND_TAG> is the name and the tag of your image to be built
  • <ENVIRONMENT> is the execution environment you want to use. Valid options are gen1 for first generation and gen2 for second generation.

Note: You can change the DT_TAGS environment variable to another value as needed.

Build and deploy your Cloud Run Service

Edit and run this command:

bash
gcloud builds submit \ <SAMPLE_NAME> \ --project <GCP_PROJECT_ID> \ --substitutions \ "_API_KEY=<DT_TOKEN>,\ _TENANT_NAME=<DT_ENV_ID>,\ _TENANT_FQDN=<DT_ENV_FQDN>,\ _IMAGE_NAME_AND_TAG=<YOUR_IMAGE_NAME_AND_TAG>,\ _SERVICE_NAME=<YOUR_SERVICE_NAME>,\ _PROJECT=<GCP_PROJECT_ID>,\ _GCP_REGION=<GCP_REGION>,\" \ --config cloudbuild.yaml

Make sure to substitute the placeholders with your actual values.

  • <SAMPLE_NAME>is the name of your Cloud Run Service
  • <GCP_PROJECT_ID> is the name of your Google Cloud project
  • <YOUR_IMAGE_NAME_AND_TAG> is the name and the tag of your image to be built

Integrate into cloud built without cloudbuild.yaml

Add OneAgent installer

Build and deploy

Add the OneAgent installer to a Docker image

Requires Docker version 17.05+

Open your Dockerfile and add the following sample to the application image after the last FROM.

Dockerfile
ARG DT_API_URL="<DT_ENV_FQDN>/api" ARG DT_API_TOKEN="<DT_TOKEN>" ARG DT_ONEAGENT_OPTIONS="flavor=default&include=java" ENV DT_HOME="/opt/dynatrace/oneagent" RUN apt-get update && \ apt-get install -y wget && \ apt-get install unzip && \ mkdir -p "$DT_HOME" && \ wget -O "$DT_HOME/oneagent.zip" "$DT_API_URL/v1/deployment/installer/agent/unix/paas/latest?Api-Token=$DT_API_TOKEN&$DT_ONEAGENT_OPTIONS" && \ unzip -d "$DT_HOME" "$DT_HOME/oneagent.zip" && \ rm "$DT_HOME/oneagent.zip" ENV LD_PRELOAD /opt/dynatrace/oneagent/agent/lib64/liboneagentproc.so # Run the web service on container startup. ENTRYPOINT ["java", "-jar", "/hello-world.jar"]

Make sure to substitute the placeholders with your actual values.

  • <DT_ENV_FQDN> is your actual Dynatrace API endpoint as described in the Prerequisites.
  • <DT_TOKEN> is your actual token as described in the Prerequisites.

Notes:

  • Technology support is enabled via include parameters. For Alpine Linux–based environments, use flavor=musl&include=java.
  • The wget and unzip commands above might fail if they aren't provided by the base image.
Example

This is a sample Dockerfile as provided by Google via the Getting Started guide on Google Cloud Run with Java, adapted with the instructions provided above.

Dockerfile
# Use the official maven/Java 11 image to create a build artifact. # https://hub.docker.com/_/maven FROM maven:3-jdk-11-slim AS build-env # Set the working directory to /app WORKDIR /app # Copy the pom.xml file to download dependencies COPY pom.xml . # Copy local code to the container image. COPY src ./src # Download dependencies and build a release artifact. RUN mvn package -DskipTests # Use OpenJDK for base image. # https://hub.docker.com/_/openjdk # https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds FROM openjdk:11-jre-slim # Copy the jar to the production image from the builder stage. COPY --from=build-env /app/target/hello-world-*.jar /hello-world.jar # Get and enable Dynatrace ARG DT_API_URL="<DT_ENV_FQDN>/api" ARG DT_API_TOKEN="<DT_TOKEN>" ARG DT_ONEAGENT_OPTIONS="flavor=default&include=java" ENV DT_HOME="/opt/dynatrace/oneagent" RUN apt-get update && \ apt-get install -y wget && \ apt-get install unzip && \ mkdir -p "$DT_HOME" && \ wget -O "$DT_HOME/oneagent.zip" "$DT_API_URL/v1/deployment/installer/agent/unix/paas/latest?Api-Token=$DT_API_TOKEN&$DT_ONEAGENT_OPTIONS" && \ unzip -d "$DT_HOME" "$DT_HOME/oneagent.zip" && \ rm "$DT_HOME/oneagent.zip" ENV LD_PRELOAD /opt/dynatrace/oneagent/agent/lib64/liboneagentproc.so # Run the web service on container startup. ENTRYPOINT ["java", "-jar", "/hello-world.jar"]

Build and deploy your Cloud Run Service

To build your Cloud Run Service, edit and run the following command within your project directory:

bash
gcloud builds submit --region=<GCP_REGION> --tag gcr.io/<GCP_PROJECT_ID>/<YOUR_IMAGE_NAME_AND_TAG>

To deploy your Cloud Run Service, edit and run the following command:

bash
gcloud run deploy <YOUR_SERVICE_NAME> --image gcr.io/<GCP_PROJECT_ID>/<YOUR_IMAGE_NAME_AND_TAG>

Make sure to substitute the placeholders with your actual values.

  • <GCP_REGION> is the name of the Google Cloud region you deploy
  • <GCP_PROJECT_ID> is the name of your Google Cloud project
  • <YOUR_IMAGE_NAME_AND_TAG> is the name and the tag of your image to be built
  • <YOUR_SERVICE_NAME> is the name of the service that will be displayed in Dynatrace

Integrate using Jib container tool

Google's Jib container tool builds optimized Docker and OCI images for your Java applications without a Docker daemon—and without requiring deep mastery of Docker best practices. It is available as plugins for Maven and Gradle and as a Java library.

In the GitHub repository for Jib, you can find a sample integration for the Google StackDriver Java agent that follows the same pattern as the Dynatrace integration (Download, Configure, and Inject). You can adapt this blueprint to your needs for integrating Dynatrace using jib.

Additional configuration

You can use additional environment variables to configure, for example, troubleshooting or advanced networking settings.

NameDescription
Networking
DT_NETWORK_ZONESpecifies to use a network zone. For details, see Network zones.
DT_PROXYWhen using a proxy, use this environment variable to pass proxy credentials. For details, see Set up OneAgent on containers for application-only monitoring
Additional metadata for Process Grouping / Service Detection
DT_LOCALTOVIRTUALHOSTNAMEMultiple containers are sometimes detected as a single instance (localhost), leading to various problems in, for example, service detection or availability alerts. Use this environment variable to define a unique name for your container instance. For details, see Service detection and naming
DT_APPLICATIONIDSome technologies don't provide unique application names. In such cases, use this environment variable to provide a unique name. For details, see Service detection and naming
DT_TAGSApplies custom tags to your process group
DT_CUSTOM_PROPApplies custom metadata to your process group
DT_CLUSTER_IDIf the process group detection rules won't work for your use-case, use this environment variable to group all processes with the same value.
DT_NODE_IDIf the process group detection rules won't work for your use-case, use this environment variable to separate process group instances
Troubleshooting
DT_LOGSTREAMSet this variable with stdout to configure agent to log errors into console. To see additional agent logs set the log level with DT_LOGLEVELCON as below.
DT_LOGLEVELCONUse this environment variable to define the console log level. Valid options are NONE, SEVERE, INFO in order to increase log level.
DT_AGENTACTIVEtrue or false to enable or disable OneAgent.

Verify that the integration was successful

After the build and deploy, you should start seeing your Cloud Run service in Dynatrace.

Verify via service overview

Check your service's overview within Dynatrace for your instrumented application.

Note: The service will show up in Dynatrace after running the newly built version and calling it at least once via, for example, a webrequest.

Verify via host overview

You can filter for containers in the host overview to filter by Monitoring Mode with Standalone/PaaS.

Known limitations

  • No host metrics for Gen1

    The first generation of the GCR execution environment, also referred to as Gen1, comes with intentionally increased security limitations. As a consequence, some OneAgent functionalities cannot work in this runtime and are not available. For example, metrics on the Hosts page such as CPU Usage and Memory Usage are not available.

  • GCR instances detected as hosts

    GCR execution environments are currently displayed on the Hosts page, with proper detection of GCP properties and the memory limit of each of these runtime (container) instances, not on the Container groups page. Container metrics are not available.

  • Possible startup overhead

    Because each revision of Google Cloud Run scales automatically to the number of container instances needed to handle incoming requests, such cold starts might appear more often than on other environments, thus increasing overall startup overhead.

Update OneAgent

Each time you want to leverage a new version of Dynatrace OneAgent, you must rebuild and redeploy.

If you've specified a default OneAgent installation version for new hosts and applications using OneAgent update settings, your application will be automatically monitored by the defined default version of OneAgent.

Uninstall OneAgent

To uninstall OneAgent from application-only monitoring, remove references from your application or Docker image and redeploy the application.

Related topics
  • Set up Dynatrace on Google Cloud Platform

    Monitor Google Cloud Platform with Dynatrace.

  • OneAgent platform and capability support matrix

    Learn which capabilities are supported by OneAgent on different operating systems and platforms.