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
.
Then in the script that you want to debug, add in the debugger;
statement to trigger the debugger during execution.
Also, we need to enable debugging for the GatewayScript Action.
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:
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 |
|
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.
You can also see the status of the debug action in DataPower by searching for Debug Action Status
to see any live debug sessions.
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.