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

package elastic

import "gopkg.in/DataDog/dd-trace-go.v1/contrib/olivere/elastic"

Package elastic provides functions to trace the gopkg.in/olivere/elastic.v{3,5} packages.

To trace elastic.v3 you create a TracedHTTPClient in the same way but all requests must use the DoC() call to pass the request context.

Code:

tc := elastictrace.NewHTTPClient(elastictrace.WithServiceName("my-es-service"))
client, _ := elasticv3.NewClient(
    elasticv3.SetURL("http://127.0.0.1:9200"),
    elasticv3.SetHttpClient(tc),
)

// Spans are emitted for all
client.Index().
    Index("twitter").Type("tweet").Index("1").
    BodyString(`{"user": "test", "message": "hello"}`).
    DoC(context.Background())

// Use a context to pass information down the call chain
root, ctx := tracer.StartSpanFromContext(context.Background(), "parent.request",
    tracer.ServiceName("web"),
    tracer.ResourceName("/tweet/1"),
)
client.Get().
    Index("twitter").Type("tweet").Index("1").
    DoC(ctx)
root.Finish()

To start tracing elastic.v5 requests, create a new TracedHTTPClient that you will use when initializing the elastic.Client.

Code:

tc := elastictrace.NewHTTPClient(elastictrace.WithServiceName("my-es-service"))
client, _ := elasticv5.NewClient(
    elasticv5.SetURL("http://127.0.0.1:9200"),
    elasticv5.SetHttpClient(tc),
)

// Spans are emitted for all
client.Index().
    Index("twitter").Type("tweet").Index("1").
    BodyString(`{"user": "test", "message": "hello"}`).
    Do(context.Background())

// Use a context to pass information down the call chain
root, ctx := tracer.StartSpanFromContext(context.Background(), "parent.request",
    tracer.ServiceName("web"),
    tracer.ResourceName("/tweet/1"),
)
client.Get().
    Index("twitter").Type("tweet").Index("1").
    Do(ctx)
root.Finish()

Index

Examples

Package Files

elastictrace.go option.go

func NewHTTPClient Uses

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

NewHTTPClient returns a new http.Client which traces requests under the given service name.

type ClientOption Uses

type ClientOption func(*clientConfig)

ClientOption represents an option that can be used when creating 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 WithResourceNamer Uses

func WithResourceNamer(namer func(url, method string) string) ClientOption

WithResourceNamer specifies a quantizing function which will be used to obtain a resource name for a given ElasticSearch request, using the request's URL and method. Note that the default quantizer obfuscates IDs and indexes and by replacing it, sensitive data could possibly be exposed, unless the new quantizer specifically takes care of that.

func WithServiceName Uses

func WithServiceName(name string) ClientOption

WithServiceName sets the given service name for the client.

func WithTransport Uses

func WithTransport(t *http.Transport) ClientOption

WithTransport sets the given transport as an http.Transport for the client.

Package elastic imports 14 packages (graph). Updated 2020-02-14. Refresh now. Tools for package owners.