Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AdaptiveSampler ¶
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 ¶
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.
Types ¶
type Config ¶
type Config struct { // MeterProvider is the OpenTelemetry meter provider used by the clue // metrics package. MeterProvider metric.MeterProvider // TracerProvider is the OpenTelemetry tracer provider used by the clue // trace package. TracerProvider trace.TracerProvider // Propagators is the OpenTelemetry propagator used by the clue trace // package. Propagators propagation.TextMapPropagator // ErrorHandler is the error handler used by the OpenTelemetry // package. ErrorHandler otel.ErrorHandler }
Config is used to initialize metrics and tracing.
func NewConfig ¶
func NewConfig( ctx context.Context, svcName string, svcVersion string, metricsExporter sdkmetric.Exporter, spanExporter sdktrace.SpanExporter, opts ...Option, ) (*Config, error)
NewConfig creates a new Config object adequate for use by ConfigureOpenTelemetry. The metricsExporter and spanExporter are used to record telemetry. If either is nil then the corresponding package will not record any telemetry. The OpenTelemetry metrics 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:
metricsExporter, err := stdoutmetric.New() if err != nil { return err } spanExporter, err := stdouttrace.New() if err != nil { return err } cfg := clue.NewConfig("mysvc", "1.0.0", metricsExporter, 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 ¶
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 ¶
WithReaderInterval returns an option that sets the interval at which the metrics reader is invoked.
func WithSampleSize ¶
WithSampleSize sets the number of requests between two adjustments of the sampling rate.