The following describes how to use the delve debugger with telegraf during development. Delve has many, very well documented subcommands and options.
To run telegraf manually, users can run:
go run ./cmd/telegraf --config config.toml
To attach delve with a similar config users can run the following. Note the
additional --
to specify flags passed to telegraf. Additional flags need to
go after this double dash:
$ dlv debug ./cmd/telegraf -- --config config.toml
Type 'help' for list of commands.
(dlv)
At this point a user could set breakpoints and continue execution.
Visual Studio Code's go language extension includes the ability to easily make use of delve for debugging. Check out this full tutorial from the go extension's wiki.
A basic config is all that is required along with additional arguments to tell Telegraf where the config is located:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"args": ["--config", "/path/to/config"]
}
]
}
JetBrains' GoLand also includes full featured debugging options.
The following is an example debug config to run Telegraf with a config:
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="build & run" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="telegraf" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="--config telegraf.conf" />
<kind value="DIRECTORY" />
<package value="github.com/influxdata/telegraf" />
<directory value="$PROJECT_DIR$/cmd/telegraf" />
<filePath value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
</component>