elastic

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2018 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

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

Example (V3)

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.

package main

import (
	"context"

	elastictrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/olivere/elastic"
	"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"

	elasticv3 "gopkg.in/olivere/elastic.v3"
)

func main() {
	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()
}
Output:

Example (V5)

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

package main

import (
	"context"

	elastictrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/olivere/elastic"
	"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"

	elasticv5 "gopkg.in/olivere/elastic.v5"
)

func main() {
	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()
}
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 func(*clientConfig)

ClientOption represents an option that can be used when creating a client.

func WithServiceName

func WithServiceName(name string) ClientOption

WithServiceName sets the given service name for the client.

func WithTransport

func WithTransport(t *http.Transport) 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