meterprovider

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: Apache-2.0, BSD-3-Clause, MIT Imports: 15 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNotFound = fmt.Errorf("record not found")

ErrNotFound 记录未找到

Functions

This section is empty.

Types

type ExportRecord

type ExportRecord struct {
	InstrumentName         string
	InstrumentationLibrary Library
	Attributes             []attribute.KeyValue
	AggregationKind        aggregation.Kind
	NumberKind             number.Kind
	Sum                    number.Number
	Count                  uint64
	Histogram              aggregation.Buckets
	LastValue              number.Number
	Unit                   unit.Unit
}

ExportRecord represents one collected datapoint from the Exporter.

func (ExportRecord) String

func (r ExportRecord) String() string

String implements Stringer to custom print.

type Exporter

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

Exporter is a manually collected exporter for testing the SDK. It does not satisfy the `export.Exporter` interface because it is not intended to be used with the periodic collection of the SDK, instead the test should manually call `Collect()`

Exporters are not thread safe, and should only be used for testing.

func NewOtelMeterProvider

func NewOtelMeterProvider(opts ...Option) (metric.MeterProvider, *Exporter)

NewOtelMeterProvider creates a MeterProvider and Exporter to be used in tests.

func (*Exporter) Collect

func (e *Exporter) Collect(ctx context.Context) error

Collect triggers the SDK's collect methods and then aggregates the data into ExportRecords. This will overwrite any previous collected metrics.

func (*Exporter) GetByName

func (e *Exporter) GetByName(name string) (ExportRecord, error)

GetByName returns the first Record with a matching instrument name.

Example
mp, exp := NewOtelMeterProvider([]Option{}...)
meter := mp.Meter("go.opentelemetry.io/otel/sdk/metric/metrictest/exporter_ExampleExporter_GetByName")

cnt, err := meter.SyncFloat64().Counter("fCount")
if err != nil {
	panic("could not acquire counter")
}

cnt.Add(context.Background(), 2.5)

err = exp.Collect(context.Background())
if err != nil {
	panic("collection failed")
}

out, _ := exp.GetByName("fCount")

fmt.Println(out.Sum.AsFloat64())
Output:

2.5

func (*Exporter) GetByNameAndAttributes

func (e *Exporter) GetByNameAndAttributes(name string, attributes []attribute.KeyValue) (ExportRecord, error)

GetByNameAndAttributes returns the first Record with a matching name and the sub-set of attributes.

Example
mp, exp := NewOtelMeterProvider([]Option{}...)
meter := mp.Meter("go.opentelemetry.io/otel/sdk/metric/metrictest/exporter_ExampleExporter_GetByNameAndAttributes")

cnt, err := meter.SyncFloat64().Counter("fCount")
if err != nil {
	panic("could not acquire counter")
}

cnt.Add(context.Background(), 4, attribute.String("foo", "bar"), attribute.Bool("found", false))

err = exp.Collect(context.Background())
if err != nil {
	panic("collection failed")
}

out, err := exp.GetByNameAndAttributes("fCount", []attribute.KeyValue{attribute.String("foo", "bar")})
if err != nil {
	println(err.Error())
}

fmt.Println(out.Sum.AsFloat64())
Output:

4

func (*Exporter) GetRecords

func (e *Exporter) GetRecords() []ExportRecord

GetRecords returns all records found by the SDK.

type Library

type Library struct {
	InstrumentationName    string
	InstrumentationVersion string
	SchemaURL              string
}

Library is the same as "sdk/instrumentation".Library but there is a package cycle to use it so it is redeclared here.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option allow for control of details of the TestMeterProvider created.

func WithExplicitBoundaries

func WithExplicitBoundaries(boundaries []float64) Option

WithExplicitBoundaries allows for the explicit specified boundaries for histogram.

func WithTemporalitySelector

func WithTemporalitySelector(ts aggregation.TemporalitySelector) Option

WithTemporalitySelector allows for the use of either cumulative (default) or delta metrics.

Warning: the current SDK does not convert async instruments into delta temporality.

Jump to

Keyboard shortcuts

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