trace

package
v0.0.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 trace 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 trace 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 trace 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
}

Provider is the interface that wraps the basic methods of a trace provider. If missconfigured or disabled, the provider will return a noop tracer

func NewProvider

func NewProvider(opts ...Option) (Provider, error)
 NewProvider creates a new trace provider with the given options
 The trace 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