trace

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: MPL-2.0 Imports: 17 Imported by: 2

Documentation

Index

Constants

View Source
const (
	SPAN_STATUS_ERROR = codes.Error
	SPAN_STATUS_UNSET = codes.Unset
	SPAN_STATUS_OK    = codes.Ok
)
View Source
const (
	NOOP_PROVIDER = "noop"
	OTEL_PROVIDER = "otel"
)

Variables

This section is empty.

Functions

func NewHTTPHandler added in v0.0.4

func NewHTTPHandler(name string, handler http.Handler, tp Provider) http.Handler

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.

func SpanFromContext added in v0.0.4

func SpanFromContext(ctx context.Context) trace.Span

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

func WithContext(ctx context.Context) Option
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

func WithLogger(logger Logger) Option
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

func NewProvider(opts ...Option) (Provider, error)
 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)
	}

type Tracer

type Tracer = oteltrace.Tracer

Jump to

Keyboard shortcuts

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