otel

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Overview

Package otel is a wrapper around Open-Telemetry's API for submitting metrics.

This satisfies the go-kit metrics Provider type.

Index

Constants

View Source
const (
	// ServiceKey is the attribute key for the `_service` convention.
	ServiceKey = attribute.Key("_service")

	// ComponentKey is the attribute key for the `component` convention
	ComponentKey = attribute.Key("component")
)

Service level resource attributes

View Source
const (
	// StageKey is the attribute key for the `stage` convention.
	StageKey = attribute.Key("stage")

	// SubServiceKey is the attribute key for the `_subservice` convention.
	SubServiceKey = attribute.Key("_subservice")

	// CloudKey is the attribute key for the `cloud` convention.
	CloudKey = attribute.Key("cloud")
)

Environment level resource attributes

View Source
const (
	// HoneycombDatasetKey maps to the honeycomb specific dataset attribute
	HoneycombDatasetKey  = attribute.Key("dataset")
	MetricDestinationVal = "true"
)
View Source
const (
	// DefaultAgentEndpoint is a default exporter endpoint that points to a local otel collector.
	DefaultAgentEndpoint = "http://0.0.0.0:55680"
)

Variables

View Source
var (
	// ErrExporterNil is returned if an exporter is required, but is not passed in.
	ErrExporterNil = errors.New("exporter cannot be nil")
	// ErrAggregatorNil is returned if an aggregator is required, but is not passed in.
	ErrAggregatorNil = errors.New("aggregator cannot be nil")
	// ErrEndpointNil is returned if an endpoint is required, but is not passed in.
	ErrEndpointNil = errors.New("endpoint cannot be nil")
)
View Source
var (
	DefaultAggregationSelector = WithExponentialHistograms
	DefaultEndpointExporter    = WithHTTPExporter
)
View Source
var DefaultReaderInterval = time.Minute
View Source
var ExplicitAggregationSelector = metric.DefaultAggregationSelector

Functions

func Cloud added in v0.1.0

func Cloud(val string) attribute.KeyValue

Cloud returns an attribute.KeyValue for the `cloud` attribute.

func Component added in v0.1.0

func Component(name string) attribute.KeyValue

Component returns an attribute.KeyValue for the `component` attribute.

func CumulativeTemporalitySelector added in v0.1.0

func CumulativeTemporalitySelector(_ metric.InstrumentKind) metricdata.Temporality

func DeltaTemporalitySelector added in v0.1.0

func DeltaTemporalitySelector(_ metric.InstrumentKind) metricdata.Temporality

func EnvironmentConv added in v0.1.0

func EnvironmentConv(stage string) []attribute.KeyValue

EnvironmentConv returns an attribute list for the `stage` and `_subservice` convention.

func ExponentialAggregationSelector added in v0.1.0

func ExponentialAggregationSelector(ik metric.InstrumentKind) metric.Aggregation

func HoneycombDataset added in v0.1.0

func HoneycombDataset(val string) attribute.KeyValue

HoneycombDataset sets the value for the honeycomb `dataset` attribute.

func MetricsDestinations added in v0.1.0

func MetricsDestinations(destinations []string) []attribute.KeyValue

MetricsDestinations appends attributes for each destination in the provided list.

func New

func New(ctx context.Context, serviceName string, opts ...Option) (xmetrics.Provider, error)

New returns a new, unstarted Provider. Use its Start() method to start and establish a connection with its exporter's collector agent.

func SemConv added in v0.1.0

func SemConv(name, namespace, instanceID string) []attribute.KeyValue

SemConv returns a list of semconv attribute tags for `service.name`, `service.namespace` and `service.instance.id`.

func Service added in v0.1.0

func Service(name string) attribute.KeyValue

Service returns an attribute.KeyValue for the `_service` attribute.

func ServiceConv added in v0.1.0

func ServiceConv(name string) []attribute.KeyValue

ServiceConv returns an attriubte list for the `_service` and `component` convention.

func Stage added in v0.1.0

func Stage(val string) attribute.KeyValue

Stage returns an attribute.KeyValue for the `stage` attribute.

func SubService added in v0.1.0

func SubService(val string) attribute.KeyValue

SubService returns an attribute.KeyValue for the `_subservice` attribute.

Types

type Counter

type Counter struct {
	metric.Float64Counter
	// contains filtered or unexported fields
}

Counter is a counter.

func (*Counter) Add

func (c *Counter) Add(delta float64)

Add implements metrics.Counter.

func (*Counter) With

func (c *Counter) With(labelValues ...string) metrics.Counter

With implements metrics.Counter.

type Gauge

type Gauge struct {
	*generic.Gauge
	// contains filtered or unexported fields
}

Gauge is a gauge.

func (*Gauge) Add

func (g *Gauge) Add(delta float64)

Add implements metrics.Gauge.

func (*Gauge) Set

func (g *Gauge) Set(value float64)

Set implements metrics.Gauge.

