Documentation ¶
Index ¶
Constants ¶
const ( SPAN_STATUS_ERROR = codes.Error SPAN_STATUS_UNSET = codes.Unset SPAN_STATUS_OK = codes.Ok )
const ( NOOP_PROVIDER = "noop" OTEL_PROVIDER = "otel" )
Variables ¶
This section is empty.
Functions ¶
func NewHTTPHandler ¶ added in v0.0.4
NewHTTPHandler wraps the provided http.Handler with one that starts a span and injects the span context into the outbound request headers. You need to initialize the TracerProvider first since it utilizes the underlying TracerProvider and propagators. It also utilizes a spanNameFormatter to format the span name r.Method + " " + r.URL.Path.
func NewHTTPTransport ¶ added in v0.0.4
func NewHTTPTransport(base http.RoundTripper) http.RoundTripper
NewHTTPTransport wraps the provided http.RoundTripper with one that starts a span and injects the span context into the outbound request headers.
Types ¶
type Logger ¶ added in v0.0.2
type Logger interface { Info(args ...interface{}) Error(args ...interface{}) }
Logger represents the internal library logger used for error and info messages
type Option ¶ added in v0.0.2
type Option interface {
// contains filtered or unexported methods
}
func WithConfig ¶ added in v0.0.2
func WithConfig(cfg *config.OpenTelemetry) Option
WithConfig sets the configuration options for the tracer provider
Example
config := &config.OpenTelemetry{ Enabled: true, Exporter: "grpc", Endpoint: "localhost:4317", } provider, err := trace.NewProvider(trace.WithConfig(config)) if err != nil { panic(err) }
func WithContext ¶ added in v0.0.2
WithContext sets the context for the tracer provider
Example
ctx := context.Background() provider, err := trace.NewProvider(trace.WithContext(ctx)) if err != nil { panic(err) }
func WithLogger ¶ added in v0.0.2
WithLogger sets the logger for the tracer provider This is used to log errors and info messages for underlying operations
Example
logger := logrus.New().WithField("component", "trace") provider, err := trace.NewProvider(trace.WithLogger(logger)) if err != nil { panic(err) }
type Provider ¶
type Provider interface { // Shutdown execute the underlying exporter shutdown function Shutdown(context.Context) error // Tracer returns a tracer with pre-configured name. It's used to create spans. Tracer() Tracer // Type returns the type of the provider, it can be either "noop" or "otel" Type() string }
Provider is the interface that wraps the basic methods of a tracer provider. If missconfigured or disabled, the provider will return a noop tracer
func NewProvider ¶
NewProvider creates a new tracer provider with the given options The tracer provider is responsible for creating spans and sending them to the exporter Example provider, err := trace.NewProvider( trace.WithContext(context.Background()), trace.WithConfig(&config.OpenTelemetry{ Enabled: true, Exporter: "grpc", Endpoint: "localhost:4317", }), trace.WithLogger(logrus.New().WithField("component", "tyk")), ) if err != nil { panic(err) }