splunkelastic

package module
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

README

Splunk instrumentation for gopkg.in/olivere/elastic

This package provides OpenTelemetry instrumentation for the */olivere/elastic packages:

Elastic version Package URL
7.0 github.com/olivere/elastic/v7
6.0 github.com/olivere/elastic
5.0 gopkg.in/olivere/elastic.v5
3.0 gopkg.in/olivere/elastic.v3

Getting Started

This package provides an http.Transport that can be used with gopkg.in/olivere/elastic to instrument requests that package makes. See example_test.go for more information.

Documentation

Overview

Package splunkelastic provides OpenTelemetry instrumentation for the gopkg.in/olivere/elastic package.

Example
package main

import (
	"context"
	"net/http"

	elasticv7 "github.com/olivere/elastic/v7"

	"github.com/signalfx/splunk-otel-go/instrumentation/gopkg.in/olivere/elastic/splunkelastic"
)

func main() {
	// Wrap the HTTP Transport used by the client to communicate with the
	// Elasticsearch cluster so all requests made are included in traces.
	client, err := elasticv7.NewClient(
		elasticv7.SetURL("http://127.0.0.1:9200"),
		elasticv7.SetHttpClient(&http.Client{
			Transport: splunkelastic.WrapRoundTripper(http.DefaultTransport),
		}),
	)
	if err != nil {
		// Handle error.
		panic(err)
	}

	// Spans are emitted for all operations the client performs against the
	// Elasticsearch cluster.
	_, err = client.Index().
		Index("twitter").
		Index("1").
		BodyString(`{"user": "test", "message": "hello"}`).
		// If a context that contains an span is passed here it will be used
		// as the parent span for the performed operations.
		Do(context.Background())
	if err != nil {
		// Handle error.
		panic(err)
	}
}
Output:

Example (V3)
package main

import (
	"context"
	"net/http"

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

	"github.com/signalfx/splunk-otel-go/instrumentation/gopkg.in/olivere/elastic/splunkelastic"
)

func main() {
	// Wrap the HTTP Transport used by the client to communicate with the
	// Elasticsearch cluster so all requests made are included in traces.
	client, err := elasticv3.NewClient(
		elasticv3.SetURL("http://127.0.0.1:9200"),
		elasticv3.SetHttpClient(&http.Client{
			Transport: splunkelastic.WrapRoundTripper(http.DefaultTransport),
		}),
	)
	if err != nil {
		// Handle error.
		panic(err)
	}

	// Spans are emitted for all operations the client performs against the
	// Elasticsearch cluster.
	_, err = client.Index().
		Index("twitter").
		Type("tweet").
		Index("1").
		BodyString(`{"user": "test", "message": "hello"}`).
		// Be sure to use DoC to propagate a trace with a context that
		// contains a parent span.
		DoC(context.Background())
	if err != nil {
		// Handle error.
		panic(err)
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Version added in v1.6.0

func Version() string

Version returns the version of splunkelastic.

func WrapRoundTripper

func WrapRoundTripper(rt http.RoundTripper, opts ...Option) http.RoundTripper

WrapRoundTripper returns an http.RoundTripper that wraps the passed rt. All requests handled by the returned http.RoundTripper will be traced with the assuption they are being made to an Elasticsearch server using the gopkg.in/olivere/elastic package.

If rt is nil, the http.DefaultTransport will be used instead.

Types

type Option

type Option interface {
	internal.Option
}

Option applies options to a configuration.

func WithAttributes

func WithAttributes(attr []attribute.KeyValue) Option

WithAttributes returns an Option that appends attr to the attributes set for every span created with this instrumentation library.

func WithPropagator

func WithPropagator(p propagation.TextMapPropagator) Option

WithPropagator returns an Option that sets p as the TextMapPropagator used when propagating a span context.

func WithTracerProvider

func WithTracerProvider(tp trace.TracerProvider) Option

WithTracerProvider returns an Option that sets the TracerProvider used with this instrumentation library.

Directories

Path Synopsis
tokenize.go generator.
tokenize.go generator.
test module

Jump to

Keyboard shortcuts

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