func (*Gauge) With

func (g *Gauge) With(labelValues ...string) metrics.Gauge

With implements metrics.Gauge.

type Histogram

type Histogram struct {
	metric.Float64Histogram
	// contains filtered or unexported fields
}

Histogram is a histogram.

func (*Histogram) Observe

func (h *Histogram) Observe(value float64)

Observe implements metrics.Histogram.

func (*Histogram) With

func (h *Histogram) With(labelValues ...string) metrics.Histogram

With implements metrics.Histogram.

type Option

type Option func(*config) error

Option is used for optional arguments when initializing Provider.

func WithAggregationSelector added in v0.1.0

func WithAggregationSelector(selector metric.AggregationSelector) Option

func WithAttributes

func WithAttributes(attributes ...attribute.KeyValue) Option

WithAttributes initializes a serviceNameResource with attributes. This is a deprecated function provided for convenence.

func WithCollectPeriod added in v0.0.47

func WithCollectPeriod(collectPeriod time.Duration) Option

WithCollectPeriod initial

func WithCumulativeTemporality added in v0.1.0

func WithCumulativeTemporality() Option

func WithDeltaTemporality added in v0.1.0

func WithDeltaTemporality() Option

func WithEnvironmentStandard added in v0.1.0

func WithEnvironmentStandard(env string) Option

WithEnvironmentStandard returns an Option that configures service attributes for the EnvironmentConv convention.

func WithExplicitAggregation added in v0.1.0

func WithExplicitAggregation() Option

func WithExplicitHistograms deprecated added in v0.1.0

func WithExplicitHistograms() Option

Deprecated: WithExplicitHistograms is deprecated use WithExplicitAggregation instead.

func WithExponentialAggregation added in v0.1.0

func WithExponentialAggregation() Option

func WithExponentialHistograms deprecated added in v0.1.0

func WithExponentialHistograms() Option

Deprecated: WithExponentialHistograms is deprecated use WithExponentialAggregation instead.

func WithExporterFunc added in v0.1.0

func WithExporterFunc(fn exporterFactory) Option

func WithGRPCExporter added in v0.1.0

func WithGRPCExporter(endpoint string, options ...otlpmetricgrpc.Option) Option

func WithHTTPEndpointExporter added in v0.1.0

func WithHTTPEndpointExporter(endpoint string, options ...otlpmetrichttp.Option) Option

func WithHTTPExporter added in v0.1.0

func WithHTTPExporter(options ...otlpmetrichttp.Option) Option

func WithOpenTelemetryStandardService added in v0.1.0

func WithOpenTelemetryStandardService(name, namespace, instanceID string) Option

WithOpenTelemetryStandardService returns an Option that configures service attributes according to open-telemetry semconv conventions.

func WithPrefix added in v0.1.0

func WithPrefix(prefix string) Option

func WithResource added in v0.1.0

func WithResource(res *resource.Resource) Option

WithResource will merge the given resource with the provided default, any duplicate attributes will be overwritten.

func WithServiceStandard added in v0.1.0

func WithServiceStandard(name string) Option

WithServiceStandard returns an Option that configures service attributes for the ServiceConv convention.

func WithTemporalitySelector added in v0.1.0

func WithTemporalitySelector(temporality metric.TemporalitySelector) Option

type Provider

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

Provider initializes a global otlp meter provider that can collect metrics and use a collector to push those metrics to various backends (e.g. Argus, Honeycomb). Initialize with New(...). An initialized Provider must be started before it can be used to provide a Meter (i.e. p.Start()).

func (*Provider) Flush added in v0.0.41

func (p *Provider) Flush() error

Flush stops and starts the controller in order to flush metrics immediately, without having to wait until the next collection occurs. The flush is synchronous and returns an error if the controller fails to flush or cannot restart after flushing.

func (*Provider) NewCardinalityCounter

func (p *Provider) NewCardinalityCounter(name string) xmetrics.CardinalityCounter

NewCardinalityCounter implements metrics.Provider.

func (*Provider) NewCounter

func (p *Provider) NewCounter(name string) metrics.Counter

NewCounter creates a new Counter.

func (*Provider) NewExplicitHistogram added in v0.0.48

func (p *Provider) NewExplicitHistogram(name string, fn xmetrics.DistributionFunc) metrics.Histogram

func (*Provider) NewGauge

func (p *Provider) NewGauge(name string) metrics.Gauge

NewGauge implements metrics.Provider.

func (*Provider) NewHistogram

func (p *Provider) NewHistogram(name string, buckets int) metrics.Histogram

NewHistogram implements metrics.Provider.

func (*Provider) Start

func (p *Provider) Start() error

Start starts the provider's controller and exporter.

func (*Provider) Stop

func (p *Provider) Stop()

Stop shuts down the provider's controller and exporter. It should be used to ensure the metrics provider drains all metrics before exiting the program.

Jump to

Keyboard shortcuts

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