Debugging a service

Debugging your Cloud Run service

To debug your service, follow these steps:

  1. Select Debug on Cloud Run Emulator using the Command Palette (accessible with Ctrl/Cmd+Shift+P) to run your service and attach a debugger session to it.
  2. This launches the Run/Debug on Cloud Run Emulator dialog where you can set the specifications for your configuration.

  3. Optionally, you can further customize how your service is run by specifying your environment variables and directly defining fields in your launch.json.

  4. Click Debug to begin debugging your service.

  5. For each debuggable container in your service, you'll be prompted to confirm or enter the directory in the remote container where the program you'd like to debug is found.

    Alternatively, you can press ESC to skip debugging the container.

    Cloud Code will attach a debug session for each debuggable container in the service.

  6. Click in the editor margin of the file you are debugging to add a breakpoint.

    Red filled circles denote active breakpoints, while gray hollow circles signify disabled breakpoints.

    When you send a new request to your service, it will pause at that desired line.

  7. After your session completes, additional contextual menu options are available to monitor your application and its resources via the Cloud Code status bar, including:

    • Open Deployment Logs: Open the application logs of a specific deployment with the Cloud Code Logs Viewer
    • Open Service URL: Open the application service URL of a specific service in a web browser
    • Turn on/off watch mode: Toggle watch mode for the current session (not available for debug sessions)

      Options available via the Cloud Code status bar: Open Deployment Logs, Open Service URL, and Turn on Watch mode, in addition to regular Cloud Code actions

  8. (Optional) To inspect variables and stack info, use the Debug Sidebar. To interact with the debugging session, use the Debug Console in the bottom pane debugger.

  9. To stop your deployment, you can click the Stop button in the action bar for your current deployment.

    Action bar for Cloud Run deployment