opentelemetry

package module
v0.0.0-...-703044a Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

README

Telemetry OpenTelemetry

This package contains a Telemetry Metric interface compatible implementation based on OpenTelemetry.

For information on the Telemetry Metric interface, see: https://github.com/tetratelabs/telemetry

For more information on how to use this specific package, see: https://pkg.go.dev/github.com/tetratelabs/telemetry-opentelemetry

Documentation

Overview

Package opentelemetry provides a telemetry Metric interface implementation based on OpenTelemetry.

Package opentelemetry provides a tetratelabs/telemetry compatible metrics implementation based on OpenTelemetry.

Example (NewDistribution)
package main

import (
	"github.com/tetratelabs/telemetry"

	"github.com/tetratelabs/telemetry-opentelemetry"
)

var (
	method        telemetry.Label
	receivedBytes telemetry.Metric
)

func main() {
	telemetry.ToGlobalMetricSink(func(m telemetry.MetricSink) {
		method = m.NewLabel("method")
		receivedBytes = m.NewDistribution(
			"received_bytes_total",
			"Distribution of received bytes by method",
			[]float64{10, 100, 1000, 10000},
			telemetry.WithUnit(telemetry.Bytes),
		)
	})

	telemetry.SetGlobalMetricSink(opentelemetry.New("example"))

	receivedBytes.With(method.Insert("/projects/1")).Record(458)
}
Output:

Example (NewGauge)
package main

import (
	"github.com/tetratelabs/telemetry"

	"github.com/tetratelabs/telemetry-opentelemetry"
)

var pushLatency telemetry.Metric

func main() {
	telemetry.ToGlobalMetricSink(func(m telemetry.MetricSink) {
		pushLatency = m.NewGauge(
			"push_latency_seconds",
			"Duration, measured in seconds, of the last push",
			telemetry.WithUnit(telemetry.Seconds),
		)
	})
	telemetry.SetGlobalMetricSink(opentelemetry.New("example"))

	// only the last recorded value (99.2) will be exported for this gauge
	pushLatency.Record(77.3)
	pushLatency.Record(22.8)
	pushLatency.Record(99.2)
}
Output:

Example (NewSum)
package main

import (
	"github.com/tetratelabs/telemetry"

	"github.com/tetratelabs/telemetry-opentelemetry"
)

var (
	protocol telemetry.Label
	requests telemetry.Metric
)

func main() {
	telemetry.ToGlobalMetricSink(func(m telemetry.MetricSink) {
		protocol = m.NewLabel("protocol")
		requests = m.NewSum(
			"requests_total",
			"Number of requests handled, by protocol",
		)
	})
	telemetry.SetGlobalMetricSink(opentelemetry.New("example"))

	// increment on every http request
	requests.With(protocol.Insert("http")).Increment()

	// count gRPC requests double
	requests.With(protocol.Insert("grpc")).Record(2)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Start

func Start(ms telemetry.MetricSink) []sdk.Option

Start should be used by telemetry Exporters so we can trigger final initialization of our histograms.

Types

type MetricAndDerivedMetricSink

type MetricAndDerivedMetricSink interface {
	telemetry.MetricSink
	telemetry.DerivedMetricSink
}

func New

func New(appName string, opts ...SinkOption) MetricAndDerivedMetricSink

New returns a new Telemetry facade compatible MetricSink.

type MetricDefinition

type MetricDefinition struct {
	Name        string
	Type        string
	Description string
	Bounds      []float64
}

MetricDefinition records a metric's metadata. This is used to work around two limitations of OpenTelemetry:

  • (https://github.com/open-telemetry/opentelemetry-go/issues/4003) Histogram buckets cannot be defined per instrument. instead, we record all metric definitions and add them as Views at registration time.
  • Support pkg/collateral, which wants to query all metrics. This cannot use a simple Collect() call, as this ignores any unused metrics.

type SinkOption

type SinkOption func(ms *metricSink)

func WithLogger

func WithLogger(l telemetry.Logger) SinkOption

func WithStrictDimensions

func WithStrictDimensions() SinkOption

type Unit

type Unit string

Unit encodes the standard name for describing the quantity measured by a Metric (if applicable).

const (
	None         Unit = "1"
	Bytes        Unit = "By"
	Seconds      Unit = "s"
	Milliseconds Unit = "ms"
)

Predefined units for use with the monitoring package.

Directories

Path Synopsis
internal
slices
Package slices defines various functions useful with slices of any type.
Package slices defines various functions useful with slices of any type.
tag
Package tag contains Telemetry tags.
Package tag contains Telemetry tags.
pkg

Jump to

Keyboard shortcuts

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