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 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 ¶
Option applies options to a configuration.
func WithAttributes ¶
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.