Configuration

Configure the Bearer Agent

The Bearer Agent allows you to update the configuration in your code using the bearer.New function along with functional arguments during initialization. For example:

bearer.New(
"app_secretkey",
bearer.WithEnvironment("development"),
bearer.WithSensitiveKeys(["auth.*"])
)

Available Configuration Options

The following is a list of all available configuration options.

function

Value

WithDisabled(disabled bool) Option

Disables the agent at a local level. (defaults to false)

WithEnvironment(rtet string) Option

Sets the name of the environment to be used in the dashboard. (defaults to "development")

WithSensitiveKeys(keys []string) Option

An array of regular expressions to strip key names (see defaults)

WithSensitiveRegexps(res []string) Option

An array of regular expressions used for value stripping (see defaults)

WithLogger(logger io.Writer) Option

Use to enable full logging output by passing a custom io.Writer. By default, the agent will write minimal logs to stderr.

For more on using the WithSensitiveKeys and WithSensitiveRegexps configuration properties see Keep your Data Protected.

Setting an application's environment name

Bearer uses the environment name to differentiate between agents linked to an application in the Bearer Dashboard. By default, the agent will be associated with the "development" environment. To define an environment name, use the WithEnvironment argument function when configuring the agent during initialization.

Using a custom transport

Once initialized, the Bearer Agent will automatically instrument any http clients that take advantage of the Go Standard Library's http.DefaultTransport.

If your application needs support for other clients, you can create your own instrumented transport. This can be done by decorating your custom transport with the Bearer Agent. For example:

package main
import (
"net/http"
"os"
"time"
"github.com/bearer/go-agent/proxy"
bearer "github.com/bearer/go-agent"
)
func main() {
// Step 1: initialize Bearer with secret key.
agent := bearer.New(os.Getenv(bearer.SecretKeyName))
defer agent.Close()
// Step 2: prepare your custom transport
var baseTransport = http.Transport{
TLSHandshakeTimeout: 5 * time.Second,
}
// Step 3: decorate your transport with the Bearer Agent.
transport := agent.Decorate(baseTransport)
// Step 4: Use the client as you normally would.
client := http.Client{Transport: transport}
response, err := client.Get(`https://some.example.com/path`)
// ...
}

This same approach can be used to create multiple configurations and with multiple agents.