otel

package
v0.0.48 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: BSD-3-Clause Imports: 26 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 DefaultAgentEndpoint = "0.0.0.0:55680"

DefaultAgentEndpoint is a default exporter endpoint that points to a local otel collector.

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 WithDefaultAggregator = WithExactAggregator

WithDefaultAggregator initializes the Provider with a default aggregator.

Functions

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

func NewHTTPClient(url url.URL, opts ...otlpmetrichttp.Option) otlpmetric.Client

NewHTTPClient creates a new HTTP client for exporting otel metrics.

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(*Provider) error

Option is used for optional arguments when initializing Provider.

func WithAggregator

func WithAggregator(agg metric.AggregatorSelector) Option

WithAggregator initializes the Provider with an aggregator used by its controller.

func WithAttributes

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

WithAttributes initializes a serviceNameResource with attributes. If a resource already exists, a new resource is created by merging the two resources.

func WithCloudAttribute added in v0.0.33

func WithCloudAttribute(cloud string) Option

WithCloudAttribute adds the "cloud" attribute.

func WithCollectPeriod added in v0.0.47

func WithCollectPeriod(collectPeriod time.Duration) Option

WithCollectPeriod initializes the controller with the collectPeriod.

func WithDefaultEndpointExporter

func WithDefaultEndpointExporter() Option

WithDefaultEndpointExporter initializes the Provider with an exporter using a default endpoint.

func WithEndpointExporter

func WithEndpointExporter(endpoint string) Option

WithEndpointExporter initializes the Provider with a default exporter.

func WithExactAggregator added in v0.0.48

func WithExactAggregator() Option

WithExactAggregator initializes the Provider with the simple.NewWithExactDistribution.

NOTE: simple.NewWithExactDistribution is removed in go.opentelemetry.io/otel/sdk/metric@v0.26.0.

func WithExplicitHistogramAggregator added in v0.0.48

func WithExplicitHistogramAggregator() Option

WithExplicitHistogramAggregator initializes the Provider with with our custom explicit.NewExplicitHistogramSelector.

This AggregatorSelector hooks the Provider interface to allow customization of a histogram's bucket definition.

func WithExporter

func WithExporter(exp exporter) Option

WithExporter initializes the Provider with an exporter.

func WithServiceInstanceIDAttribute added in v0.0.33

func WithServiceInstanceIDAttribute(serviceInstanceID string) Option

WithServiceInstanceIDAttribute adds the "service.instance.id" attribute.

func WithServiceNamespaceAttribute added in v0.0.38

func WithServiceNamespaceAttribute(serviceNamespace string) Option

WithServiceNamespaceAttribute adds the "service.namespace" attribute.

func WithStageAttribute added in v0.0.33

func WithStageAttribute(stage string) Option

WithStageAttribute adds the "stage" and "_subservice" attributes.

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) Meter

func (p *Provider) Meter(name string) metric.Meter

Meter returns an oltp meter used for the creation of metric instruments. This relies on the Provider's controller having been properly initialized.

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, _ 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.

Directories

Path Synopsis
selector

Jump to

Keyboard shortcuts

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