Cloud Debugger lets you inspect the state of an application, at any code location, without stopping or slowing down the running application.
Cloud Debugger is supported in all Google Cloud runtime environments (except for Cloud Functions) and can also be used when running applications in non-Google Cloud environments (on-premises, other clouds).
Enable API
gcloudservicesenableclouddebugger.googleapis.com
Snapshot
A Snapshot can introspect the context information on a given line of code as user go through the code flow.
Logpoint
A Logpoint can add additional log messages to a running application without modifying the code nor redeploying the code.
Conditions
In both Snapshot and Logpoint, you can specify conditionals so you can capture specific information for a specific request (e.g., match against a session ID, or request ID).
Java Agent
Cloud Debugger works by adding a Java agent to your JVM startup argument, and the agent can communicate with the Cloud Debugger service in the Cloud. Through the Cloud Console, you can then instruct your JVM instances to take a Snapshot of the application state at a specific line of code, or to add an additional log message on a specific line.
Agent Files
There are 2 types of Cloud Debugger Java agents that authenticates with Cloud Debugger service differently:
By default the Cloud Debugger agent writes its logs to cdbg_java_agent.INFO file in the default logging directory. You can overwrite the log file path:
Cloud Debugger agent is automatically added to your App Engine application.
In Cloud Debugger console, you can see the Default service in the drop down:
Add the Cloud Debugger Java agent to the container, and configure the agent in the startup command line.
Clone
# Clone the sample repository manuallygitclonehttps://github.com/saturnism/jvm-helloworld-by-examplecdjvm-helloworld-by-example/helloworld-springboot-tomcat
Containerize with a Dockerfile
In the Dockerfile, download the Cloud Debugger and build it as part of the container image:
Dockerfile
FROM openjdk:11
# Create a directory for the Debugger. Add and unzip the agent in the directory.
RUN mkdir /opt/cdbg && \
wget -qO- https://storage.googleapis.com/cloud-debugger/compute-java/debian-wheezy/cdbg_java_agent_gce.tar.gz | \
tar xvz -C /opt/cdbg
COPY target/helloworld.jar /app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
Download the Cloud Debugger Java agent into src/main/jib directory so that Jib can include the agent files as part of the container image:
# Make a directory to store the Java agentmkdir-psrc/main/jib/opt/cdbg# Download and extract the Java agent to the directorywget-qO-https://storage.googleapis.com/cloud-debugger/compute-java/debian-wheezy/cdbg_java_agent_gce.tar.gz| \tarxvz-Csrc/main/jib/opt/cdbg
In Cloud Debugger console, you can see the helloworld service in the drop down:
Add the Cloud Debugger Java agent to the container, and configure the agent in the startup command line.
Clone
# Clone the sample repository manuallygitclonehttps://github.com/saturnism/jvm-helloworld-by-examplecdjvm-helloworld-by-example/helloworld-springboot-tomcat
Containerize with a Dockerfile
In the Dockerfile, download the Cloud Debugger and build it as part of the container image:
Dockerfile
FROM openjdk:11
# Create a directory for the Debugger. Add and unzip the agent in the directory.
RUN mkdir /opt/cdbg && \
wget -qO- https://storage.googleapis.com/cloud-debugger/compute-java/debian-wheezy/cdbg_java_agent_gce.tar.gz | \
tar xvz -C /opt/cdbg
COPY target/helloworld.jar /app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
Download the Cloud Debugger Java agent into src/main/jib directory so that Jib can include the agent files as part of the container image:
# Make a directory to store the Java agentmkdir-psrc/main/jib/opt/cdbg# Download and extract the Java agent to the directorywget-qO-https://storage.googleapis.com/cloud-debugger/compute-java/debian-wheezy/cdbg_java_agent_gce.tar.gz| \tarxvz-Csrc/main/jib/opt/cdbg
In Cloud Debugger console, you can see the helloworld-gce service in the drop down:
You can attach the Cloud Debugger agent to any Java application even if it runs outside of the Google Cloud environment (whether it's in a container, or on your local laptop, or in another cloud). Authentication has to be done using Service Account key file rather than using the Machine Credentials.
This only works on a Linux x86 based system.
Clone
# Clone the sample repository manuallygitclonehttps://github.com/saturnism/jvm-helloworld-by-examplecdjvm-helloworld-by-example/helloworld-springboot-tomcat
Cloud Debugger needs to have access to the application's source code in order for you to add a Snapshot or Logpoint from the Cloud Debugger console. There are severals ways to associating the source code:
Existing Git Repository
Source code capture / upload
Git repository reference from git.properties
IntelliJ Cloud Code plugin
Git Repository
From Cloud Debugger console, navigate to Deployed Files > Add source code.
Choose an Alternative source code.
For example, using an existing GitHub repository:
Once selected, the contents of the Git repository will be available to navigate.
Upload
Upload from Browser
From Cloud Debugger console, navigate to Deployed Files > Add source code.
Choose an Alternative source code.
Click on Local files's Select Source, then simply select the folder/directory that contains the source code.
Upload from Command Line
You can use gcloud CLI to upload the source code into a Source Captures repository.
Create a Source Captures repository:
# Enable APIgcloudservicesenablesourcerepo.googleapis.com# Create a source capture repositorygcloudsourcereposcreategoogle-source-captures
In the Alternative source code choices, scroll to the very bottom is Upload a source code capture to Google servers.
Do not click on Select source yet.
Use the command line to upload the source code (for example, if you deployed the Helloworld Application):
# Clone the sample repository manuallygitclonehttps://github.com/GoogleCloudPlatform/java-docs-samplescdjava-docs-samples/appengine-java11/springboot-helloworld# Upload just the `src/` directory.# Note that the `branch` value is important and you must use the same value# that's shown in the UIgcloudbetadebugsourceupload \--project=<FROMTHEUI> \--branch=<FROMTHEUI> \src/
Once uploaded, click Select source.
Use git.properties
You can associate a Git repository using the git-commit-plugin that generates a git.properties file, which contains the information to the Git repository. This only works if the repository is publicly accessible.