Documentation ¶
Overview ¶
Example ¶
Here's an example illustrating a simple use case for interacting with consul with tracing enabled.
// 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 ¶
- type Client
- type ClientOption
- type KV
- func (k *KV) Acquire(p *consul.KVPair, q *consul.WriteOptions) (bool, *consul.WriteMeta, error)
- func (k *KV) CAS(p *consul.KVPair, q *consul.WriteOptions) (bool, *consul.WriteMeta, error)
- func (k *KV) Delete(key string, w *consul.WriteOptions) (*consul.WriteMeta, error)
- func (k *KV) DeleteCAS(p *consul.KVPair, q *consul.WriteOptions) (bool, *consul.WriteMeta, error)
- func (k *KV) DeleteTree(prefix string, w *consul.WriteOptions) (*consul.WriteMeta, error)
- func (k *KV) Get(key string, q *consul.QueryOptions) (*consul.KVPair, *consul.QueryMeta, error)
- func (k *KV) Keys(prefix, separator string, q *consul.QueryOptions) ([]string, *consul.QueryMeta, error)
- func (k *KV) List(prefix string, q *consul.QueryOptions) ([]*consul.KVPair, *consul.QueryMeta, error)
- func (k *KV) Put(p *consul.KVPair, q *consul.WriteOptions) (*consul.WriteMeta, error)
- func (k *KV) Release(p *consul.KVPair, q *consul.WriteOptions) (bool, *consul.WriteMeta, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client wraps the regular *consul.Client and augments it with tracing. Use NewClient to initialize it.
func NewClient ¶
func NewClient(config *consul.Config, opts ...ClientOption) (*Client, error)
NewClient returns a traced Consul client.
func WrapClient ¶
func WrapClient(c *consul.Client, opts ...ClientOption) *Client
WrapClient wraps a given consul.Client with a tracer under the given service name.
type ClientOption ¶
type ClientOption func(*clientConfig)
ClientOption represents an option that can be used to create or wrap a client.
func WithAnalytics ¶
func WithAnalytics(on bool) ClientOption
WithAnalytics enables Trace Analytics for all started spans.
func WithAnalyticsRate ¶
func WithAnalyticsRate(rate float64) ClientOption
WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.
func WithServiceName ¶
func WithServiceName(name string) ClientOption
WithServiceName sets the given service name for the client.
type KV ¶
A KV is used to trace requests to Consul's KV.
func (*KV) Acquire ¶
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 ¶
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 ¶
Delete is used to delete a single key.
func (*KV) DeleteCAS ¶
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 ¶
DeleteTree is used to delete all keys under a prefix.
func (*KV) Get ¶
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 ¶
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 ¶
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 ¶
Put is used to write a new value. Only the Key, Flags and Value is respected.