Chun Sing Tsui

Coding, Technology, and other Interests

DataPower GatewayScript Remote Debugging With Visual Studio Code

This short guide will show how to connect a remote debugger like Visual Studio Code or Chrome DevTools to help debug your GatewayScript, allowing you to inspect variables and step through lines of code to help with troubleshooting and development.

Enabling GatewayScript Remote Debugging

First we need to enable remote debugging. Search gatewayscript remote debugger and set to enabled. Make sure the port is accessible from your local machine.

For example, if DataPower is running on local Docker, use docker run ... -p 9229:9229 ... to expose the port. If running on Kubernetes/Openshift, use kubectl port-forward dp-pod 9229:9229 so it is accessible via localhost.

remote-debugging

Then in the script that you want to debug, add in the debugger; statement to trigger the debugger during execution.

gwscript-debugger

Also, we need to enable debugging for the GatewayScript Action.

action-debugging

Connecting with Visual Studio Code

First we need to create a launch.json file to tell VS Code how to connect to the DP Debugging interface:

vscode-debug-launch

Then use the node type and inspector protocol in the configuration as follows. Set timeout to be a larger number so it won’t time out while you trigger the policy/gatewayscript action.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "attach",
            "name": "Attach to DP",
            "address": "localhost",
            "port": "9229",
            "protocol": "inspector",
            "timeout": 100000
          }
    ]
}

Press Run to start the debugger, and then trigger your gatewayscript action. You’ll then be able to step through the code or inspect variables.

vscode-debug-statement

You can also see the status of the debug action in DataPower by searching for Debug Action Status to see any live debug sessions.

vscode-debug-statement

Connecting with Chrome DevTools

Connecting with Chrome DevTools is quite straight-forward. Navigate to chrome://inspect/#devices, and press Configure.. to add your debugging address/port (e.g. localhost:9229) to the list if it doesn’t already exist. When the GWS action is triggered, the debug session should show up and you can then click on inspect to show the debugger.

vscode-debug-statement

References

https://www.ibm.com/support/knowledgecenter/SS9H2Y_7.7.0/com.ibm.dp.doc/debugger_remotedebugging.html

https://github.com/ibm-datapower/datapower-tutorials/blob/master/gatewayscript-remote-debugging/gateway-script-remote-debugging.md

https://code.visualstudio.com/docs/nodejs/nodejs-debugging