With Cloud Code, you can debug your Cloud Run applications locally in a Cloud Run-like environment. You can set breakpoints, step through your code, and debug remote applications running in containers.
Defining your debug configuration
Before you debug your application, you must create your debug configuration:
- Navigate to Run/Debug configurations dialog on the top taskbar and click 'Edit Configurations'.
- Choose 'Cloud Run: Run Locally' under Cloud Code: Cloud Run.
- Click 'OK'.
Debugging your application
To debug your application, follow these steps:
Click the debug action for 'Cloud Run: Run Locally' to start the development cycle in debug mode.
Cloud Code will attach a debug session. Once successful, the Debug Tool window opens, confirming connection (within the Console tab).
Click the gutter at the executable line of the code where you want to add a breakpoint.
Red filled circles denote active breakpoints, while red-outlined hollow circles signify disabled breakpoints.
To access your running app, click the URL displayed in your Event Log panel.
When you do, a new request is sent to your application and it pauses at the breakpoint-marked line.
To end the debugging session, click the stop icon on the Cloud Run: Run Locally run configuration.
Cloud Code, powered by Skaffold under the hood, can help configure your debugging sessions. With Cloud Code, you can set breakpoints and debug remote applications running in containers for the following languages:
Cloud Code will automatically add an environment variable,
JAVA_TOOL_OPTIONS, with the appropriate JDWP configuration to
enable debugging. If already present, Cloud Code will use
existing settings specified in
Depending on the structure of your application and its image build configuration, you may have to help the debugger map your local sources to the remote sources in the container. This enables the Node debugger to correctly process your breakpoints.
There are two ways to configure this:
Select the 'Cloud Run: Run Locally' Run Configuration from the dropdown and select 'Edit Configurations'. In the 'Debug' tab, configure the source mapping from your local application source to the source location in the remote container.
- File/Directory - the local file or directory of your application running on Cloud Run.
- Remote Path - the path to the file or directory running in the container on Cloud Run.
You can choose to defer this mapping to Cloud Code. When you start your debug session, Cloud Code will attempt to infer this mapping automatically. It will be presented to you in a dialog; one dialog for each artifact you are debugging.
- Local path - the local path to the root of the artifact you are debugging.
- Remote Path - the path to the file or directory running in the
container on Cloud Run. You can choose to override
this with your own value. If you hit
Cancel, then no mapping will be applied.
In order to configure your application for debugging, your app must be:
- a Go Module-based application.
- identified as being Go-based by setting one of the
standard Go runtime environment variables
in the container, such as
GOTRACEBACK=singleis the default setting for Go, and
GOTRACEBACK=allis a generally useful configuration.
Optionally (but recommended), your app should be built with the
-gcflags='all=-N -l' options to disable optimizations. Skaffold
Profiles are a useful
option for this purpose, and can be set with the 'Deployment Profile' field in
your Run configuration under the 'Build/Deploy' tab.
For more details, refer to the Skaffold debug documentation.