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 ¶
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 ¶
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
Source Files ¶
Click to show internal directories.
Click to hide internal directories.