otel

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GlobalTracer

func GlobalTracer() trace.Tracer

GlobalTracer returns the global tracer. If Setup wasn't called, the function returns a default tracer.

This function isn't thread safe which means that if it's called at the same time that Setup is creating the global tracer, this result in a race condition. Besides that, this isn't secured since the access to the tracer doesn't need to be thread locked.

func MarshallContext

func MarshallContext(ctx context.Context) ([]byte, error)

MarshallContext encodes the context to a JSON object. Assumes that there is an initialized context map propagator.

func Setup added in v1.1.0

func Setup(opt *Options) error

Setup initializes the opentelemetry sdk and creates a global tracer which can be access with GlobalTracer. Does nothing on future calls.

func StartSpan added in v1.2.0

func StartSpan(
	ctx context.Context,
	name string,
	fn Operation,
	opts ...trace.SpanStartOption,
) (err error)

StartSpan creates a span arround a given operation. The function automatically closes the span, records the error returned by Operation (if any) and rereturns it. Span.End has no effect if called more than one time.

func UnmarshallContext

func UnmarshallContext(
	ctx context.Context,
	obj []byte,
) (context.Context, error)

UnmarshallContext decodes the JSON object into the given context. Assumes that there is an initialized context map propagator.

Types

type Operation added in v0.2.0

type Operation func(ctx context.Context, span trace.Span) error

Operation represents the execution wrapped by a span. The ctx parameter contains the context tied to the span. The returned error will be recorded in span and re-returned by StartSpan.

type Options

type Options struct {
	ServiceName string
	TracerName  string

	// CollectorAddr contains the grpc collector
	// address in the form <ip/domain>:<port>.
	CollectorAddr string

	// DialDeadline is the max time to dial
	// a connection with the collector.
	DialDeadline time.Duration
}

Options contains all basic elements to establish a connection with an OpenTelemetry cluster.

Jump to

Keyboard shortcuts

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