elastic

package module
v0.0.0-...-7ebff8f Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: Apache-2.0, BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package elastic provides functions to trace the gopkg.in/olivere/elastic.v5 packages.

Example

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

tc := elastictrace.NewHTTPClient(elastictrace.WithService("my-es-service"))
client, _ := elastic.NewClient(
	elastic.SetURL("http://127.0.0.1:9200"),
	elastic.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()
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHTTPClient

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

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

Types

type ClientOption

type ClientOption interface {
	// contains filtered or unexported methods
}

ClientOption describes options for the Elastic integration.

type ClientOptionFn

type ClientOptionFn func(config *clientConfig)

ClientOptionFn represents options applicable to NewHTTPClient.

func WithAnalytics

func WithAnalytics(on bool) ClientOptionFn

WithAnalytics enables Trace Analytics for all started spans.

func WithAnalyticsRate

func WithAnalyticsRate(rate float64) ClientOptionFn

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

func WithResourceNamer

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

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 WithService

func WithService(name string) ClientOptionFn

WithService sets the given service name for the client.

func WithTransport

func WithTransport(t *http.Transport) ClientOptionFn

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

Jump to

Keyboard shortcuts

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