Debugging Guide
Guide to debugging ZMS with VSCode and gRPC plugins
Debugging Guide
This guide explains how to debug ZMS with gRPC plugins in VSCode.
Available Launch Configurations
1. Launch Debug profile (Legacy)
Original debug configuration using debug tags.
- Use case: Basic debugging of ZMS core functionality
- Config file:
zmsd-test.yaml - Build flags:
-tags debug
2. ZMS with Print Plugin (Recommended)
Launches ZMS with the print plugin pre-built and ready to use.
- Use case: Debugging ZMS with gRPC plugin integration
- Config file:
zmsd-test.yaml - Pre-launch task: Automatically builds the print plugin
- Build flags: Includes version info and ldflags
- Environment:
ZMS_LOG_LEVEL=debugfor verbose logging - Console: Integrated terminal for better output visibility
How to use:
- Press
F5or select “ZMS with Print Plugin” from the debug dropdown - The print plugin will be built automatically before launch
- ZMS will start with debug logging enabled
- Plugin output will appear in the integrated terminal
3. Debug Print Plugin (Standalone)
Launches the print plugin as a standalone process for testing.
- Use case: Testing plugin in isolation without ZMS
- Program:
plugins/print/print.go - Console: Integrated terminal
How to use:
- Select “Debug Print Plugin” from the debug dropdown
- The plugin will run standalone (useful for testing plugin logic)
- Note: This is mainly for plugin development, not normal usage
Build Tasks
The following VSCode tasks are available (via Ctrl+Shift+B or Terminal > Run Build Task):
build-print-plugin
Builds the print plugin executable.
- Output:
build/bin/plugins/print - Source:
plugins/print/print.go
build-log-print-plugin
Builds the log_print example plugin executable.
- Output:
build/bin/plugins/log_print - Source:
examples/plugins/log_print/log_print.go
build-all-plugins (Default)
Builds all plugins in parallel.
- Dependencies: build-print-plugin, build-log-print-plugin
clean-plugins
Removes all built plugin executables.
- Removes:
build/bin/pluginsdirectory
Configuration Files
zmsd-test.yaml
Test configuration file used by debug launches.
Key settings:
|
|
Configured targets:
print2(type:log_print) - Filters LOG-type history itemsprint(type:print) - Prints all history items to stderr
Plugin Architecture
ZMS uses HashiCorp’s go-plugin framework for gRPC-based plugins:
- Main Process: ZMS core (
cmd/zmsd/main.go) - Plugin Processes: Independent executables in
build/bin/plugins/ - Communication: gRPC with Protocol Buffers
- Isolation: Plugins run as separate processes
Debugging Workflow
Standard Debugging Session
- Set breakpoints in ZMS code or plugin code
- Launch with “ZMS with Print Plugin” configuration
- Monitor output in the integrated terminal
- Step through code as ZMS processes data
Plugin Development Workflow
- Edit plugin code in
plugins/print/print.go - Rebuild using task:
Ctrl+Shift+B> “build-print-plugin” - Restart debugger to load new plugin binary
- Test changes
Multi-Process Debugging
To debug both ZMS and the plugin simultaneously:
- Launch ZMS with “ZMS with Print Plugin”
- Attach to the plugin process using “Debug Print Plugin”
- Note: The plugin runs as a child process of ZMS
Environment Variables
The following environment variables are set for debugging:
ZMS_LOG_LEVEL=debug- Enables verbose logging
You can add more in the launch configuration’s env section.
Troubleshooting
Plugin Not Found
Error: Failed to load plugin: exec: "print": executable file not found
Solution: Run the “build-print-plugin” task or “build-all-plugins”
Plugin Handshake Failed
Error: plugin handshake failed
Solution: Ensure plugin was built with matching pkg/plugin version
Permission Denied
Error: permission denied when launching plugin
Solution: Ensure plugin executable has execute permissions:
|
|
Config File Not Found
Error: config file not found
Solution: Ensure zmsd-test.yaml exists and paths are correct
Zabbix Server Config Missing
Error: failed to parse server config
Solution: Update server_config path in zmsd-test.yaml to point to valid Zabbix server config
Tips
- Use Integrated Terminal: Set
"console": "integratedTerminal"to see plugin output clearly - Rebuild Before Launch: The preLaunchTask ensures plugins are always fresh
- Check Plugin Logs: Plugins use structured logging - check stderr for plugin messages
- Version Info: Build flags include version/commit/date for debugging builds
- Clean Builds: Use “clean-plugins” task if you encounter caching issues
Related Files
.vscode/launch.json- Debug configurations.vscode/tasks.json- Build taskszmsd-test.yaml- Test configurationplugins/print/print.go- Print plugin sourceexamples/plugins/log_print/log_print.go- Log print plugin example
References
- Architecture - ZMS architecture overview
- CLAUDE.md - ZMS development guide
- HashiCorp go-plugin - Plugin framework documentation
- VSCode Go Debugging - VSCode Go extension debugging guide