telemetry

package
v0.0.0-...-05ee0c8 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package telemetry provides functions for application tracing. Primarily used while debugging.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrUnsupportedProvider is the error given when a trace provider cannot be found for the provided
	// configuration.
	ErrUnsupportedProvider = errors.New("unsupported trace provider")

	// Discard is a sentinel error that is used to discard any current traces.
	// nolint: revive,stylecheck
	Discard = errors.New("discard")
)
View Source
var Flags = flag.Flags{
	&flag.String{
		Name:        "telemetry-url",
		Usage:       "URL to configure opentelemetry. See documentation for all configuration options.",
		Destination: &telemetryURL,
		EnvVar:      "TELEMETRY_URL",
		Value:       "noop://",
		Hidden:      true,
	},
}

Flags contains all command-line flags that can be used to configure telemetry.

Functions

func Extract

func Extract(ctx context.Context) map[string]string

Extract the tracer headers from the provided context as a map[string]string.

func Inject

func Inject(ctx context.Context, m map[string]string) context.Context

Inject the tracer headers from the provided map into a new context.Context.

func NewTracer

func NewTracer(ctx context.Context) (io.Closer, error)

NewTracer constructs a tracer based on the telemetry flag and returns an io.Closer implementation used to stop the tracer. Tracers are configured via a URL where the scheme denotes the tracer to use. Currently noop, log, zipkin and jaeger are supported.

func WithinSpan

func WithinSpan(ctx context.Context, name string, fn func(ctx context.Context, span Span) error) error

WithinSpan wraps fn with a Span.

Types

type Span

type Span struct {
	trace.Span
}

Span is a wrapper for trace.Span.

func (Span) SetAttributes

func (s Span) SetAttributes(m map[string]interface{})

SetAttributes is a wrapper around trace.Span.SetAttributes that uses an interface map to set attributes.

type TracedMutex

type TracedMutex struct {
	// contains filtered or unexported fields
}

The TracedMutex type is a wrapper around a sync.Mutex that creates a span when Lock is called.

func NewTracedMutex

func NewTracedMutex() *TracedMutex

NewTracedMutex returns a new TracedMutex initialised with a sync.Mutex.

func (*TracedMutex) Lock

func (t *TracedMutex) Lock(ctx context.Context)

Lock the mutex.

func (*TracedMutex) Unlock

func (t *TracedMutex) Unlock()

Unlock the mutex.

Jump to

Keyboard shortcuts

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