elastic / template-kibana-plugin

sao.js template for kibana plugins
Apache License 2.0
64 stars 34 forks source link

Step-by-step debugging (inspect) my Kibana plugin server side code #4

Closed sscarduzio closed 7 years ago

sscarduzio commented 7 years ago

I saw instructions on how to debug Kibana code from here https://medium.com/@paul_irish/debugging-node-js-nightlies-with-chrome-devtools-7c4a1b95ae27

But I can't make it work for my plugin. This is what I tried:

I added a "debugger;" statement in the middle of my code, so I expect it to stop as it was a breakpoint.

$ NODE_OPTIONS="--debug --inspect" npm start

> readonlyrest_kbn@0.1.6-pre1 start /me/kibana_plugin/new
> plugin-helpers start

Debugger listening on port 9229.
Warning: This is an experimental feature and could change at any time.
To start debugging, open the following URL in Chrome:
    chrome-devtools://devtools/remote/serve_file/@60cd6e859b9f557d2312f5bf532f6aec5f284980/inspector.html?experiments=true&v8only=true&ws=localhost:9229/4215b5b1-e4d3-45f7-97d0-c8aad47017ce
 watching for changes  (409 files)
Debugger listening on port 5859.
Warning: This is an experimental feature and could change at any time.
To start debugging, open the following URL in Chrome:
    chrome-devtools://devtools/remote/serve_file/@60cd6e859b9f557d2312f5bf532f6aec5f284980/inspector.html?experiments=true&v8only=true&ws=localhost:5859/a265edd1-57ae-408c-813b-c49778600c1d
Debugger listening on port 5860.
Warning: This is an experimental feature and could change at any time.
To start debugging, open the following URL in Chrome:
    chrome-devtools://devtools/remote/serve_file/@60cd6e859b9f557d2312f5bf532f6aec5f284980/inspector.html?experiments=true&v8only=true&ws=localhost:5860/9f2b65b0-6521-44ba-a1d3-9a03afde9de

Three node processes are started, all allow an inspector connection, but none of them is stopped at my "debugger;" statement as I open the chrome inspector.

I ran out of ideas :(

sscarduzio commented 7 years ago

sorry I should have used the forum for this as it's not a bug 🤦‍♂️

w33ble commented 7 years ago

You're right, it's not an issue with the template, so I'm going to close this.

I can tell you that you're using the debugger wrong though. You need to use --debug-brk, which will stop execution on the first line, which allows you to open the debugger and continue execution, at which point the chrome debugger will catch your debugger statement.

tl;dr use --debug-brk instead of of just --debug.

It seems odd that you get a debugger for all the other processes though (presumably the dev server and... I'm not sure what the 3rd process would be, are reading those settings too). That could be worth opening a bug in the Kibana repo for.