Your first debug session
In this tutorial, you attach Delve to a Go service in your cluster and stop at a breakpoint.
Before you start
- DebugHero is installed.
- Your cluster and your binary meet the cluster requirements.
kubectl get pods -n <namespace>works in your shell and shows the target pod. DebugHero uses the same kubeconfig askubectl:KUBECONFIG, else~/.kube/config. See Which cluster DebugHero uses.- You have the source code of the service on your machine, at the same version as the image.
You need these values for the target pod:
| Value | Example | Notes |
|---|---|---|
| Namespace | payments | |
| Pod labels | app=checkout | Use labels that select exactly one pod. DebugHero uses the first pod in the list. |
| Container name | app | Optional. The default is the first container in the pod. |
| Process name | checkout | Optional. The default is PID 1 in the container. |
To check that the labels select one pod, run:
kubectl get pods -n payments -l app=checkout
1. Start debugd
Open a terminal and start the daemon:
debugd
debugd listens on port 58090 and writes its logs to ~/.debughero/logs/debugd.log. Keep it running while you debug.
To check that it runs, open another terminal and run:
curl http://localhost:58090/health/check
2. Log in
debugctl login
Your browser opens the DebugHero sign-in page. After you sign in, debugctl stores your credentials in the OS keychain.
You can also sign in from the IDE: in VS Code, select Sign In in the DebugHero view; in GoLand, run the action DebugHero: Login.
3. Start a session
Select one of the three methods.
VS Code
- Open the folder of the service as the workspace. DebugHero maps the workspace root to the build directory of the binary, so the workspace root must be the root of the Go module that was built.
- Select the DebugHero icon in the Activity Bar. The Debug Sessions view opens.
- Enter the Pod labels and the Namespace. Optionally, enter the Container name and the Match process name.
- Select Start Debug Session.
- When the session is ready, select Connect. VS Code starts a debug session that is attached to Delve.
GoLand
- Open the project of the service.
- Open the DebugHero tool window.
- Enter the Pod labels and the Namespace. Optionally, enter the container name and the process name.
- Select Start Debug Session.
- When the session is ready, select Connect. GoLand starts a Go Remote debug configuration that is attached to Delve.
CLI
-
Start the session:
shelldebugctl debug --namespace payments --labels app=checkoutOutputdebug session requested — run `debugctl get sessions` to check status -
Wait until the status is
READY:shelldebugctl get sessionsNote the values in the
DEBUGGER_PORTandPATHcolumns. -
Connect your IDE to
127.0.0.1:<DEBUGGER_PORT>. For VS Code, add this configuration to.vscode/launch.json:.vscode/launch.json{"version": "0.2.0","configurations": [{"name": "DebugHero","type": "go","request": "attach","mode": "remote","host": "127.0.0.1","port": 40123,"substitutePath": [{"from": "${workspaceFolder}", "to": "/src"}]}]}Replace
40123with theDEBUGGER_PORTvalue and/srcwith thePATHvalue.
4. Stop at a breakpoint
- Set a breakpoint in a handler of the service.
- Send a request that runs this handler. If the service is not exposed, forward its port. With
debugctl debug, use--port <application-port>. In the IDE form, enter the App port. DebugHero forwards it to the same port number onlocalhost. - The IDE stops at the breakpoint. You can now examine variables, goroutines, and the call stack.
- Continue the process quickly. While it is stopped, it does not answer requests or health checks.
5. End the session
There are two different actions:
- Disconnect closes the connection of the IDE to Delve. The session continues, and Delve stays attached to the process. You can connect again.
- Stop Session ends the session. Delve removes its breakpoints and detaches. The process continues to run. The debug container exits, and the session status changes to
COMPLETED. You cannot connect to this session again.
To stop the session, do one of these steps:
-
In the IDE, select Stop Session on the session. In VS Code, the session is in the Debug Sessions view. In GoLand, it is in the DebugHero tool window.
-
In a terminal, run:
shelldebugctl stop <session-id>The output shows the result:
outputsession 3: COMPLETEDdebugger detached: truecontainer terminated: true
If you only disconnect, the session stops automatically after 1 hour.
Stop the session when you are done. Then Delve does not stay attached to a production process.
If something does not work
| Symptom | What to do |
|---|---|
failed to start debug session - make sure debugd is running | Start debugd. If you changed its port, use the same port in the IDE settings. |
The session status is FAILED | Run debugctl get sessions and read the LAST_ERRORS column. |
The session is READY, but the IDE does not connect | Run debugctl logs <session-id> to see the Delve log. |
Version of Delve is too old for Go version in the Delve log | The binary was built with Go 1.26 or later. See Go version. |
| Breakpoints are not hit, or show as unverified | The source path mapping is wrong. Open the module root as the workspace, and check that your source has the same version as the image. |
LAST_ERRORS starts with missing kubernetes permissions or blocked by | RBAC or an admission policy rejected the debug container. See Cluster requirements and Admission policy exemptions. |
debugd writes more details to ~/.debughero/logs/debugd.log.