otelx

package
v0.0.670 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 29 Imported by: 48

Documentation

Index

Constants

View Source
const ConfigSchemaID = "ory://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 AutoInt added in v0.0.656

func AutoInt[I int | int32 | int64](k string, v I) attribute.KeyValue

func End added in v0.0.524

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 NewHandler

func NewHandler(handler http.Handler, operation string, opts ...otelhttp.Option) http.Handler

NewHandler returns a wrapped otelhttp.NewHandler with our request filters.

func NullInt added in v0.0.656

func NullInt[I int | int32 | int64, V *I | sql.Null[I]](k string, v V) attribute.KeyValue

func NullString added in v0.0.656

func NullString[V *string | sql.Null[string]](k string, v V) attribute.KeyValue

func NullStringer added in v0.0.656

func NullStringer(k string, v fmt.Stringer) attribute.KeyValue

func Nullable added in v0.0.656

func Nullable[V any, VN *V | sql.Null[V], A func(string, V) attribute.KeyValue](a A, k string, v VN) attribute.KeyValue

func SetupJaeger

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

SetupJaeger configures and returns a Jaeger tracer.

The returned tracer will by default attempt to send spans to a local Jaeger agent. Optionally, otelx.JaegerConfig.LocalAgentAddress can be set to specify a different target.

By default, unless a parent sampler has taken a sampling decision, every span is sampled. otelx.JaegerSampling.TraceIdRatio may be used to customize the sampling probability, optionally alongside otelx.JaegerSampling.ServerURL to consult a remote server for the sampling strategy to be used.

func SetupOTLP added in v0.0.381

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

func SetupZipkin added in v0.0.381

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

func StringAttrs

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

func TraceHandler added in v0.0.404

func TraceHandler(h http.Handler, opts ...otelhttp.Option) http.Handler

TraceHandler wraps otelx.NewHandler, passing the URL path as the span name.

func WithSpan added in v0.0.523

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"`
	DeploymentEnvironment string          `json:"deployment_environment"`
	Provider              string          `json:"provider"`
	Providers             ProvidersConfig `json:"providers"`
}

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

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

type OTLPSampling added in v0.0.381

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

type ProvidersConfig

type ProvidersConfig struct {
	Jaeger JaegerConfig `json:"jaeger"`
	Zipkin ZipkinConfig `json:"zipkin"`
	OTLP   OTLPConfig   `json:"otlp"`
}

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

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

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

func (*Tracer) Tracer

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

Tracer returns the underlying OpenTelemetry tracer.

func (*Tracer) WithOTLP added in v0.0.506

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

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

type ZipkinConfig added in v0.0.381

type ZipkinConfig struct {
	ServerURL string         `json:"server_url"`
	Sampling  ZipkinSampling `json:"sampling"`
}

type ZipkinSampling added in v0.0.381

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

Directories

Path Synopsis
Package semconv contains OpenTelemetry semantic convention constants.
Package semconv contains OpenTelemetry semantic convention constants.

Jump to

Keyboard shortcuts

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