otelx

package
v0.0.66 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const MeterConfigSchemaID = "clinia://meter-config"
View Source
const TracerConfigSchemaID = "clinia://tracer-config"

Variables

View Source
var MeterConfigSchema string
View Source
var TracerConfigSchema string

Functions

func AddMeterConfigSchema added in v0.0.36

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

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

func AddTracerConfigSchema added in v0.0.33

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

AddTracerConfigSchema adds the tracer 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 NewMeterProvider added in v0.0.63

func NewMeterProvider(l *logrusx.Logger, c *MeterConfig) (metric.MeterProvider, error)

NewMeterProvider creates a new meter provider based on the configuration.

func SetupJaegerTracer added in v0.0.33

func SetupJaegerTracer(tracerName string, c *TracerConfig) (trace.Tracer, propagation.TextMapPropagator, error)

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

func SetupOTLPMeterProvider added in v0.0.63

func SetupOTLPMeterProvider(meterName string, c *MeterConfig) (metric.MeterProvider, error)

func SetupOTLPTracer added in v0.0.33

func SetupOTLPTracer(tracerName string, c *TracerConfig) (trace.Tracer, propagation.TextMapPropagator, error)

func SetupPrometheusMeterProvider added in v0.0.63

func SetupPrometheusMeterProvider(meterName string, c *MeterConfig) (metric.MeterProvider, error)

func SetupStdoutMeterProvider added in v0.0.63

func SetupStdoutMeterProvider(meterName string, c *MeterConfig) (metric.MeterProvider, error)

func SetupStdoutTracer added in v0.0.33

func SetupStdoutTracer(tracerName string, c *TracerConfig) (trace.Tracer, propagation.TextMapPropagator, 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 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 MeterConfig added in v0.0.36

type MeterConfig struct {
	ServiceName        string               `json:"service_name"`
	Name               string               `json:"name"`
	Provider           string               `json:"provider"`
	Providers          MeterProvidersConfig `json:"providers,omitempty"`
	ResourceAttributes []attribute.KeyValue `json:"resource_attributes"`
}

type MeterProvidersConfig added in v0.0.36

type MeterProvidersConfig struct {
	OTLP OTLPMeterConfig `json:"otlp"`
}

type OTLPMeterConfig added in v0.0.36

type OTLPMeterConfig struct {
	Protocol  string `json:"protocol"`
	ServerURL string `json:"server_url"`
	Insecure  bool   `json:"insecure"`
}

type OTLPSampling

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

type OTLPTracerConfig added in v0.0.36

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

type Otel added in v0.0.33

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

func New

func New(l *logrusx.Logger, opts ...OtelOption) (*Otel, error)

Creates opentelemetry tools (meter and tracer). Leaving

func NewNoop

func NewNoop() *Otel

Creates a new no-op tracer and meter.

func (*Otel) Meter added in v0.0.36

func (o *Otel) Meter(opts ...metric.MeterOption) metric.Meter

func (*Otel) MeterProvider added in v0.0.63

func (o *Otel) MeterProvider() metric.MeterProvider

MeterProvider returns the underlying OpenTelemetry meter provider.

func (*Otel) Tracer added in v0.0.33

func (o *Otel) Tracer() *Tracer

Tracer returns the underlying OpenTelemetry tracer.

type OtelOption added in v0.0.33

type OtelOption func(*OtelOptions)

func WithMeterConfig added in v0.0.63

func WithMeterConfig(config *MeterConfig) OtelOption

func WithTracer added in v0.0.33

func WithTracer(config *TracerConfig) OtelOption

type OtelOptions added in v0.0.33

type OtelOptions struct {
	TracerConfig *TracerConfig
	MeterConfig  *MeterConfig
}

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 NewNoopTracer added in v0.0.33

func NewNoopTracer(tracerName string) *Tracer

func (*Tracer) Extract added in v0.0.33

func (t *Tracer) Extract(ctx context.Context, carrier propagation.TextMapCarrier) context.Context

Extract reads tracecontext from the carrier into a returned Context. If the extracted tracecontext is invalid, the passed ctx will be returned directly instead.

func (*Tracer) Inject added in v0.0.33

func (t *Tracer) Inject(ctx context.Context, carrier propagation.TextMapCarrier)

Inject set tracecontext from the Context into the carrier.

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) TextMapPropagator added in v0.0.33

func (t *Tracer) TextMapPropagator() propagation.TextMapPropagator

TextMapPropagator returns the underlying OpenTelemetry textMapPropagator.

func (*Tracer) Tracer

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

Tracer returns the underlying OpenTelemetry tracer.

type TracerConfig added in v0.0.33

type TracerConfig struct {
	ServiceName        string                `json:"service_name"`
	Name               string                `json:"name"`
	Provider           string                `json:"provider"`
	Providers          TracerProvidersConfig `json:"tracer_providers"`
	ResourceAttributes []attribute.KeyValue  `json:"resource_attributes"`
	SpanLimits         *sdktrace.SpanLimits  `json:"span_limits,omitempty"`
}

type TracerProvidersConfig added in v0.0.33

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

Directories

Path Synopsis
instrumentation
otelhttpx
package otelhttpx provides an http.Handler and functions that are intended to be used to add tracing by wrapping existing handlers (with Handler) and routes WithRouteTag.
package otelhttpx provides an http.Handler and functions that are intended to be used to add tracing by wrapping existing handlers (with Handler) and routes WithRouteTag.
otelhttpx/filters
Package filters provides a set of filters useful with the otelhttpx.WithFilter() option to control which inbound requests are traced.
Package filters provides a set of filters useful with the otelhttpx.WithFilter() option to control which inbound requests are traced.

Jump to

Keyboard shortcuts

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