stats

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: AGPL-3.0 Imports: 30 Imported by: 59

Documentation

Index

Constants

View Source
const (
	CountType     = "count"
	TimerType     = "timer"
	GaugeType     = "gauge"
	HistogramType = "histogram"
)
View Source
const (
	// SpanStatusUnset is the default status code.
	SpanStatusUnset = SpanStatus(codes.Unset)

	// SpanStatusError indicates the operation contains an error.
	SpanStatusError = SpanStatus(codes.Error)

	// SpanStatusOk indicates operation has been validated by an Application developers
	// or Operator to have completed successfully, or contain no error.
	SpanStatusOk = SpanStatus(codes.Ok)
)
View Source
const (
	// SpanKindUnspecified is an unspecified SpanKind and is not a valid
	// SpanKind. SpanKindUnspecified should be replaced with SpanKindInternal
	// if it is received.
	SpanKindUnspecified = trace.SpanKindUnspecified
	// SpanKindInternal is a SpanKind for a Span that represents an internal
	// operation within an application.
	SpanKindInternal = trace.SpanKindInternal
	// SpanKindServer is a SpanKind for a Span that represents the operation
	// of handling a request from a client.
	SpanKindServer = trace.SpanKindServer
	// SpanKindClient is a SpanKind for a Span that represents the operation
	// of client making a request to a server.
	SpanKindClient = trace.SpanKindClient
	// SpanKindProducer is a SpanKind for a Span that represents the operation
	// of a producer sending a message to a message broker. Unlike
	// SpanKindClient and SpanKindServer, there is often no direct
	// relationship between this kind of Span and a SpanKindConsumer kind. A
	// SpanKindProducer Span will end once the message is accepted by the
	// message broker which might not overlap with the processing of that
	// message.
	SpanKindProducer = trace.SpanKindProducer
	// SpanKindConsumer is a SpanKind for a Span that represents the operation
	// of a consumer receiving a message from a message broker. Like
	// SpanKindProducer Spans, there is often no direct relationship between
	// this Span and the Span that produced the message.
	SpanKindConsumer = trace.SpanKindConsumer
)

Variables

View Source
var DefaultGoRoutineFactory = defaultGoRoutineFactory{}

Functions

func GetTraceParentFromContext added in v0.19.0

func GetTraceParentFromContext(ctx context.Context) string

GetTraceParentFromContext returns the traceparent header from the context

func InjectTraceParentIntoContext added in v0.19.0

func InjectTraceParentIntoContext(ctx context.Context, traceParent string) context.Context

InjectTraceParentIntoContext injects the traceparent header into the context

Types

type Counter

type Counter interface {
	Count(n int)
	Increment()
}

Counter represents a counter metric

type Gauge

type Gauge interface {
	Gauge(value interface{})
}

Gauge represents a gauge metric

type GoRoutineFactory

type GoRoutineFactory interface {
	Go(function func())
}

type Histogram

type Histogram interface {
	Observe(value float64)
}

Histogram represents a histogram metric

type Measurement

type Measurement interface {
	Counter
	Gauge
	Histogram
	Timer
}

Measurement provides all stat measurement functions TODO: the API should not return a union of measurement methods, but rather a distinct type for each measurement type

type Option

type Option func(*statsConfig)

Option is a function used to configure the stats service.

func WithDefaultHistogramBuckets added in v0.10.0

func WithDefaultHistogramBuckets(buckets []float64) Option

WithDefaultHistogramBuckets sets the histogram buckets for the stats service.

func WithHistogramBuckets added in v0.10.0

func WithHistogramBuckets(histogramName string, buckets []float64) Option

WithHistogramBuckets sets the histogram buckets for a measurement.

func WithPrometheusRegistry added in v0.11.0

func WithPrometheusRegistry(registerer prometheus.Registerer, gatherer prometheus.Gatherer) Option

WithPrometheusRegistry sets the prometheus registerer and gatherer for the stats service. If nil is passed the default ones will be used.

func WithServiceName

func WithServiceName(name string) Option

WithServiceName sets the service name for the stats service.

func WithServiceVersion

func WithServiceVersion(version string) Option

WithServiceVersion sets the service version for the stats service.

type SpanContext added in v0.19.0

