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.*"]))
The following is a list of all available configuration options.
function | Value |
| Disables the agent at a local level. (defaults to |
| Sets the name of the environment to be used in the dashboard. (defaults to |
| An array of regular expressions to strip key names (see defaults) |
| An array of regular expressions used for value stripping (see defaults) |
| 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.
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.
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 mainimport ("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 transportvar 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.