Debugging applications in odo

With odo, you can attach a debugger to remotely debug your application. This feature is only supported for NodeJS and Java components.

Components created with odo run in the debug mode by default. A debugger agent runs on the component, on a specific port. To start debugging your application, you must start port forwarding and attach the local debugger bundled in your Integrated development environment (IDE).

Debugging an application

You can debug your application in odo with the odo debug command.

Procedure

  1. Download the sample application that contains the necessary debugrun step within its devfile:

    1. $ odo create nodejs --starter

    Example output

    1. Validation
    2. Checking devfile existence [11498ns]
    3. Checking devfile compatibility [15714ns]
    4. Creating a devfile component from registry: DefaultDevfileRegistry [17565ns]
    5. Validating devfile component [113876ns]
    6. Starter Project
    7. Downloading starter project nodejs-starter from https://github.com/odo-devfiles/nodejs-ex.git [428ms]
    8. Please use `odo push` command to create the component with source deployed
  2. Push the application with the --debug flag, which is required for all debugging deployments:

    1. $ odo push --debug

    Example output

    1. Validation
    2. Validating the devfile [29916ns]
    3. Creating Kubernetes resources for component nodejs
    4. Waiting for component to start [38ms]
    5. Applying URL changes
    6. URLs are synced with the cluster, no changes are required.
    7. Syncing to component nodejs
    8. Checking file changes for pushing [1ms]
    9. Syncing files to the component [778ms]
    10. Executing devfile commands for component nodejs
    11. Executing install command "npm install" [2s]
    12. Executing debug command "npm run debug" [1s]
    13. Pushing devfile component nodejs
    14. Changes successfully pushed to component

    You can specify a custom debug command by using the —debug-command=”custom-step” flag.

  3. Port forward to the local port to access the debugging interface:

    1. $ odo debug port-forward

    Example output

    1. Started port forwarding at ports - 5858:5858

    You can specify a port by using the —local-port flag.

  4. Check that the debug session is running in a separate terminal window:

    1. $ odo debug info

    Example output

    1. Debug is running for the component on the local port : 5858
  5. Attach the debugger that is bundled in your IDE of choice. Instructions vary depending on your IDE, for example: VSCode debugging interface.

Configuring debugging parameters

You can specify a remote port with odo config command and a local port with the odo debug command.

Procedure

  • To set a remote port on which the debugging agent should run, run:

    1. $ odo config set DebugPort 9292

    You must redeploy your component for this value to be reflected on the component.

  • To set a local port to port forward, run:

    1. $ odo debug port-forward --local-port 9292

    The local port value does not persist. You must provide it every time you need to change the port.