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.
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:
Before you begin, you need to take care of the following:
Get an access token with InstallerDownload scope to retrieve connection parameters from the Dynatrace API. For details on access tokens, see Dynatrace API - Tokens and authentication.
In the procedures that follow, replace <DT_TOKEN> with your actual access token.
Get your environment ID and API endpoint. The endpoint is https://<DT_ENV_ID>.live.dynatrace.com. For details, see What is a monitoring environment?.
In the procedures that follow, replace <DT_ENV_ID> with your environment ID and <DT_ENV_FQDN> with your API endpoint.
Install gcloud CLI
Retrieve and store connection credentials in Secret Manager. Retrieve runtime connection parameters from the Dynatrace connection info API:
curl -H "Authorization: Api-Token <DT_TOKEN>" "https://<DT_ENV_FQDN>/api/v1/deployment/installer/agent/connectioninfo"
Map the response fields to the following environment variables:
| Environment variable | API response field |
|---|---|
DT_TENANT | tenantUUID |
DT_TENANTTOKEN | tenantToken (a short communication token, not the PaaS token) |
DT_CONNECTION_POINT | formattedCommunicationEndpoints |
Store each value as a secret:
echo -n "<DT_CONNECTION_POINT_VALUE>" | gcloud secrets create dt-connection-point --data-file=- --project=<GCP_PROJECT_ID>echo -n "<DT_TENANT_VALUE>" | gcloud secrets create dt-tenant --data-file=- --project=<GCP_PROJECT_ID>echo -n "<DT_TENANTTOKEN_VALUE>" | gcloud secrets create dt-tenanttoken --data-file=- --project=<GCP_PROJECT_ID>
Grant the Cloud Run service account the roles/secretmanager.secretAccessor role on your secrets. See Secret Manager access control for details. Replace <PROJECT_NUMBER> with the numeric project ID (run gcloud projects describe <GCP_PROJECT_ID> --format='value(projectNumber)'):
gcloud projects add-iam-policy-binding <GCP_PROJECT_ID> --member="serviceAccount:<PROJECT_NUMBER>-compute@developer.gserviceaccount.com" --role="roles/secretmanager.secretAccessor"
After you have completed the above prerequisites, follow one of these procedures (select a tab) to integrate Dynatrace into your containers.
If you use Cloud Build, you may encounter toomanyrequests rate limit errors when pulling codemodule images directly from public ECR, because Cloud Build workers share IP address pools. To avoid this, mirror the image to a private registry.
Pull the codemodule image and push it to a registry within your own infrastructure. Example using Google Artifact Registry:
gcloud artifacts repositories create dynatrace --repository-format=docker --location=<GCP_REGION> --project=<GCP_PROJECT_ID>gcloud auth configure-docker <GCP_REGION>-docker.pkg.devdocker pull public.ecr.aws/dynatrace/dynatrace-codemodules:<VERSION>-<TECH>docker tag public.ecr.aws/dynatrace/dynatrace-codemodules:<VERSION>-<TECH> <GCP_REGION>-docker.pkg.dev/<GCP_PROJECT_ID>/dynatrace/dynatrace-codemodules:<VERSION>-<TECH>docker push <GCP_REGION>-docker.pkg.dev/<GCP_PROJECT_ID>/dynatrace/dynatrace-codemodules:<VERSION>-<TECH>
Replace <TECH> with the technology tag (for example python) and <VERSION> with the codemodule version. Then update the CODEMODULE_IMAGE ARG in your Dockerfile to point to your private registry path.
cloudbuild.yamlRequires Docker version 17.05+
Add the codemodule as the first build stage and copy its contents into the runtime image using COPY --from. Select the tab for your technology.
Replace <VERSION> with an available codemodule tag. Browse available tags at gallery.ecr.aws/dynatrace/dynatrace-codemodules. Note that tech-specific tags (for example -python) are not published for every version. Use the all-technology tag (no suffix) as a fallback. No docker login is required because public.ecr.aws/dynatrace is publicly accessible.
The runtime base image must be glibc-based. Alpine (musl libc) is not supported by the Dynatrace code module for any technology.
ARG CODEMODULE_IMAGE=public.ecr.aws/dynatrace/dynatrace-codemodules:<VERSION>-javaFROM ${CODEMODULE_IMAGE} AS dynatraceFROM maven:3-eclipse-temurin-21-alpine AS buildWORKDIR /appCOPY pom.xml .RUN mvn -q dependency:go-offlineCOPY src ./srcRUN mvn -q package -DskipTestsFROM eclipse-temurin:21-jreCOPY --from=dynatrace / /WORKDIR /appCOPY --from=build /app/target/*.jar app.jarENV LD_PRELOAD=/opt/dynatrace/oneagent/agent/lib64/liboneagentproc.soENV DT_LOGSTREAM=stdoutEXPOSE 8080ENTRYPOINT ["java", "-jar", "app.jar"]
Open your cloudbuild.yaml file and add the following steps:
steps:# Build the container image- name: 'gcr.io/cloud-builders/docker'args: ['build', '-t', '$_IMAGE', '.']# Push the container image to Artifact Registry- name: 'gcr.io/cloud-builders/docker'args: ['push', '$_IMAGE']# Deploy container image to Cloud Run- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'entrypoint: gcloudargs:- run- deploy- $_SERVICE_NAME- --allow-unauthenticated- --image=$_IMAGE- --region=$_GCP_REGION- --execution-environment=gen2- --project=$_PROJECT- --update-secrets=DT_CONNECTION_POINT=dt-connection-point:latest,DT_TENANT=dt-tenant:latest,DT_TENANTTOKEN=dt-tenanttoken:latest- --update-env-vars=DT_TAGS=$_SERVICE_NAME,DT_LOGLEVELCON=INFO
$_IMAGE is your full Artifact Registry image path, for example <GCP_REGION>-docker.pkg.dev/<GCP_PROJECT_ID>/<REPO>/<IMAGE>:<TAG><GCP_PROJECT_ID> is the name of your Google Cloud projectThe gen2 execution environment is recommended for best compatibility.
You can change DT_TAGS and DT_LOGLEVELCON as needed. DT_LOGLEVELCON accepts NONE, INFO, WARNING, or SEVERE.
Edit and run this command:
gcloud builds submit . --project <GCP_PROJECT_ID> --substitutions "_IMAGE=<GCP_REGION>-docker.pkg.dev/<GCP_PROJECT_ID>/<REPO>/<IMAGE>:<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.
. is the build source directory (current directory)<GCP_REGION>-docker.pkg.dev/<GCP_PROJECT_ID>/<REPO>/<IMAGE>:<TAG> is the full Artifact Registry image path<YOUR_SERVICE_NAME> is the name of your Cloud Run service, also used as the DT_TAGS value<GCP_PROJECT_ID> is the name of your Google Cloud project<GCP_REGION> is the name of the Google Cloud region you deploy toYou can use additional environment variables to configure, for example, troubleshooting or advanced networking settings.
| Name | Description |
|---|---|
DT_NETWORK_ZONE | Specifies to use a network zone. For details, see Network zones. |
DT_PROXY | When using a proxy, use this environment variable to pass proxy credentials. For details, see Set up OneAgent on containers for application-only monitoring |
| Name | Description |
|---|---|
DT_LOCALTOVIRTUALHOSTNAME | Multiple 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 v1 |
DT_APPLICATIONID | Some technologies don't provide unique application names. In such cases, use this environment variable to provide a unique name. For details, see Service Detection v1 |
DT_TAGS | Applies custom tags to your process group |
DT_CUSTOM_PROP | Applies custom metadata to your process group |
DT_CLUSTER_ID | If 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_ID | If the process group detection rules won't work for your use-case, use this environment variable to separate process group instances |
| Name | Description |
|---|---|
DT_LOGSTREAM | Set 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_LOGLEVELCON | Use this environment variable to define the console log level. Valid options are NONE, INFO, WARNING, SEVERE in order to increase log level. |
This section contains variables only relevant for .NET environments.
| Parameter | Description |
|---|---|
DT_AGENTACTIVE | .NET-specific variable to configure OneAgent monitoring of .NET Framework and .NET Core applications. OneAgent .NET monitoring is active by default (true). To deactivate it, set DT_AGENTACTIVE to false. If you configure .NET monitoring using the .NET profiler environment variables, you need to set DT_AGENTACTIVE to true to activate it. |
After the build and deploy, you should start seeing your Cloud Run service in Dynatrace.
Check your service's overview within Dynatrace for your instrumented application.
The service will show up in Dynatrace after running the newly built version and calling it at least once via, for example, a webrequest.
You can filter for containers in the host overview to filter by Monitoring Mode with Standalone/PaaS.
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.
To update to a new version of Dynatrace OneAgent, update the <VERSION> tag in the CODEMODULE_IMAGE ARG in your Dockerfile, then rebuild and redeploy.
To uninstall OneAgent from application-only monitoring, remove references from your application or Docker image and redeploy the application.