Configure the Go agent

The standard configuration for all agents uses this order of precedence.

There are different ways to configure the Go agent:

  • A YAML configuration file is required to run your application. It is not needed to run the Go agent. You can create your own YAML configuration file or use this YAML template that contains all valid properties for the Go agent.

    You can configure the Contrast service separately or they share the same contrast_security.yaml configuration file. Place the file at /etc/contrast/contrast_security.yaml and then find the agent keys and set these values:

    api:
      url:
      api_key:
      secret_key:
      user_name:
    agent:
      service:
        host: 127.0.0.1
        port: 30555
        #socket: /tmp/contrast.sock # optional: only `socket` OR `host` and `port` should be set
        grpc: true
  • You can use environment variables to configure your build.

  • Command line configuration is also available.

Command line arguments for Go

The contrast-go build tool supports some runtime flags to control how the application is instrumented as it is built.

These build time flags are supported:

contrast-go [flags] build
  • -v increases the level of logging when building application.

  • -vv includes all logging when building the application. This configuration option is very verbose.

  • -d provides a dry-run of the rewriting for workflow validation.

  • -nodeps excludes dependencies from rewriting; only instrument packages within the target package's module.

  • -version displays the current version of the Contrast agent.

  • -agentDir string location of agent package on disk (default “/Users/ehdens/contrast/i13n”).

  • -d dry run of rewriting (workflow validation).

  • -dataflow  enable dataflow rewrites (assess) (default true).

  • -ecu  enable ecu rewrites (default true).

  • -noLines disable line comment directives (default true).

  • -nodeps  only instrumented packages within the target package’s module.

  • -save save rewritten source files after compilation.

  • -skip skip rewrite and rebuild, use with -wd to specify the location to build from.

Note

Use -h to get help.