Version: v1.42.1 Latest Latest

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

Go to latest
Published: Sep 26, 2022 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 14 Imported by: 0



Package elastic provides functions to trace the github.com/elastic/go-elasticsearch packages.

Example (V7)
package main

import (

	elasticsearch "github.com/elastic/go-elasticsearch/v7"

	elastictrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/elastic/go-elasticsearch.v6"

func main() {
	cfg := elasticsearch.Config{
		Transport: elastictrace.NewRoundTripper(elastictrace.WithServiceName("my-es-service")),
		Addresses: []string{
	es, err := elasticsearch.NewClient(cfg)
	if err != nil {
		log.Fatalf("Error creating the client: %s", err)

	_, err = esapi.IndexRequest{
		Index:        "twitter",
		DocumentID:   "1",
		DocumentType: "tweet",
		Body:         strings.NewReader(`{"user": "test", "message": "hello"}`),
	}.Do(context.Background(), es)

	if err != nil {
		log.Fatalf("Error creating index: %s", err)

	// Use a context to pass information down the call chain
	root, ctx := tracer.StartSpanFromContext(context.Background(), "parent.request",

	_, err = esapi.GetRequest{
		Index:        "twitter",
		DocumentID:   "1",
		DocumentType: "tweet",
	}.Do(ctx, es)

	if err != nil {
		log.Fatalf("Error getting index: %s", err)






This section is empty.


This section is empty.


func NewRoundTripper

func NewRoundTripper(opts ...ClientOption) http.RoundTripper

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


type ClientOption

type ClientOption func(*clientConfig)

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

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

func WithServiceName(name string) ClientOption

WithServiceName sets the given service name for the client.

func WithTransport

func WithTransport(t http.RoundTripper) ClientOption

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