clue

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: MIT Imports: 20 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdaptiveSampler

func AdaptiveSampler(maxSamplingRate, sampleSize int) sdktrace.Sampler

AdaptiveSampler returns a trace sampler that dynamically computes the interval between samples to target a desired maximum sampling rate.

maxSamplingRate is the desired maximum sampling rate in requests per second.

sampleSize sets the number of requests between two adjustments of the sampling rate when MaxSamplingRate is set. the sample rate cannot be adjusted until the sample size is reached at least once.

func ConfigureOpenTelemetry

func ConfigureOpenTelemetry(ctx context.Context, cfg *Config)

ConfigureOpenTelemetry sets up code instrumentation using the OpenTelemetry API. It leverages the clue logger configured in ctx to log errors.

func NewErrorHandler

func NewErrorHandler(ctx context.Context) otel.ErrorHandler

NewErrorHandler returns an error handler that logs errors using the clue logger configured in ctx.

func NewGRPCMetricExporter added in v1.0.2

func NewGRPCMetricExporter(ctx context.Context, options ...otlpmetricgrpc.Option) (exporter metric.Exporter, shutdown func(), err error)

NewGRPCMetricExporter returns an OpenTelementry Protocol metric exporter that report metrics to a gRPC collector.

func NewGRPCSpanExporter added in v1.0.2

func NewGRPCSpanExporter(ctx context.Context, options ...otlptracegrpc.Option) (exporter trace.SpanExporter, shutdown func(), err error)

NewGRPCSpanExporter returns an OpenTelementry Protocol span exporter that report spans to a gRPC collector.

func NewHTTPMetricExporter added in v1.0.2

func NewHTTPMetricExporter(ctx context.Context, options ...otlpmetrichttp.Option) (exporter metric.Exporter, shutdown func(), err error)

NewHTTPMetricExporter returns an OpenTelementry Protocol metric exporter that report metrics to a HTTP collector.

func NewHTTPSpanExporter added in v1.0.2

func NewHTTPSpanExporter(ctx context.Context, options ...otlptracehttp.Option) (exporter trace.SpanExporter, shutdown func(), err error)

NewHTTPSpanExporter returns an OpenTelementry Protocol span exporter that report spans to a HTTP collector.

Types

type Config

type Config struct {
	// MeterProvider is the OpenTelemetry meter provider used by clue
	MeterProvider metric.MeterProvider
	// TracerProvider is the OpenTelemetry tracer provider used clue
	TracerProvider trace.TracerProvider
	// Propagators is the OpenTelemetry propagator used by clue
	Propagators propagation.TextMapPropagator
	// ErrorHandler is the error handler used by OpenTelemetry
	ErrorHandler otel.ErrorHandler
}

Config is used to configure OpenTelemetry.

func NewConfig

func NewConfig(
	ctx context.Context,
	svcName string,
	svcVersion string,
	metricExporter sdkmetric.Exporter,
	spanExporter sdktrace.SpanExporter,
	opts ...Option,
) (*Config, error)

NewConfig creates a new Config object adequate for use by ConfigureOpenTelemetry. The metricExporter and spanExporter are used to record telemetry. If either is nil then the corresponding package will not record any telemetry. The OpenTelemetry metric provider is configured with a periodic reader. The OpenTelemetry tracer provider is configured to use a batch span processor and an adaptive sampler that aims at a maximum sampling rate of requests per second. The resulting configuration can be modified (and providers replaced) by the caller prior to calling ConfigureOpenTelemetry.

Example:

metricExporter, err := stdoutmetric.New()
if err != nil {
	return err
}
spanExporter, err := stdouttrace.New()
if err != nil {
	return err
}
cfg := clue.NewConfig("mysvc", "1.0.0", metricExporter, spanExporter)

type Option

type Option func(*options)

Option is a function that initializes the clue configuration.

func WithErrorHandler

func WithErrorHandler(errorHandler otel.ErrorHandler) Option

WithErrorHandler sets the error handler used by the telemetry package.

func WithMaxSamplingRate

func WithMaxSamplingRate(rate int) Option

WithMaxSamplingRate sets the maximum sampling rate in requests per second.

func WithPropagators

func WithPropagators(propagator propagation.TextMapPropagator) Option

WithPropagators sets the propagators when extracting and injecting trace context.

func WithReaderInterval

func WithReaderInterval(interval time.Duration) Option

WithReaderInterval returns an option that sets the interval at which the metrics reader is invoked.

func WithSampleSize

func WithSampleSize(size int) Option

WithSampleSize sets the number of requests between two adjustments of the sampling rate.

Jump to

Keyboard shortcuts

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