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

package consul

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

Here's an example illustrating a simple use case for interacting with consul with tracing enabled.

Code:

// Get a new Consul client
client, err := NewClient(consul.DefaultConfig(), WithServiceName("consul.example"))
if err != nil {
    log.Fatal(err)
}

// Optionally, create a new root span
root, ctx := tracer.StartSpanFromContext(context.Background(), "root_span",
    tracer.SpanType(ext.SpanTypeConsul),
    tracer.ServiceName("example"),
)
defer root.Finish()
client = client.WithContext(ctx)

// Get a handle to the KV API
kv := client.KV()

// PUT a new KV pair
p := &consul.KVPair{Key: "test", Value: []byte("1000")}
_, err = kv.Put(p, nil)
if err != nil {
    log.Fatal(err)
}

// Lookup the pair
pair, _, err := kv.Get("test", nil)
if err != nil {
    log.Fatal(err)
}
fmt.Printf("%v: %s\n", pair.Key, pair.Value)

Output:

test: 1000

Index

Examples

Package Files

consul.go option.go

type Client Uses

type Client struct {
    *consul.Client
    // contains filtered or unexported fields
}

Client wraps the regular *consul.Client and augments it with tracing. Use NewClient to initialize it.

func NewClient Uses

func NewClient(config *consul.Config, opts ...ClientOption) (*Client, error)

NewClient returns a traced Consul client.

func WrapClient Uses

func WrapClient(c *consul.Client, opts ...ClientOption) *Client

WrapClient wraps a given consul.Client with a tracer under the given service name.

func (*Client) KV Uses

func (c *Client) KV() *KV

KV returns the KV for the Client.

func (*Client) WithContext Uses

func (c *Client) WithContext(ctx context.Context) *Client

WithContext sets a context on a Client. Use it to ensure that emitted spans have the correct parent.

type ClientOption Uses

type ClientOption func(*clientConfig)

ClientOption represents an option that can be used to create or wrap a client.

func WithAnalytics Uses

func WithAnalytics(on bool) ClientOption

WithAnalytics enables Trace Analytics for all started spans.

func WithAnalyticsRate Uses

func WithAnalyticsRate(rate float64) ClientOption

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

func WithServiceName Uses

func WithServiceName(name string) ClientOption

WithServiceName sets the given service name for the client.

type KV Uses

type KV struct {
    *consul.KV
    // contains filtered or unexported fields
}

A KV is used to trace requests to Consul's KV.

func (*KV) Acquire Uses

func (k *KV) Acquire(p *consul.KVPair, q *consul.WriteOptions) (bool, *consul.WriteMeta, error)

Acquire is used for a lock acquisition operation. The Key, Flags, Value and Session are respected. Returns true on success or false on failures.

func (*KV) CAS Uses

func (k *KV) CAS(p *consul.KVPair, q *consul.WriteOptions) (bool, *consul.WriteMeta, error)

CAS is used for a Check-And-Set operation. The Key, ModifyIndex, Flags and Value are respected. Returns true on success or false on failures.

func (*KV) Delete Uses

func (k *KV) Delete(key string, w *consul.WriteOptions) (*consul.WriteMeta, error)

Delete is used to delete a single key.

func (*KV) DeleteCAS Uses

func (k *KV) DeleteCAS(p *consul.KVPair, q *consul.WriteOptions) (bool, *consul.WriteMeta, error)

DeleteCAS is used for a Delete Check-And-Set operation. The Key and ModifyIndex are respected. Returns true on success or false on failures.

func (*KV) DeleteTree Uses

func (k *KV) DeleteTree(prefix string, w *consul.WriteOptions) (*consul.WriteMeta, error)

DeleteTree is used to delete all keys under a prefix.

func (*KV) Get Uses

func (k *KV) Get(key string, q *consul.QueryOptions) (*consul.KVPair, *consul.QueryMeta, error)

Get is used to lookup a single key. The returned pointer to the KVPair will be nil if the key does not exist.

func (*KV) Keys Uses

func (k *KV) Keys(prefix, separator string, q *consul.QueryOptions) ([]string, *consul.QueryMeta, error)

Keys is used to list all the keys under a prefix. Optionally, a separator can be used to limit the responses.

func (*KV) List Uses

func (k *KV) List(prefix string, q *consul.QueryOptions) ([]*consul.KVPair, *consul.QueryMeta, error)

List is used to lookup all keys under a prefix.

func (*KV) Put Uses

func (k *KV) Put(p *consul.KVPair, q *consul.WriteOptions) (*consul.WriteMeta, error)

Put is used to write a new value. Only the Key, Flags and Value is respected.

func (*KV) Release Uses

func (k *KV) Release(p *consul.KVPair, q *consul.WriteOptions) (bool, *consul.WriteMeta, error)

Release is used for a lock release operation. The Key, Flags, Value and Session are respected. Returns true on success or false on failures.

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