type SpanContext = trace.SpanContext

type SpanKind added in v0.19.0

type SpanKind = trace.SpanKind

type SpanOption added in v0.19.0

type SpanOption func(*spanConfig)

SpanOption can be used with span.Start() and span.AddEvent()

func SpanWithTags added in v0.19.0

func SpanWithTags(tags Tags) SpanOption

SpanWithTags sets the tags for the span

func SpanWithTimestamp added in v0.19.0

func SpanWithTimestamp(timestamp time.Time) SpanOption

SpanWithTimestamp sets the timestamp for the span

type SpanStatus added in v0.19.0

type SpanStatus uint32

SpanStatus is an 32-bit representation of a status state.

type Stats

type Stats interface {
	// NewStat creates a new Measurement with provided Name and Type
	NewStat(name, statType string) (m Measurement)

	// NewTaggedStat creates a new Measurement with provided Name, Type and Tags
	NewTaggedStat(name, statType string, tags Tags) Measurement

	NewSampledTaggedStat(name, statType string, tags Tags) Measurement

	NewTracer(name string) Tracer

	// Start starts the stats service and the collection of periodic stats.
	Start(ctx context.Context, goFactory GoRoutineFactory) error

	// Stop stops the service and the collection of periodic stats.
	Stop()
}

Stats manages stat Measurements

var Default Stats

Default is the default (singleton) Stats instance

var NOP Stats = &nop{}

func NewStats

func NewStats(
	config *config.Config, loggerFactory loggerFactory, metricManager svcMetric.Manager, opts ...Option,
) Stats

NewStats create a new Stats instance using the provided config, logger factory and metric manager as dependencies

type Tags

type Tags map[string]string

Tags is a map of key value pairs

func (Tags) String

func (t Tags) String() string

String returns all key value pairs as a single string, separated by commas, sorted by increasing key order

func (Tags) Strings

func (t Tags) Strings() []string

Strings returns all key value pairs as an ordered list of strings, sorted by increasing key order

type Timer

type Timer interface {
	SendTiming(duration time.Duration)
	Since(start time.Time)
	RecordDuration() func()
}

Timer represents a timer metric

type TraceSpan added in v0.19.0

type TraceSpan interface {
	// AddEvent adds an event with the provided name and options.
	AddEvent(name string, options ...SpanOption)

	// SetStatus sets the status of the Span in the form of a code and a
	// description, provided the status hasn't already been set to a higher
	// value before (OK > Error > Unset). The description is only included in a
	// status when the code is for an error.
	SetStatus(code SpanStatus, description string)

	// SpanContext returns the SpanContext of the Span. The returned SpanContext
	// is usable even after the End method has been called for the Span.
	SpanContext() SpanContext

	// SetAttributes sets kv as attributes of the Span. If a key from kv
	// already exists for an attribute of the Span it will be overwritten with
	// the value contained in kv.
	SetAttributes(tags Tags)

	// End terminates the span
	End()
}

type Tracer added in v0.19.0

type Tracer interface {
	SpanFromContext(context.Context) TraceSpan
	Start(
		ctx context.Context, spanName string, spanKind SpanKind, options ...SpanOption,
	) (context.Context, TraceSpan)
}

func NewTracerFromOpenTelemetry added in v0.19.0

func NewTracerFromOpenTelemetry(t trace.Tracer) Tracer

NewTracerFromOpenTelemetry creates a new go-kit Tracer from an OpenTelemetry Tracer.

Directories

Path Synopsis
internal
otel/prometheus
Package prometheus is imported from the official OpenTelemetry package: https://github.com/open-telemetry/opentelemetry-go/tree/v1.14.0/exporters/prometheus The version of the exporter would be v0.37.0 (not v1.14.0, see releases).
Package prometheus is imported from the official OpenTelemetry package: https://github.com/open-telemetry/opentelemetry-go/tree/v1.14.0/exporters/prometheus The version of the exporter would be v0.37.0 (not v1.14.0, see releases).
Package metric implements an abstraction for safely managing metrics in concurrent environments.
Package metric implements an abstraction for safely managing metrics in concurrent environments.
Package mock_stats is a generated GoMock package.
Package mock_stats is a generated GoMock package.

Jump to

Keyboard shortcuts

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