camel-karavan icon indicating copy to clipboard operation
camel-karavan copied to clipboard

JBang - run in JVM debug mode so you can do JVM remote debugging

Open davsclaus opened this issue 2 years ago • 9 comments

We should find out if we can launch jbang in JVM debug mode (there are some JVM flags you need to turn on, to make it debug mode on port 5005, and suspend=y etc.

And if so we should find out if we can make VSCode detect this and be able to debug the Camel code. Not sure how easy it is for it to know which JARs to have on its project and so on.

But its also a more general problem with jbang, so we can talk to Max about this.

davsclaus avatar Nov 22 '21 13:11 davsclaus

I think this feature outside Karavan for now. If we have yaml route debugger in VSCode perhaps we could try to visualize it on the diagram.

mgubaidullin avatar Nov 23 '21 23:11 mgubaidullin

If we have yaml route debugger in VSCode perhaps we could try to visualize it on the diagram.

The Camel route debugger for yaml dsl is now available: https://www.youtube.com/watch?v=GEQHexFKWcQ&list=PLU-T8l-XOWOPjrXPojx2WDSegigcNzKs4&index=4

Given that with latest version, JMX is supported, this other video can be interesting https://www.youtube.com/watch?v=YSr-FccRgms&list=PLU-T8l-XOWOPjrXPojx2WDSegigcNzKs4&index=2&t=37s

That said, the Camel route debugger for yaml dsl is a different kind of debugging than the JVM debug. The JVM debug is also possible to attach to a running process Screenshot from 2022-04-15 14-41-51

apupier avatar Apr 15 '22 12:04 apupier

documentation for jbang in debug mode https://www.jbang.dev/documentation/guide/latest/debugging.html so basically would mean to add the --debug and it will automatically open debug port 4004

apupier avatar Apr 15 '22 12:04 apupier

  1. Karavan works as VS Code extension and web app (standalone and in kubernetes). Debug should somehow works in both.
  2. If I understand correctly Debug uses line number to be known. In that case we need first to make a new yaml-to-integration parser because the current one (js-yaml) does not provide this info.

mgubaidullin avatar Apr 15 '22 13:04 mgubaidullin

Yesterday I tried the vscode camel debugger and with a bit of configuring those config files then made it work. I could debug camel jbang for yaml files.

I think in .java then vscode would set the breakpoint as a java breakpoint so that was not possible.

Also I added camel-debug always so its included https://github.com/apache/camel/commit/ae2997944e49f29b64aebfed9151507cf8b16bcf

davsclaus avatar Apr 15 '22 13:04 davsclaus

I think in .java then vscode would set the breakpoint as a java breakpoint so that was not possible.

Unless I misunderstood the use case, it is working (cannot combine the task and the launch config, shoudl require extra configuration): CamelDebuggerWithJavaDSlLaunchedthroughJBang

Also I added camel-debug always so its included apache/camel@ae29979

camel-jbang cannot be used in production?

apupier avatar Apr 15 '22 14:04 apupier

cannot combine the task and the launch config, shoudl require extra configuration

managed to have teh single-click working.

.vscode/tasks.json:

{
	// See https://go.microsoft.com/fwlink/?LinkId=733558
	// for the documentation about the tasks.json format
	"version": "2.0.0",
	"tasks": [
		{
			"label": "Start Camel application in debug with Jbang",
			"type": "shell",
			"command": "jbang",
			"args": [
				"-Dcamel.jbang.version=3.16.0",
				"camel@apache/camel",
				"run",
				"${relativeFile}",
				"--max-messages=100",
				"--logging-level=info",
				"--reload",
				"--dep=org.apache.camel:camel-debug"
			],
			"group": "none",
			"isBackground": true,
			"problemMatcher": { // Problem matcher is mandatory to avoid a dialog warning on each launch but cannot find a good way to configure it
				"owner": "camel",
				"pattern": {
					"regexp": "^.*$"
				},
				"severity": "error",
				"source": "maven",
				"background": {
					"activeOnStart": true,
					"beginsPattern": "^.*$",
					"endsPattern": "^.*JMX Connector thread started and listening at.*$"
				}
			},
			"presentation": {
				"reveal": "always"
			}
		}
	]
}

.vscode/launch.json:

{
	"version": "0.2.0",
	"configurations": [
		{
			"name": "Run with Camel Debugger",
			"type": "apache.camel",
			"request": "attach",
			"preLaunchTask": "Start Camel application in debug with Jbang" // This must match the label provided as task
		}
	]
}

apupier avatar Apr 20 '22 09:04 apupier

Will be implemented as a part of #151

mgubaidullin avatar Sep 14 '22 20:09 mgubaidullin

Will be implemented as a part of #151

Java debugging and Camel debugging are 2 different things. Both functionnaly and technically behind the scenes. I think both issues should stay opened as they can be handled completely independently

apupier avatar Sep 15 '22 06:09 apupier