consul

package
v1.999.0-beta.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2024 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 2 Imported by: 0

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client = v2.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 = v2.ClientOption

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 WithConfig added in v1.52.0

func WithConfig(config *consul.Config) ClientOption

WithConfig extracts the config information for the client to be tagged

func WithServiceName

func WithServiceName(name string) ClientOption

WithServiceName sets the given service name for the client.

type KV

type KV = v2.KV

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL