Step Debugging Edge Micro Proxies

kkleva
Participant V

Is there any way to step-debug Edge Micro plugin code? All attempts have been unsuccessful so far. Is this because plugins run in a vm sandbox? Any way around this? Should I be debugging the Agent, Gateway or both?

We've tired Node debugger and iron-node.

0 5 929
5 REPLIES 5

prabhat
Participant V

We will have it in next release. Currently agent does not has option to take debug params.

This response was two years ago.

Surely we must have have at least one "next release" of MG since then ...

... Is there still no way to step debug a custom plugin ?

Former Community Member
Not applicable

The only way to debug is custom plugin is for the custom plugin to use the "debug" npm module. You can then use the DEBUG environment variable to selectively enable debug for specific packages. Take a look at the plugins Apigee has developed, it uses the same method.

Implementing your suggestion, I am able to filter the debug output lines, restricting them to a single proxy I am interested in. I am still not getting to step-debug the plugin.

Debug setup:

Out of interest for other readers, here's the (Windows) environment setup required.

  • Install debug on the plugin. Check dependency added in package.json
[npm prefix] \node_modules\edgemicro\plugins\your-plugin>npm install debug
  • Add debug to your plugin
  var debug = require('debug')('plugin:your-plugin');
and under the function
  debug('your plugin message here');
  • Instead of starting node via “edgemicro start”, issue from the edgemicro folder ...
    • Set debug filter > set DEBUG=plugin:your-plugin
    • Start debug session of node > node --inspect app.js

Now when you run your plugin, only debug print lines from your plugin will be shown.

Trying step-debugging:

If you issue inspect, you can see the gateway console react, issuing message …

Debugger listening on port 5859.

You can also connect to the debug session under Chrome via “about://inspect”.

To break on the first statement of the script, use --inspect-brk

(In Node 6, you have to use --inspect --debug-brk )

The system will pause on the first line … from where you can debug as expected.

This is encouraging progress !! :smiley

But that’s where we get stuck, despite stepping through the code line by line.

  • Cannot find where plugins load … it breaks and hangs up after a while.
  • Tried DEBUG=* but also DEBUG=plugin:header-uppercase ... nothing stops there.
  • Tried "debugger;" statements in the plugin but it doesn't stop there.
  • Not able to access the “in-memory” version of the plugin code to add a breakpoint.

Ideally we want to have the debug session stop when the plugin is loaded/called etc.

We seem to lose debugging when files other than app.js includes are loaded.

Not applicable

I was able to do step debugging of my plugin by invoking the edgemicro executable (script) from node with the --inspect-brk flag.

Instead of

edgemicro start -p 1

I used

node --inspect-brk /Users/PAT5422/.nvm/versions/node/v8.5.0/lib/node_modules/edgemicro/cli/edgemicro start -p 1

I'm sure this is a resource hog as you are debugging all of edgemicro this way, but in Chrome Dev Tools you are able to find your plugin js file easily enough and add breakpoints.