github.com/influxdata/telegraf@v1.30.3/docs/developers/DEBUG.md (about)

     1  # Debug
     2  
     3  The following describes how to use the [delve][1] debugger with telegraf
     4  during development. Delve has many, very well documented [subcommands][2] and
     5  options.
     6  
     7  [1]: https://github.com/go-delve/delve
     8  [2]: https://github.com/go-delve/delve/blob/master/Documentation/usage/README.md
     9  
    10  ## CLI
    11  
    12  To run telegraf manually, users can run:
    13  
    14  ```bash
    15  go run ./cmd/telegraf --config config.toml
    16  ```
    17  
    18  To attach delve with a similar config users can run the following. Note the
    19  additional `--` to specify flags passed to telegraf. Additional flags need to
    20  go after this double dash:
    21  
    22  ```bash
    23  $ dlv debug ./cmd/telegraf -- --config config.toml
    24  Type 'help' for list of commands.
    25  (dlv)
    26  ```
    27  
    28  At this point a user could set breakpoints and continue execution.
    29  
    30  ## Visual Studio Code
    31  
    32  Visual Studio Code's [go language extension][20] includes the ability to easily
    33  make use of [delve for debugging][21]. Check out this [full tutorial][22] from
    34  the go extension's wiki.
    35  
    36  A basic config is all that is required along with additional arguments to tell
    37  Telegraf where the config is located:
    38  
    39  ```json
    40  {
    41      // Use IntelliSense to learn about possible attributes.
    42      // Hover to view descriptions of existing attributes.
    43      // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    44      "version": "0.2.0",
    45      "configurations": [
    46          {
    47              "name": "Launch Package",
    48              "type": "go",
    49              "request": "launch",
    50              "mode": "auto",
    51              "program": "${fileDirname}",
    52              "args": ["--config", "/path/to/config"]
    53          }
    54      ]
    55  }
    56  ```
    57  
    58  [20]: https://code.visualstudio.com/docs/languages/go
    59  [21]: https://code.visualstudio.com/docs/languages/go#_debugging
    60  [22]: https://github.com/golang/vscode-go/wiki/debugging
    61  
    62  ## GoLand
    63  
    64  JetBrains' [GoLand][30] also includes full featured [debugging][31] options.
    65  
    66  The following is an example debug config to run Telegraf with a config:
    67  
    68  ```xml
    69  <component name="ProjectRunConfigurationManager">
    70    <configuration default="false" name="build &amp; run" type="GoApplicationRunConfiguration" factoryName="Go Application">
    71      <module name="telegraf" />
    72      <working_directory value="$PROJECT_DIR$" />
    73      <parameters value="--config telegraf.conf" />
    74      <kind value="DIRECTORY" />
    75      <package value="github.com/influxdata/telegraf" />
    76      <directory value="$PROJECT_DIR$/cmd/telegraf" />
    77      <filePath value="$PROJECT_DIR$" />
    78      <method v="2" />
    79    </configuration>
    80  </component>
    81  ```
    82  
    83  [30]: https://www.jetbrains.com/go/
    84  [31]: https://www.jetbrains.com/help/go/debugging-code.html