dd-trace-go.v1: gopkg.in/DataDog/dd-trace-go.v1/contrib/hashicorp/vault Index | Examples | Files

package vault

import "gopkg.in/DataDog/dd-trace-go.v1/contrib/hashicorp/vault"

Package vault contains functions to construct or augment an http.Client that will integrate with the github.com/hashicorp/vault/api and collect traces to send to Datadog.

The easiest way to use this package is to create an http.Client with NewHTTPClient, and put it in the Vault API config that is passed to the

If you are already using your own http.Client with the Vault API, you can use the WrapHTTPClient function to wrap the client with the tracer code. Your http.Client will continue to work as before, but will also capture traces.

Index

Examples

Package Files

option.go vault.go

func NewHTTPClient Uses

func NewHTTPClient(opts ...Option) *http.Client

NewHTTPClient returns an http.Client for use in the Vault API config Client. A set of options can be passed in for further configuration.

This is the most basic way to enable tracing with Vault.

Code:

c, err := api.NewClient(&api.Config{
    HttpClient: vaulttrace.NewHTTPClient(),
    Address:    "http://vault.mydomain.com:8200",
})
if err != nil {
    log.Fatalf("Failed to create Vault client: %s\n", err)
}
// This call wil be traced
c.Logical().Read("/secret/key")

NewHTTPClient can be called with additional options for further configuration.

Code:

c, err := api.NewClient(&api.Config{
    HttpClient: vaulttrace.NewHTTPClient(
        vaulttrace.WithServiceName("my.vault"),
        vaulttrace.WithAnalytics(true),
    ),
    Address: "http://vault.mydomain.com:8200",
})
if err != nil {
    log.Fatalf("Failed to create Vault client: %s\n", err)
}
// This call wil be traced
c.Logical().Read("/secret/key")

func WrapHTTPClient Uses

func WrapHTTPClient(c *http.Client, opts ...Option) *http.Client

WrapHTTPClient takes an existing http.Client and wraps the underlying transport with tracing.

If you already have an http.Client that you're using, you can add tracing to it with WrapHTTPClient.

Code:

// We use a custom *http.Client to talk to Vault.
c := &http.Client{
    CheckRedirect: func(r *http.Request, via []*http.Request) error {
        if len(via) > 5 {
            return fmt.Errorf("Won't perform more that 5 redirects.")
        }
        return nil
    },
}
client, err := api.NewClient(&api.Config{
    HttpClient: vaulttrace.WrapHTTPClient(c),
    Address:    "http://vault.mydomain.com:8200",
})
if err != nil {
    log.Fatalf("Failed to create Vault client: %s\n", err)
}

// This call wil be traced
client.Logical().Read("/secret/key")

WrapHTTPClient can be called with additional options to configure the integration.

Code:

// We use a custom *http.Client to talk to Vault.
c := &http.Client{
    CheckRedirect: func(r *http.Request, via []*http.Request) error {
        if len(via) > 5 {
            return fmt.Errorf("Won't perform more that 5 redirects.")
        }
        return nil
    },
}
client, err := api.NewClient(&api.Config{
    HttpClient: vaulttrace.WrapHTTPClient(
        c,
        vaulttrace.WithServiceName("my.vault"),
        vaulttrace.WithAnalytics(true),
    ),
    Address: "http://vault.mydomain.com:8200",
})
if err != nil {
    log.Fatalf("Failed to create Vault client: %s\n", err)
}
// This call wil be traced
client.Logical().Read("/secret/key")

type Option Uses

type Option func(*config)

Option can be passed to NewHTTPClient and WrapHTTPClient to configure the integration.

func WithAnalytics Uses

func WithAnalytics(on bool) Option

WithAnalytics enables or disables Trace Analytics for all started spans.

func WithAnalyticsRate Uses

func WithAnalyticsRate(rate float64) Option

WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.

func WithServiceName Uses

func WithServiceName(name string) Option

WithServiceName sets the given service name for the http.Client.

Package vault imports 10 packages (graph). Updated 2020-08-06. Refresh now. Tools for package owners.