otelx

package
v0.0.28 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2023 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigSchemaID = "clinia://tracing-config"

Variables

View Source
var ConfigSchema string

Functions

func AddConfigSchema

func AddConfigSchema(c interface {
	AddResource(url string, r io.Reader) error
}) error

AddConfigSchema adds the tracing schema to the compiler. The interface is specified instead of `jsonschema.Compiler` to allow the use of any jsonschema library fork or version.

func End

func End(span trace.Span, err *error)

End finishes span, and automatically sets the error state if *err is not nil or during panicking.

Usage:

func Divide(ctx context.Context, numerator, denominator int) (ratio int, err error) {
	ctx, span := tracer.Start(ctx, "my-operation")
	defer otelx.End(span, &err)
	if denominator == 0 {
		return 0, errors.New("cannot divide by zero")
	}
	return numerator / denominator, nil
}

func SetupJaeger

func SetupJaeger(t *Tracer, tracerName string, c *Config) (trace.Tracer, error)

Optionally, Config.Providers.Jaeger.LocalAgentAddress can be set. NOTE: If Config.Providers.Jaeger.Sampling.ServerURL is not specfied, AlwaysSample is used.

func SetupOTLP

func SetupOTLP(t *Tracer, tracerName string, c *Config) (trace.Tracer, error)

func SetupStdout added in v0.0.4

func SetupStdout(t *Tracer, tracerName string, c *Config) (trace.Tracer, error)

func StringAttrs

func StringAttrs(attrs map[string]string) []attribute.KeyValue

func WithSpan

func WithSpan(ctx context.Context, name string, f func(context.Context) error, opts ...trace.SpanStartOption) (err error)

WithSpan wraps execution of f in a span identified by name.

If f returns an error or panics, the span status will be set to the error state. The error (or panic) will be propagated unmodified.

f will be wrapped in a child span by default. To make a new root span instead, pass the trace.WithNewRoot() option.

Types

type Config

type Config struct {
	ServiceName        string               `json:"service_name"`
	Provider           string               `json:"provider"`
	Providers          ProvidersConfig      `json:"providers"`
	ResourceAttributes []attribute.KeyValue `json:"resource_attributes"`
}

type JaegerConfig

type JaegerConfig struct {
	LocalAgentAddress string         `json:"local_agent_address"`
	Sampling          JaegerSampling `json:"sampling"`
}

type JaegerSampling

type JaegerSampling struct {
	ServerURL    string  `json:"server_url"`
	TraceIdRatio float64 `json:"trace_id_ratio"`
}

type OTLPConfig

type OTLPConfig struct {
	Protocol  string       `json:"protocol"`
	ServerURL string       `json:"server_url"`
	Insecure  bool         `json:"insecure"`
	Sampling  OTLPSampling `json:"sampling"`
}

type OTLPSampling

type OTLPSampling struct {
	SamplingRatio float64 `json:"sampling_ratio"`
}

type ProvidersConfig

type ProvidersConfig struct {
	Jaeger JaegerConfig `json:"jaeger"`
	OTLP   OTLPConfig   `json:"otlp"`
	Stdout StdoutConfig `json:"stdout"`
}

type StdoutConfig added in v0.0.4

type StdoutConfig struct {
	Pretty bool `json:"pretty"`
}

type Tracer

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

func New

func New(name string, l *logrusx.Logger, c *Config) (*Tracer, error)

Creates a new tracer. If name is empty, a default tracer name is used instead. See: https://godocs.io/go.opentelemetry.io/otel/sdk/trace#TracerProvider.Tracer

func NewNoop

func NewNoop(_ *logrusx.Logger, c *Config) *Tracer

Creates a new no-op tracer.

func (*Tracer) IsLoaded

func (t *Tracer) IsLoaded() bool

IsLoaded returns true if the tracer has been loaded.

func (*Tracer) Provider

func (t *Tracer) Provider() trace.TracerProvider

Provider returns a TracerProvider which in turn yieds this tracer unmodified.

func (*Tracer) Tracer

func (t *Tracer) Tracer() trace.Tracer

Tracer returns the underlying OpenTelemetry tracer.

func (*Tracer) WithOTLP

func (t *Tracer) WithOTLP(other trace.Tracer) *Tracer

WithOTLP returns a new tracer with the underlying OpenTelemetry Tracer replaced.

Jump to

Keyboard shortcuts

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