You've already forked opentelemetry-go
							
							
				mirror of
				https://github.com/open-telemetry/opentelemetry-go.git
				synced 2025-10-31 00:07:40 +02:00 
			
		
		
		
	Move InstrumentKind into the new metric/sdkapi package (#2091)
* Move InstrumentKind into the new metric/sdkapi package * remove the alias * remove the alias (everywhere) * Changelog * Add a test * merge updates * fix changelog Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
		| @@ -14,6 +14,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm | ||||
|  | ||||
| ### Changed | ||||
|  | ||||
| - Metric SDK/API implementation type `InstrumentKind` moves into `sdkapi` sub-package. (#2091) | ||||
|  | ||||
| ### Deprecated | ||||
|  | ||||
| - The `go.opentelemetry.io/otel/bridge/opencensus/utils` package is deprecated. | ||||
| @@ -51,7 +53,6 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm | ||||
|  | ||||
| - The `SpanModels` function is now exported from the `go.opentelemetry.io/otel/exporters/zipkin` package to convert OpenTelemetry spans into Zipkin model spans. (#2027) | ||||
| - Rename the `"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc".RetrySettings` to `RetryConfig`. (#2095) | ||||
| - Rename the `"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp".RetrySettings` to `RetryConfig`. (#2095) | ||||
|  | ||||
| ### Deprecated | ||||
|  | ||||
|   | ||||
| @@ -28,6 +28,7 @@ import ( | ||||
| 	"go.opentelemetry.io/otel/attribute" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	"go.opentelemetry.io/otel/metric/unit" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| 	"go.opentelemetry.io/otel/sdk/export/metric/aggregation" | ||||
| @@ -133,21 +134,21 @@ func convertResource(res *ocresource.Resource) *resource.Resource { | ||||
| func convertDescriptor(ocDescriptor metricdata.Descriptor) (metric.Descriptor, error) { | ||||
| 	var ( | ||||
| 		nkind number.Kind | ||||
| 		ikind metric.InstrumentKind | ||||
| 		ikind sdkapi.InstrumentKind | ||||
| 	) | ||||
| 	switch ocDescriptor.Type { | ||||
| 	case metricdata.TypeGaugeInt64: | ||||
| 		nkind = number.Int64Kind | ||||
| 		ikind = metric.ValueObserverInstrumentKind | ||||
| 		ikind = sdkapi.ValueObserverInstrumentKind | ||||
| 	case metricdata.TypeGaugeFloat64: | ||||
| 		nkind = number.Float64Kind | ||||
| 		ikind = metric.ValueObserverInstrumentKind | ||||
| 		ikind = sdkapi.ValueObserverInstrumentKind | ||||
| 	case metricdata.TypeCumulativeInt64: | ||||
| 		nkind = number.Int64Kind | ||||
| 		ikind = metric.SumObserverInstrumentKind | ||||
| 		ikind = sdkapi.SumObserverInstrumentKind | ||||
| 	case metricdata.TypeCumulativeFloat64: | ||||
| 		nkind = number.Float64Kind | ||||
| 		ikind = metric.SumObserverInstrumentKind | ||||
| 		ikind = sdkapi.SumObserverInstrumentKind | ||||
| 	default: | ||||
| 		// Includes TypeGaugeDistribution, TypeCumulativeDistribution, TypeSummary | ||||
| 		return metric.Descriptor{}, fmt.Errorf("%w; descriptor type: %v", errConversion, ocDescriptor.Type) | ||||
|   | ||||
| @@ -29,6 +29,7 @@ import ( | ||||
| 	"go.opentelemetry.io/otel/attribute" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	"go.opentelemetry.io/otel/metric/unit" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| 	exportmetric "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| @@ -70,7 +71,7 @@ func TestExportMetrics(t *testing.T) { | ||||
| 	now := time.Now() | ||||
| 	basicDesc := metric.NewDescriptor( | ||||
| 		"", | ||||
| 		metric.ValueObserverInstrumentKind, | ||||
| 		sdkapi.ValueObserverInstrumentKind, | ||||
| 		number.Int64Kind, | ||||
| 		metric.WithInstrumentationName("OpenCensus Bridge"), | ||||
| 	) | ||||
| @@ -384,7 +385,7 @@ func TestConvertDescriptor(t *testing.T) { | ||||
| 			desc: "empty descriptor", | ||||
| 			expected: metric.NewDescriptor( | ||||
| 				"", | ||||
| 				metric.ValueObserverInstrumentKind, | ||||
| 				sdkapi.ValueObserverInstrumentKind, | ||||
| 				number.Int64Kind, | ||||
| 				metric.WithInstrumentationName("OpenCensus Bridge"), | ||||
| 			), | ||||
| @@ -399,7 +400,7 @@ func TestConvertDescriptor(t *testing.T) { | ||||
| 			}, | ||||
| 			expected: metric.NewDescriptor( | ||||
| 				"foo", | ||||
| 				metric.ValueObserverInstrumentKind, | ||||
| 				sdkapi.ValueObserverInstrumentKind, | ||||
| 				number.Int64Kind, | ||||
| 				metric.WithInstrumentationName("OpenCensus Bridge"), | ||||
| 				metric.WithDescription("bar"), | ||||
| @@ -416,7 +417,7 @@ func TestConvertDescriptor(t *testing.T) { | ||||
| 			}, | ||||
| 			expected: metric.NewDescriptor( | ||||
| 				"foo", | ||||
| 				metric.ValueObserverInstrumentKind, | ||||
| 				sdkapi.ValueObserverInstrumentKind, | ||||
| 				number.Float64Kind, | ||||
| 				metric.WithInstrumentationName("OpenCensus Bridge"), | ||||
| 				metric.WithDescription("bar"), | ||||
| @@ -433,7 +434,7 @@ func TestConvertDescriptor(t *testing.T) { | ||||
| 			}, | ||||
| 			expected: metric.NewDescriptor( | ||||
| 				"foo", | ||||
| 				metric.SumObserverInstrumentKind, | ||||
| 				sdkapi.SumObserverInstrumentKind, | ||||
| 				number.Int64Kind, | ||||
| 				metric.WithInstrumentationName("OpenCensus Bridge"), | ||||
| 				metric.WithDescription("bar"), | ||||
| @@ -450,7 +451,7 @@ func TestConvertDescriptor(t *testing.T) { | ||||
| 			}, | ||||
| 			expected: metric.NewDescriptor( | ||||
| 				"foo", | ||||
| 				metric.SumObserverInstrumentKind, | ||||
| 				sdkapi.SumObserverInstrumentKind, | ||||
| 				number.Float64Kind, | ||||
| 				metric.WithInstrumentationName("OpenCensus Bridge"), | ||||
| 				metric.WithDescription("bar"), | ||||
|   | ||||
| @@ -31,6 +31,7 @@ import ( | ||||
| 	"go.opentelemetry.io/otel/attribute" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	metricsdk "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| 	"go.opentelemetry.io/otel/sdk/resource" | ||||
| 	commonpb "go.opentelemetry.io/proto/otlp/common/v1" | ||||
| @@ -98,7 +99,7 @@ func (m *checkpointSet) ForEach(_ metricsdk.ExportKindSelector, fn func(metricsd | ||||
|  | ||||
| type record struct { | ||||
| 	name     string | ||||
| 	iKind    metric.InstrumentKind | ||||
| 	iKind    sdkapi.InstrumentKind | ||||
| 	nKind    number.Kind | ||||
| 	resource *resource.Resource | ||||
| 	opts     []metric.InstrumentOption | ||||
| @@ -184,7 +185,7 @@ func TestNoGroupingExport(t *testing.T) { | ||||
| 		[]record{ | ||||
| 			{ | ||||
| 				"int64-count", | ||||
| 				metric.CounterInstrumentKind, | ||||
| 				sdkapi.CounterInstrumentKind, | ||||
| 				number.Int64Kind, | ||||
| 				nil, | ||||
| 				nil, | ||||
| @@ -192,7 +193,7 @@ func TestNoGroupingExport(t *testing.T) { | ||||
| 			}, | ||||
| 			{ | ||||
| 				"int64-count", | ||||
| 				metric.CounterInstrumentKind, | ||||
| 				sdkapi.CounterInstrumentKind, | ||||
| 				number.Int64Kind, | ||||
| 				nil, | ||||
| 				nil, | ||||
| @@ -239,7 +240,7 @@ func TestNoGroupingExport(t *testing.T) { | ||||
| func TestValuerecorderMetricGroupingExport(t *testing.T) { | ||||
| 	r := record{ | ||||
| 		"valuerecorder", | ||||
| 		metric.ValueRecorderInstrumentKind, | ||||
| 		sdkapi.ValueRecorderInstrumentKind, | ||||
| 		number.Int64Kind, | ||||
| 		nil, | ||||
| 		nil, | ||||
| @@ -290,7 +291,7 @@ func TestValuerecorderMetricGroupingExport(t *testing.T) { | ||||
| func TestCountInt64MetricGroupingExport(t *testing.T) { | ||||
| 	r := record{ | ||||
| 		"int64-count", | ||||
| 		metric.CounterInstrumentKind, | ||||
| 		sdkapi.CounterInstrumentKind, | ||||
| 		number.Int64Kind, | ||||
| 		nil, | ||||
| 		nil, | ||||
| @@ -340,7 +341,7 @@ func TestCountInt64MetricGroupingExport(t *testing.T) { | ||||
| func TestCountFloat64MetricGroupingExport(t *testing.T) { | ||||
| 	r := record{ | ||||
| 		"float64-count", | ||||
| 		metric.CounterInstrumentKind, | ||||
| 		sdkapi.CounterInstrumentKind, | ||||
| 		number.Float64Kind, | ||||
| 		nil, | ||||
| 		nil, | ||||
| @@ -394,7 +395,7 @@ func TestResourceMetricGroupingExport(t *testing.T) { | ||||
| 		[]record{ | ||||
| 			{ | ||||
| 				"int64-count", | ||||
| 				metric.CounterInstrumentKind, | ||||
| 				sdkapi.CounterInstrumentKind, | ||||
| 				number.Int64Kind, | ||||
| 				testInstA, | ||||
| 				nil, | ||||
| @@ -402,7 +403,7 @@ func TestResourceMetricGroupingExport(t *testing.T) { | ||||
| 			}, | ||||
| 			{ | ||||
| 				"int64-count", | ||||
| 				metric.CounterInstrumentKind, | ||||
| 				sdkapi.CounterInstrumentKind, | ||||
| 				number.Int64Kind, | ||||
| 				testInstA, | ||||
| 				nil, | ||||
| @@ -410,7 +411,7 @@ func TestResourceMetricGroupingExport(t *testing.T) { | ||||
| 			}, | ||||
| 			{ | ||||
| 				"int64-count", | ||||
| 				metric.CounterInstrumentKind, | ||||
| 				sdkapi.CounterInstrumentKind, | ||||
| 				number.Int64Kind, | ||||
| 				testInstA, | ||||
| 				nil, | ||||
| @@ -418,7 +419,7 @@ func TestResourceMetricGroupingExport(t *testing.T) { | ||||
| 			}, | ||||
| 			{ | ||||
| 				"int64-count", | ||||
| 				metric.CounterInstrumentKind, | ||||
| 				sdkapi.CounterInstrumentKind, | ||||
| 				number.Int64Kind, | ||||
| 				testInstB, | ||||
| 				nil, | ||||
| @@ -512,7 +513,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { | ||||
| 		[]record{ | ||||
| 			{ | ||||
| 				"int64-count", | ||||
| 				metric.CounterInstrumentKind, | ||||
| 				sdkapi.CounterInstrumentKind, | ||||
| 				number.Int64Kind, | ||||
| 				testInstA, | ||||
| 				countingLib1, | ||||
| @@ -520,7 +521,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { | ||||
| 			}, | ||||
| 			{ | ||||
| 				"int64-count", | ||||
| 				metric.CounterInstrumentKind, | ||||
| 				sdkapi.CounterInstrumentKind, | ||||
| 				number.Int64Kind, | ||||
| 				testInstA, | ||||
| 				countingLib2, | ||||
| @@ -528,7 +529,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { | ||||
| 			}, | ||||
| 			{ | ||||
| 				"int64-count", | ||||
| 				metric.CounterInstrumentKind, | ||||
| 				sdkapi.CounterInstrumentKind, | ||||
| 				number.Int64Kind, | ||||
| 				testInstA, | ||||
| 				countingLib1, | ||||
| @@ -536,7 +537,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { | ||||
| 			}, | ||||
| 			{ | ||||
| 				"int64-count", | ||||
| 				metric.CounterInstrumentKind, | ||||
| 				sdkapi.CounterInstrumentKind, | ||||
| 				number.Int64Kind, | ||||
| 				testInstA, | ||||
| 				countingLib1, | ||||
| @@ -544,7 +545,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { | ||||
| 			}, | ||||
| 			{ | ||||
| 				"int64-count", | ||||
| 				metric.CounterInstrumentKind, | ||||
| 				sdkapi.CounterInstrumentKind, | ||||
| 				number.Int64Kind, | ||||
| 				testInstA, | ||||
| 				summingLib, | ||||
| @@ -552,7 +553,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { | ||||
| 			}, | ||||
| 			{ | ||||
| 				"int64-count", | ||||
| 				metric.CounterInstrumentKind, | ||||
| 				sdkapi.CounterInstrumentKind, | ||||
| 				number.Int64Kind, | ||||
| 				testInstB, | ||||
| 				countingLib1, | ||||
| @@ -688,16 +689,16 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { | ||||
| func TestStatelessExportKind(t *testing.T) { | ||||
| 	type testcase struct { | ||||
| 		name           string | ||||
| 		instrumentKind metric.InstrumentKind | ||||
| 		instrumentKind sdkapi.InstrumentKind | ||||
| 		aggTemporality metricpb.AggregationTemporality | ||||
| 		monotonic      bool | ||||
| 	} | ||||
|  | ||||
| 	for _, k := range []testcase{ | ||||
| 		{"counter", metric.CounterInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA, true}, | ||||
| 		{"updowncounter", metric.UpDownCounterInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA, false}, | ||||
| 		{"sumobserver", metric.SumObserverInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE, true}, | ||||
| 		{"updownsumobserver", metric.UpDownSumObserverInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE, false}, | ||||
| 		{"counter", sdkapi.CounterInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA, true}, | ||||
| 		{"updowncounter", sdkapi.UpDownCounterInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA, false}, | ||||
| 		{"sumobserver", sdkapi.SumObserverInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE, true}, | ||||
| 		{"updownsumobserver", sdkapi.UpDownSumObserverInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE, false}, | ||||
| 	} { | ||||
| 		t.Run(k.name, func(t *testing.T) { | ||||
| 			runMetricExportTests( | ||||
|   | ||||
| @@ -27,6 +27,7 @@ import ( | ||||
| 	"go.opentelemetry.io/otel/attribute" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| 	"go.opentelemetry.io/otel/sdk/export/metric/aggregation" | ||||
| 	arrAgg "go.opentelemetry.io/otel/sdk/metric/aggregator/exact" | ||||
| @@ -122,7 +123,7 @@ func TestMinMaxSumCountValue(t *testing.T) { | ||||
| } | ||||
|  | ||||
| func TestMinMaxSumCountDatapoints(t *testing.T) { | ||||
| 	desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind) | ||||
| 	desc := metric.NewDescriptor("", sdkapi.ValueRecorderInstrumentKind, number.Int64Kind) | ||||
| 	labels := attribute.NewSet(attribute.String("one", "1")) | ||||
| 	mmscs := minmaxsumcount.New(2, &metric.Descriptor{}) | ||||
| 	mmsc, ckpt := &mmscs[0], &mmscs[1] | ||||
| @@ -178,7 +179,7 @@ func TestMinMaxSumCountPropagatesErrors(t *testing.T) { | ||||
| } | ||||
|  | ||||
| func TestSumIntDataPoints(t *testing.T) { | ||||
| 	desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind) | ||||
| 	desc := metric.NewDescriptor("", sdkapi.ValueRecorderInstrumentKind, number.Int64Kind) | ||||
| 	labels := attribute.NewSet(attribute.String("one", "1")) | ||||
| 	sums := sumAgg.New(2) | ||||
| 	s, ckpt := &sums[0], &sums[1] | ||||
| @@ -218,7 +219,7 @@ func TestSumIntDataPoints(t *testing.T) { | ||||
| } | ||||
|  | ||||
| func TestSumFloatDataPoints(t *testing.T) { | ||||
| 	desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Float64Kind) | ||||
| 	desc := metric.NewDescriptor("", sdkapi.ValueRecorderInstrumentKind, number.Float64Kind) | ||||
| 	labels := attribute.NewSet(attribute.String("one", "1")) | ||||
| 	sums := sumAgg.New(2) | ||||
| 	s, ckpt := &sums[0], &sums[1] | ||||
| @@ -256,7 +257,7 @@ func TestSumFloatDataPoints(t *testing.T) { | ||||
| } | ||||
|  | ||||
| func TestLastValueIntDataPoints(t *testing.T) { | ||||
| 	desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind) | ||||
| 	desc := metric.NewDescriptor("", sdkapi.ValueRecorderInstrumentKind, number.Int64Kind) | ||||
| 	labels := attribute.NewSet(attribute.String("one", "1")) | ||||
| 	lvs := lvAgg.New(2) | ||||
| 	lv, ckpt := &lvs[0], &lvs[1] | ||||
| @@ -291,7 +292,7 @@ func TestLastValueIntDataPoints(t *testing.T) { | ||||
| } | ||||
|  | ||||
| func TestExactIntDataPoints(t *testing.T) { | ||||
| 	desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind) | ||||
| 	desc := metric.NewDescriptor("", sdkapi.ValueRecorderInstrumentKind, number.Int64Kind) | ||||
| 	labels := attribute.NewSet(attribute.String("one", "1")) | ||||
| 	arrs := arrAgg.New(2) | ||||
| 	e, ckpt := &arrs[0], &arrs[1] | ||||
| @@ -326,7 +327,7 @@ func TestExactIntDataPoints(t *testing.T) { | ||||
| } | ||||
|  | ||||
| func TestExactFloatDataPoints(t *testing.T) { | ||||
| 	desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Float64Kind) | ||||
| 	desc := metric.NewDescriptor("", sdkapi.ValueRecorderInstrumentKind, number.Float64Kind) | ||||
| 	labels := attribute.NewSet(attribute.String("one", "1")) | ||||
| 	arrs := arrAgg.New(2) | ||||
| 	e, ckpt := &arrs[0], &arrs[1] | ||||
| @@ -360,7 +361,7 @@ func TestExactFloatDataPoints(t *testing.T) { | ||||
| } | ||||
|  | ||||
| func TestSumErrUnknownValueType(t *testing.T) { | ||||
| 	desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Kind(-1)) | ||||
| 	desc := metric.NewDescriptor("", sdkapi.ValueRecorderInstrumentKind, number.Kind(-1)) | ||||
| 	labels := attribute.NewSet() | ||||
| 	s := &sumAgg.New(1)[0] | ||||
| 	record := export.NewRecord(&desc, &labels, nil, s, intervalStart, intervalEnd) | ||||
| @@ -445,7 +446,7 @@ var _ aggregation.MinMaxSumCount = &testErrMinMaxSumCount{} | ||||
|  | ||||
| func TestRecordAggregatorIncompatibleErrors(t *testing.T) { | ||||
| 	makeMpb := func(kind aggregation.Kind, agg aggregation.Aggregation) (*metricpb.Metric, error) { | ||||
| 		desc := metric.NewDescriptor("things", metric.CounterInstrumentKind, number.Int64Kind) | ||||
| 		desc := metric.NewDescriptor("things", sdkapi.CounterInstrumentKind, number.Int64Kind) | ||||
| 		labels := attribute.NewSet() | ||||
| 		res := resource.Empty() | ||||
| 		test := &testAgg{ | ||||
| @@ -482,7 +483,7 @@ func TestRecordAggregatorIncompatibleErrors(t *testing.T) { | ||||
|  | ||||
| func TestRecordAggregatorUnexpectedErrors(t *testing.T) { | ||||
| 	makeMpb := func(kind aggregation.Kind, agg aggregation.Aggregation) (*metricpb.Metric, error) { | ||||
| 		desc := metric.NewDescriptor("things", metric.CounterInstrumentKind, number.Int64Kind) | ||||
| 		desc := metric.NewDescriptor("things", sdkapi.CounterInstrumentKind, number.Int64Kind) | ||||
| 		labels := attribute.NewSet() | ||||
| 		res := resource.Empty() | ||||
| 		return Record(export.CumulativeExportKindSelector(), export.NewRecord(&desc, &labels, res, agg, intervalStart, intervalEnd)) | ||||
|   | ||||
| @@ -22,6 +22,7 @@ import ( | ||||
| 	"go.opentelemetry.io/otel/attribute" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	exportmetric "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric/aggregator/sum" | ||||
| 	"go.opentelemetry.io/otel/sdk/resource" | ||||
| @@ -59,7 +60,7 @@ var _ exportmetric.CheckpointSet = OneRecordCheckpointSet{} | ||||
| func (OneRecordCheckpointSet) ForEach(kindSelector exportmetric.ExportKindSelector, recordFunc func(exportmetric.Record) error) error { | ||||
| 	desc := metric.NewDescriptor( | ||||
| 		"foo", | ||||
| 		metric.CounterInstrumentKind, | ||||
| 		sdkapi.CounterInstrumentKind, | ||||
| 		number.Int64Kind, | ||||
| 	) | ||||
| 	res := resource.NewSchemaless(attribute.String("a", "b")) | ||||
|   | ||||
| @@ -29,6 +29,7 @@ import ( | ||||
| 	"go.opentelemetry.io/otel/attribute" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	exportmetric "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| 	controller "go.opentelemetry.io/otel/sdk/metric/controller/basic" | ||||
| 	processor "go.opentelemetry.io/otel/sdk/metric/processor/basic" | ||||
| @@ -47,22 +48,22 @@ func RunEndToEndTest(ctx context.Context, t *testing.T, exp *otlpmetric.Exporter | ||||
| 	labels := []attribute.KeyValue{attribute.Bool("test", true)} | ||||
|  | ||||
| 	type data struct { | ||||
| 		iKind metric.InstrumentKind | ||||
| 		iKind sdkapi.InstrumentKind | ||||
| 		nKind number.Kind | ||||
| 		val   int64 | ||||
| 	} | ||||
| 	instruments := map[string]data{ | ||||
| 		"test-int64-counter":         {metric.CounterInstrumentKind, number.Int64Kind, 1}, | ||||
| 		"test-float64-counter":       {metric.CounterInstrumentKind, number.Float64Kind, 1}, | ||||
| 		"test-int64-valuerecorder":   {metric.ValueRecorderInstrumentKind, number.Int64Kind, 2}, | ||||
| 		"test-float64-valuerecorder": {metric.ValueRecorderInstrumentKind, number.Float64Kind, 2}, | ||||
| 		"test-int64-valueobserver":   {metric.ValueObserverInstrumentKind, number.Int64Kind, 3}, | ||||
| 		"test-float64-valueobserver": {metric.ValueObserverInstrumentKind, number.Float64Kind, 3}, | ||||
| 		"test-int64-counter":         {sdkapi.CounterInstrumentKind, number.Int64Kind, 1}, | ||||
| 		"test-float64-counter":       {sdkapi.CounterInstrumentKind, number.Float64Kind, 1}, | ||||
| 		"test-int64-valuerecorder":   {sdkapi.ValueRecorderInstrumentKind, number.Int64Kind, 2}, | ||||
| 		"test-float64-valuerecorder": {sdkapi.ValueRecorderInstrumentKind, number.Float64Kind, 2}, | ||||
| 		"test-int64-valueobserver":   {sdkapi.ValueObserverInstrumentKind, number.Int64Kind, 3}, | ||||
| 		"test-float64-valueobserver": {sdkapi.ValueObserverInstrumentKind, number.Float64Kind, 3}, | ||||
| 	} | ||||
| 	for name, data := range instruments { | ||||
| 		data := data | ||||
| 		switch data.iKind { | ||||
| 		case metric.CounterInstrumentKind: | ||||
| 		case sdkapi.CounterInstrumentKind: | ||||
| 			switch data.nKind { | ||||
| 			case number.Int64Kind: | ||||
| 				metric.Must(meter).NewInt64Counter(name).Add(ctx, data.val, labels...) | ||||
| @@ -71,7 +72,7 @@ func RunEndToEndTest(ctx context.Context, t *testing.T, exp *otlpmetric.Exporter | ||||
| 			default: | ||||
| 				assert.Failf(t, "unsupported number testing kind", data.nKind.String()) | ||||
| 			} | ||||
| 		case metric.ValueRecorderInstrumentKind: | ||||
| 		case sdkapi.ValueRecorderInstrumentKind: | ||||
| 			switch data.nKind { | ||||
| 			case number.Int64Kind: | ||||
| 				metric.Must(meter).NewInt64ValueRecorder(name).Record(ctx, data.val, labels...) | ||||
| @@ -80,7 +81,7 @@ func RunEndToEndTest(ctx context.Context, t *testing.T, exp *otlpmetric.Exporter | ||||
| 			default: | ||||
| 				assert.Failf(t, "unsupported number testing kind", data.nKind.String()) | ||||
| 			} | ||||
| 		case metric.ValueObserverInstrumentKind: | ||||
| 		case sdkapi.ValueObserverInstrumentKind: | ||||
| 			switch data.nKind { | ||||
| 			case number.Int64Kind: | ||||
| 				metric.Must(meter).NewInt64ValueObserver(name, | ||||
| @@ -130,13 +131,13 @@ func RunEndToEndTest(ctx context.Context, t *testing.T, exp *otlpmetric.Exporter | ||||
| 		seen[m.Name] = struct{}{} | ||||
|  | ||||
| 		switch data.iKind { | ||||
| 		case metric.CounterInstrumentKind, metric.ValueObserverInstrumentKind: | ||||
| 		case sdkapi.CounterInstrumentKind, sdkapi.ValueObserverInstrumentKind: | ||||
| 			var dp []*metricpb.NumberDataPoint | ||||
| 			switch data.iKind { | ||||
| 			case metric.CounterInstrumentKind: | ||||
| 			case sdkapi.CounterInstrumentKind: | ||||
| 				require.NotNil(t, m.GetSum()) | ||||
| 				dp = m.GetSum().GetDataPoints() | ||||
| 			case metric.ValueObserverInstrumentKind: | ||||
| 			case sdkapi.ValueObserverInstrumentKind: | ||||
| 				require.NotNil(t, m.GetGauge()) | ||||
| 				dp = m.GetGauge().GetDataPoints() | ||||
| 			} | ||||
| @@ -150,7 +151,7 @@ func RunEndToEndTest(ctx context.Context, t *testing.T, exp *otlpmetric.Exporter | ||||
| 					assert.Equal(t, v, dp[0].Value, "invalid value for %q", m.Name) | ||||
| 				} | ||||
| 			} | ||||
| 		case metric.ValueRecorderInstrumentKind: | ||||
| 		case sdkapi.ValueRecorderInstrumentKind: | ||||
| 			require.NotNil(t, m.GetSummary()) | ||||
| 			if dp := m.GetSummary().DataPoints; assert.Len(t, dp, 1) { | ||||
| 				count := dp[0].Count | ||||
|   | ||||
| @@ -19,6 +19,7 @@ import ( | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/attribute" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	"go.opentelemetry.io/otel/metric/unit" | ||||
| ) | ||||
|  | ||||
| @@ -64,7 +65,7 @@ func (m Meter) NewBatchObserver(callback BatchObserverFunc) BatchObserver { | ||||
| // duplicate registration). | ||||
| func (m Meter) NewInt64Counter(name string, options ...InstrumentOption) (Int64Counter, error) { | ||||
| 	return wrapInt64CounterInstrument( | ||||
| 		m.newSync(name, CounterInstrumentKind, number.Int64Kind, options)) | ||||
| 		m.newSync(name, sdkapi.CounterInstrumentKind, number.Int64Kind, options)) | ||||
| } | ||||
|  | ||||
| // NewFloat64Counter creates a new floating point Counter with the | ||||
| @@ -73,7 +74,7 @@ func (m Meter) NewInt64Counter(name string, options ...InstrumentOption) (Int64C | ||||
| // duplicate registration). | ||||
| func (m Meter) NewFloat64Counter(name string, options ...InstrumentOption) (Float64Counter, error) { | ||||
| 	return wrapFloat64CounterInstrument( | ||||
| 		m.newSync(name, CounterInstrumentKind, number.Float64Kind, options)) | ||||
| 		m.newSync(name, sdkapi.CounterInstrumentKind, number.Float64Kind, options)) | ||||
| } | ||||
|  | ||||
| // NewInt64UpDownCounter creates a new integer UpDownCounter instrument with the | ||||
| @@ -82,7 +83,7 @@ func (m Meter) NewFloat64Counter(name string, options ...InstrumentOption) (Floa | ||||
| // duplicate registration). | ||||
| func (m Meter) NewInt64UpDownCounter(name string, options ...InstrumentOption) (Int64UpDownCounter, error) { | ||||
| 	return wrapInt64UpDownCounterInstrument( | ||||
| 		m.newSync(name, UpDownCounterInstrumentKind, number.Int64Kind, options)) | ||||
| 		m.newSync(name, sdkapi.UpDownCounterInstrumentKind, number.Int64Kind, options)) | ||||
| } | ||||
|  | ||||
| // NewFloat64UpDownCounter creates a new floating point UpDownCounter with the | ||||
| @@ -91,7 +92,7 @@ func (m Meter) NewInt64UpDownCounter(name string, options ...InstrumentOption) ( | ||||
| // duplicate registration). | ||||
| func (m Meter) NewFloat64UpDownCounter(name string, options ...InstrumentOption) (Float64UpDownCounter, error) { | ||||
| 	return wrapFloat64UpDownCounterInstrument( | ||||
| 		m.newSync(name, UpDownCounterInstrumentKind, number.Float64Kind, options)) | ||||
| 		m.newSync(name, sdkapi.UpDownCounterInstrumentKind, number.Float64Kind, options)) | ||||
| } | ||||
|  | ||||
| // NewInt64ValueRecorder creates a new integer ValueRecorder instrument with the | ||||
| @@ -100,7 +101,7 @@ func (m Meter) NewFloat64UpDownCounter(name string, options ...InstrumentOption) | ||||
| // duplicate registration). | ||||
| func (m Meter) NewInt64ValueRecorder(name string, opts ...InstrumentOption) (Int64ValueRecorder, error) { | ||||
| 	return wrapInt64ValueRecorderInstrument( | ||||
| 		m.newSync(name, ValueRecorderInstrumentKind, number.Int64Kind, opts)) | ||||
| 		m.newSync(name, sdkapi.ValueRecorderInstrumentKind, number.Int64Kind, opts)) | ||||
| } | ||||
|  | ||||
| // NewFloat64ValueRecorder creates a new floating point ValueRecorder with the | ||||
| @@ -109,7 +110,7 @@ func (m Meter) NewInt64ValueRecorder(name string, opts ...InstrumentOption) (Int | ||||
| // duplicate registration). | ||||
| func (m Meter) NewFloat64ValueRecorder(name string, opts ...InstrumentOption) (Float64ValueRecorder, error) { | ||||
| 	return wrapFloat64ValueRecorderInstrument( | ||||
| 		m.newSync(name, ValueRecorderInstrumentKind, number.Float64Kind, opts)) | ||||
| 		m.newSync(name, sdkapi.ValueRecorderInstrumentKind, number.Float64Kind, opts)) | ||||
| } | ||||
|  | ||||
| // NewInt64ValueObserver creates a new integer ValueObserver instrument | ||||
| @@ -121,7 +122,7 @@ func (m Meter) NewInt64ValueObserver(name string, callback Int64ObserverFunc, op | ||||
| 		return wrapInt64ValueObserverInstrument(NoopAsync{}, nil) | ||||
| 	} | ||||
| 	return wrapInt64ValueObserverInstrument( | ||||
| 		m.newAsync(name, ValueObserverInstrumentKind, number.Int64Kind, opts, | ||||
| 		m.newAsync(name, sdkapi.ValueObserverInstrumentKind, number.Int64Kind, opts, | ||||
| 			newInt64AsyncRunner(callback))) | ||||
| } | ||||
|  | ||||
| @@ -134,7 +135,7 @@ func (m Meter) NewFloat64ValueObserver(name string, callback Float64ObserverFunc | ||||
| 		return wrapFloat64ValueObserverInstrument(NoopAsync{}, nil) | ||||
| 	} | ||||
| 	return wrapFloat64ValueObserverInstrument( | ||||
| 		m.newAsync(name, ValueObserverInstrumentKind, number.Float64Kind, opts, | ||||
| 		m.newAsync(name, sdkapi.ValueObserverInstrumentKind, number.Float64Kind, opts, | ||||
| 			newFloat64AsyncRunner(callback))) | ||||
| } | ||||
|  | ||||
| @@ -147,7 +148,7 @@ func (m Meter) NewInt64SumObserver(name string, callback Int64ObserverFunc, opts | ||||
| 		return wrapInt64SumObserverInstrument(NoopAsync{}, nil) | ||||
| 	} | ||||
| 	return wrapInt64SumObserverInstrument( | ||||
| 		m.newAsync(name, SumObserverInstrumentKind, number.Int64Kind, opts, | ||||
| 		m.newAsync(name, sdkapi.SumObserverInstrumentKind, number.Int64Kind, opts, | ||||
| 			newInt64AsyncRunner(callback))) | ||||
| } | ||||
|  | ||||
| @@ -160,7 +161,7 @@ func (m Meter) NewFloat64SumObserver(name string, callback Float64ObserverFunc, | ||||
| 		return wrapFloat64SumObserverInstrument(NoopAsync{}, nil) | ||||
| 	} | ||||
| 	return wrapFloat64SumObserverInstrument( | ||||
| 		m.newAsync(name, SumObserverInstrumentKind, number.Float64Kind, opts, | ||||
| 		m.newAsync(name, sdkapi.SumObserverInstrumentKind, number.Float64Kind, opts, | ||||
| 			newFloat64AsyncRunner(callback))) | ||||
| } | ||||
|  | ||||
| @@ -173,7 +174,7 @@ func (m Meter) NewInt64UpDownSumObserver(name string, callback Int64ObserverFunc | ||||
| 		return wrapInt64UpDownSumObserverInstrument(NoopAsync{}, nil) | ||||
| 	} | ||||
| 	return wrapInt64UpDownSumObserverInstrument( | ||||
| 		m.newAsync(name, UpDownSumObserverInstrumentKind, number.Int64Kind, opts, | ||||
| 		m.newAsync(name, sdkapi.UpDownSumObserverInstrumentKind, number.Int64Kind, opts, | ||||
| 			newInt64AsyncRunner(callback))) | ||||
| } | ||||
|  | ||||
| @@ -186,7 +187,7 @@ func (m Meter) NewFloat64UpDownSumObserver(name string, callback Float64Observer | ||||
| 		return wrapFloat64UpDownSumObserverInstrument(NoopAsync{}, nil) | ||||
| 	} | ||||
| 	return wrapFloat64UpDownSumObserverInstrument( | ||||
| 		m.newAsync(name, UpDownSumObserverInstrumentKind, number.Float64Kind, opts, | ||||
| 		m.newAsync(name, sdkapi.UpDownSumObserverInstrumentKind, number.Float64Kind, opts, | ||||
| 			newFloat64AsyncRunner(callback))) | ||||
| } | ||||
|  | ||||
| @@ -199,7 +200,7 @@ func (b BatchObserver) NewInt64ValueObserver(name string, opts ...InstrumentOpti | ||||
| 		return wrapInt64ValueObserverInstrument(NoopAsync{}, nil) | ||||
| 	} | ||||
| 	return wrapInt64ValueObserverInstrument( | ||||
| 		b.meter.newAsync(name, ValueObserverInstrumentKind, number.Int64Kind, opts, b.runner)) | ||||
| 		b.meter.newAsync(name, sdkapi.ValueObserverInstrumentKind, number.Int64Kind, opts, b.runner)) | ||||
| } | ||||
|  | ||||
| // NewFloat64ValueObserver creates a new floating point ValueObserver with | ||||
| @@ -211,7 +212,7 @@ func (b BatchObserver) NewFloat64ValueObserver(name string, opts ...InstrumentOp | ||||
| 		return wrapFloat64ValueObserverInstrument(NoopAsync{}, nil) | ||||
| 	} | ||||
| 	return wrapFloat64ValueObserverInstrument( | ||||
| 		b.meter.newAsync(name, ValueObserverInstrumentKind, number.Float64Kind, opts, | ||||
| 		b.meter.newAsync(name, sdkapi.ValueObserverInstrumentKind, number.Float64Kind, opts, | ||||
| 			b.runner)) | ||||
| } | ||||
|  | ||||
| @@ -224,7 +225,7 @@ func (b BatchObserver) NewInt64SumObserver(name string, opts ...InstrumentOption | ||||
| 		return wrapInt64SumObserverInstrument(NoopAsync{}, nil) | ||||
| 	} | ||||
| 	return wrapInt64SumObserverInstrument( | ||||
| 		b.meter.newAsync(name, SumObserverInstrumentKind, number.Int64Kind, opts, b.runner)) | ||||
| 		b.meter.newAsync(name, sdkapi.SumObserverInstrumentKind, number.Int64Kind, opts, b.runner)) | ||||
| } | ||||
|  | ||||
| // NewFloat64SumObserver creates a new floating point SumObserver with | ||||
| @@ -236,7 +237,7 @@ func (b BatchObserver) NewFloat64SumObserver(name string, opts ...InstrumentOpti | ||||
| 		return wrapFloat64SumObserverInstrument(NoopAsync{}, nil) | ||||
| 	} | ||||
| 	return wrapFloat64SumObserverInstrument( | ||||
| 		b.meter.newAsync(name, SumObserverInstrumentKind, number.Float64Kind, opts, | ||||
| 		b.meter.newAsync(name, sdkapi.SumObserverInstrumentKind, number.Float64Kind, opts, | ||||
| 			b.runner)) | ||||
| } | ||||
|  | ||||
| @@ -249,7 +250,7 @@ func (b BatchObserver) NewInt64UpDownSumObserver(name string, opts ...Instrument | ||||
| 		return wrapInt64UpDownSumObserverInstrument(NoopAsync{}, nil) | ||||
| 	} | ||||
| 	return wrapInt64UpDownSumObserverInstrument( | ||||
| 		b.meter.newAsync(name, UpDownSumObserverInstrumentKind, number.Int64Kind, opts, b.runner)) | ||||
| 		b.meter.newAsync(name, sdkapi.UpDownSumObserverInstrumentKind, number.Int64Kind, opts, b.runner)) | ||||
| } | ||||
|  | ||||
| // NewFloat64UpDownSumObserver creates a new floating point UpDownSumObserver with | ||||
| @@ -261,7 +262,7 @@ func (b BatchObserver) NewFloat64UpDownSumObserver(name string, opts ...Instrume | ||||
| 		return wrapFloat64UpDownSumObserverInstrument(NoopAsync{}, nil) | ||||
| 	} | ||||
| 	return wrapFloat64UpDownSumObserverInstrument( | ||||
| 		b.meter.newAsync(name, UpDownSumObserverInstrumentKind, number.Float64Kind, opts, | ||||
| 		b.meter.newAsync(name, sdkapi.UpDownSumObserverInstrumentKind, number.Float64Kind, opts, | ||||
| 			b.runner)) | ||||
| } | ||||
|  | ||||
| @@ -273,7 +274,7 @@ func (m Meter) MeterImpl() MeterImpl { | ||||
| // newAsync constructs one new asynchronous instrument. | ||||
| func (m Meter) newAsync( | ||||
| 	name string, | ||||
| 	mkind InstrumentKind, | ||||
| 	mkind sdkapi.InstrumentKind, | ||||
| 	nkind number.Kind, | ||||
| 	opts []InstrumentOption, | ||||
| 	runner AsyncRunner, | ||||
| @@ -293,7 +294,7 @@ func (m Meter) newAsync( | ||||
| // newSync constructs one new synchronous instrument. | ||||
| func (m Meter) newSync( | ||||
| 	name string, | ||||
| 	metricKind InstrumentKind, | ||||
| 	metricKind sdkapi.InstrumentKind, | ||||
| 	numberKind number.Kind, | ||||
| 	opts []InstrumentOption, | ||||
| ) ( | ||||
| @@ -521,13 +522,13 @@ func (bm BatchObserverMust) NewFloat64UpDownSumObserver(name string, oos ...Inst | ||||
| // options. | ||||
| type Descriptor struct { | ||||
| 	name           string | ||||
| 	instrumentKind InstrumentKind | ||||
| 	instrumentKind sdkapi.InstrumentKind | ||||
| 	numberKind     number.Kind | ||||
| 	config         InstrumentConfig | ||||
| } | ||||
|  | ||||
| // NewDescriptor returns a Descriptor with the given contents. | ||||
| func NewDescriptor(name string, ikind InstrumentKind, nkind number.Kind, opts ...InstrumentOption) Descriptor { | ||||
| func NewDescriptor(name string, ikind sdkapi.InstrumentKind, nkind number.Kind, opts ...InstrumentOption) Descriptor { | ||||
| 	return Descriptor{ | ||||
| 		name:           name, | ||||
| 		instrumentKind: ikind, | ||||
| @@ -542,7 +543,7 @@ func (d Descriptor) Name() string { | ||||
| } | ||||
|  | ||||
| // InstrumentKind returns the specific kind of instrument. | ||||
| func (d Descriptor) InstrumentKind() InstrumentKind { | ||||
| func (d Descriptor) InstrumentKind() sdkapi.InstrumentKind { | ||||
| 	return d.instrumentKind | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -12,8 +12,6 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| //go:generate stringer -type=InstrumentKind | ||||
|  | ||||
| package metric // import "go.opentelemetry.io/otel/metric" | ||||
|  | ||||
| import ( | ||||
| @@ -27,69 +25,6 @@ import ( | ||||
| // ErrSDKReturnedNilImpl is returned when a new `MeterImpl` returns nil. | ||||
| var ErrSDKReturnedNilImpl = errors.New("SDK returned a nil implementation") | ||||
|  | ||||
| // InstrumentKind describes the kind of instrument. | ||||
| type InstrumentKind int8 | ||||
|  | ||||
| const ( | ||||
| 	// ValueRecorderInstrumentKind indicates a ValueRecorder instrument. | ||||
| 	ValueRecorderInstrumentKind InstrumentKind = iota | ||||
| 	// ValueObserverInstrumentKind indicates an ValueObserver instrument. | ||||
| 	ValueObserverInstrumentKind | ||||
|  | ||||
| 	// CounterInstrumentKind indicates a Counter instrument. | ||||
| 	CounterInstrumentKind | ||||
| 	// UpDownCounterInstrumentKind indicates a UpDownCounter instrument. | ||||
| 	UpDownCounterInstrumentKind | ||||
|  | ||||
| 	// SumObserverInstrumentKind indicates a SumObserver instrument. | ||||
| 	SumObserverInstrumentKind | ||||
| 	// UpDownSumObserverInstrumentKind indicates a UpDownSumObserver | ||||
| 	// instrument. | ||||
| 	UpDownSumObserverInstrumentKind | ||||
| ) | ||||
|  | ||||
| // Synchronous returns whether this is a synchronous kind of instrument. | ||||
| func (k InstrumentKind) Synchronous() bool { | ||||
| 	switch k { | ||||
| 	case CounterInstrumentKind, UpDownCounterInstrumentKind, ValueRecorderInstrumentKind: | ||||
| 		return true | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| // Asynchronous returns whether this is an asynchronous kind of instrument. | ||||
| func (k InstrumentKind) Asynchronous() bool { | ||||
| 	return !k.Synchronous() | ||||
| } | ||||
|  | ||||
| // Adding returns whether this kind of instrument adds its inputs (as opposed to Grouping). | ||||
| func (k InstrumentKind) Adding() bool { | ||||
| 	switch k { | ||||
| 	case CounterInstrumentKind, UpDownCounterInstrumentKind, SumObserverInstrumentKind, UpDownSumObserverInstrumentKind: | ||||
| 		return true | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| // Grouping returns whether this kind of instrument groups its inputs (as opposed to Adding). | ||||
| func (k InstrumentKind) Grouping() bool { | ||||
| 	return !k.Adding() | ||||
| } | ||||
|  | ||||
| // Monotonic returns whether this kind of instrument exposes a non-decreasing sum. | ||||
| func (k InstrumentKind) Monotonic() bool { | ||||
| 	switch k { | ||||
| 	case CounterInstrumentKind, SumObserverInstrumentKind: | ||||
| 		return true | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| // PrecomputedSum returns whether this kind of instrument receives precomputed sums. | ||||
| func (k InstrumentKind) PrecomputedSum() bool { | ||||
| 	return k.Adding() && k.Asynchronous() | ||||
| } | ||||
|  | ||||
| // Observation is used for reporting an asynchronous  batch of metric | ||||
| // values. Instances of this type should be created by asynchronous | ||||
| // instruments (e.g., Int64ValueObserver.Observation()). | ||||
|   | ||||
| @@ -23,6 +23,7 @@ import ( | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/metrictest" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	"go.opentelemetry.io/otel/metric/unit" | ||||
|  | ||||
| 	"github.com/google/go-cmp/cmp" | ||||
| @@ -33,49 +34,49 @@ import ( | ||||
| var Must = metric.Must | ||||
|  | ||||
| var ( | ||||
| 	syncKinds = []metric.InstrumentKind{ | ||||
| 		metric.ValueRecorderInstrumentKind, | ||||
| 		metric.CounterInstrumentKind, | ||||
| 		metric.UpDownCounterInstrumentKind, | ||||
| 	syncKinds = []sdkapi.InstrumentKind{ | ||||
| 		sdkapi.ValueRecorderInstrumentKind, | ||||
| 		sdkapi.CounterInstrumentKind, | ||||
| 		sdkapi.UpDownCounterInstrumentKind, | ||||
| 	} | ||||
| 	asyncKinds = []metric.InstrumentKind{ | ||||
| 		metric.ValueObserverInstrumentKind, | ||||
| 		metric.SumObserverInstrumentKind, | ||||
| 		metric.UpDownSumObserverInstrumentKind, | ||||
| 	asyncKinds = []sdkapi.InstrumentKind{ | ||||
| 		sdkapi.ValueObserverInstrumentKind, | ||||
| 		sdkapi.SumObserverInstrumentKind, | ||||
| 		sdkapi.UpDownSumObserverInstrumentKind, | ||||
| 	} | ||||
| 	addingKinds = []metric.InstrumentKind{ | ||||
| 		metric.CounterInstrumentKind, | ||||
| 		metric.UpDownCounterInstrumentKind, | ||||
| 		metric.SumObserverInstrumentKind, | ||||
| 		metric.UpDownSumObserverInstrumentKind, | ||||
| 	addingKinds = []sdkapi.InstrumentKind{ | ||||
| 		sdkapi.CounterInstrumentKind, | ||||
| 		sdkapi.UpDownCounterInstrumentKind, | ||||
| 		sdkapi.SumObserverInstrumentKind, | ||||
| 		sdkapi.UpDownSumObserverInstrumentKind, | ||||
| 	} | ||||
| 	groupingKinds = []metric.InstrumentKind{ | ||||
| 		metric.ValueRecorderInstrumentKind, | ||||
| 		metric.ValueObserverInstrumentKind, | ||||
| 	groupingKinds = []sdkapi.InstrumentKind{ | ||||
| 		sdkapi.ValueRecorderInstrumentKind, | ||||
| 		sdkapi.ValueObserverInstrumentKind, | ||||
| 	} | ||||
|  | ||||
| 	monotonicKinds = []metric.InstrumentKind{ | ||||
| 		metric.CounterInstrumentKind, | ||||
| 		metric.SumObserverInstrumentKind, | ||||
| 	monotonicKinds = []sdkapi.InstrumentKind{ | ||||
| 		sdkapi.CounterInstrumentKind, | ||||
| 		sdkapi.SumObserverInstrumentKind, | ||||
| 	} | ||||
|  | ||||
| 	nonMonotonicKinds = []metric.InstrumentKind{ | ||||
| 		metric.UpDownCounterInstrumentKind, | ||||
| 		metric.UpDownSumObserverInstrumentKind, | ||||
| 		metric.ValueRecorderInstrumentKind, | ||||
| 		metric.ValueObserverInstrumentKind, | ||||
| 	nonMonotonicKinds = []sdkapi.InstrumentKind{ | ||||
| 		sdkapi.UpDownCounterInstrumentKind, | ||||
| 		sdkapi.UpDownSumObserverInstrumentKind, | ||||
| 		sdkapi.ValueRecorderInstrumentKind, | ||||
| 		sdkapi.ValueObserverInstrumentKind, | ||||
| 	} | ||||
|  | ||||
| 	precomputedSumKinds = []metric.InstrumentKind{ | ||||
| 		metric.SumObserverInstrumentKind, | ||||
| 		metric.UpDownSumObserverInstrumentKind, | ||||
| 	precomputedSumKinds = []sdkapi.InstrumentKind{ | ||||
| 		sdkapi.SumObserverInstrumentKind, | ||||
| 		sdkapi.UpDownSumObserverInstrumentKind, | ||||
| 	} | ||||
|  | ||||
| 	nonPrecomputedSumKinds = []metric.InstrumentKind{ | ||||
| 		metric.CounterInstrumentKind, | ||||
| 		metric.UpDownCounterInstrumentKind, | ||||
| 		metric.ValueRecorderInstrumentKind, | ||||
| 		metric.ValueObserverInstrumentKind, | ||||
| 	nonPrecomputedSumKinds = []sdkapi.InstrumentKind{ | ||||
| 		sdkapi.CounterInstrumentKind, | ||||
| 		sdkapi.UpDownCounterInstrumentKind, | ||||
| 		sdkapi.ValueRecorderInstrumentKind, | ||||
| 		sdkapi.ValueObserverInstrumentKind, | ||||
| 	} | ||||
| ) | ||||
|  | ||||
| @@ -119,7 +120,7 @@ func TestPrecomputedSum(t *testing.T) { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func checkSyncBatches(ctx context.Context, t *testing.T, labels []attribute.KeyValue, mock *metrictest.MeterImpl, nkind number.Kind, mkind metric.InstrumentKind, instrument metric.InstrumentImpl, expected ...float64) { | ||||
| func checkSyncBatches(ctx context.Context, t *testing.T, labels []attribute.KeyValue, mock *metrictest.MeterImpl, nkind number.Kind, mkind sdkapi.InstrumentKind, instrument metric.InstrumentImpl, expected ...float64) { | ||||
| 	t.Helper() | ||||
|  | ||||
| 	batchesCount := len(mock.MeasurementBatches) | ||||
| @@ -316,7 +317,7 @@ func TestCounter(t *testing.T) { | ||||
| 		boundInstrument := c.Bind(labels...) | ||||
| 		boundInstrument.Add(ctx, -742) | ||||
| 		meter.RecordBatch(ctx, labels, c.Measurement(42)) | ||||
| 		checkSyncBatches(ctx, t, labels, mockSDK, number.Float64Kind, metric.CounterInstrumentKind, c.SyncImpl(), | ||||
| 		checkSyncBatches(ctx, t, labels, mockSDK, number.Float64Kind, sdkapi.CounterInstrumentKind, c.SyncImpl(), | ||||
| 			1994.1, -742, 42, | ||||
| 		) | ||||
| 	}) | ||||
| @@ -329,7 +330,7 @@ func TestCounter(t *testing.T) { | ||||
| 		boundInstrument := c.Bind(labels...) | ||||
| 		boundInstrument.Add(ctx, 4200) | ||||
| 		meter.RecordBatch(ctx, labels, c.Measurement(420000)) | ||||
| 		checkSyncBatches(ctx, t, labels, mockSDK, number.Int64Kind, metric.CounterInstrumentKind, c.SyncImpl(), | ||||
| 		checkSyncBatches(ctx, t, labels, mockSDK, number.Int64Kind, sdkapi.CounterInstrumentKind, c.SyncImpl(), | ||||
| 			42, 4200, 420000, | ||||
| 		) | ||||
|  | ||||
| @@ -343,7 +344,7 @@ func TestCounter(t *testing.T) { | ||||
| 		boundInstrument := c.Bind(labels...) | ||||
| 		boundInstrument.Add(ctx, -100) | ||||
| 		meter.RecordBatch(ctx, labels, c.Measurement(42)) | ||||
| 		checkSyncBatches(ctx, t, labels, mockSDK, number.Int64Kind, metric.UpDownCounterInstrumentKind, c.SyncImpl(), | ||||
| 		checkSyncBatches(ctx, t, labels, mockSDK, number.Int64Kind, sdkapi.UpDownCounterInstrumentKind, c.SyncImpl(), | ||||
| 			100, -100, 42, | ||||
| 		) | ||||
| 	}) | ||||
| @@ -356,7 +357,7 @@ func TestCounter(t *testing.T) { | ||||
| 		boundInstrument := c.Bind(labels...) | ||||
| 		boundInstrument.Add(ctx, -76) | ||||
| 		meter.RecordBatch(ctx, labels, c.Measurement(-100.1)) | ||||
| 		checkSyncBatches(ctx, t, labels, mockSDK, number.Float64Kind, metric.UpDownCounterInstrumentKind, c.SyncImpl(), | ||||
| 		checkSyncBatches(ctx, t, labels, mockSDK, number.Float64Kind, sdkapi.UpDownCounterInstrumentKind, c.SyncImpl(), | ||||
| 			100.1, -76, -100.1, | ||||
| 		) | ||||
| 	}) | ||||
| @@ -372,7 +373,7 @@ func TestValueRecorder(t *testing.T) { | ||||
| 		boundInstrument := m.Bind(labels...) | ||||
| 		boundInstrument.Record(ctx, 0) | ||||
| 		meter.RecordBatch(ctx, labels, m.Measurement(-100.5)) | ||||
| 		checkSyncBatches(ctx, t, labels, mockSDK, number.Float64Kind, metric.ValueRecorderInstrumentKind, m.SyncImpl(), | ||||
| 		checkSyncBatches(ctx, t, labels, mockSDK, number.Float64Kind, sdkapi.ValueRecorderInstrumentKind, m.SyncImpl(), | ||||
| 			42, 0, -100.5, | ||||
| 		) | ||||
| 	}) | ||||
| @@ -385,7 +386,7 @@ func TestValueRecorder(t *testing.T) { | ||||
| 		boundInstrument := m.Bind(labels...) | ||||
| 		boundInstrument.Record(ctx, 80) | ||||
| 		meter.RecordBatch(ctx, labels, m.Measurement(0)) | ||||
| 		checkSyncBatches(ctx, t, labels, mockSDK, number.Int64Kind, metric.ValueRecorderInstrumentKind, m.SyncImpl(), | ||||
| 		checkSyncBatches(ctx, t, labels, mockSDK, number.Int64Kind, sdkapi.ValueRecorderInstrumentKind, m.SyncImpl(), | ||||
| 			173, 80, 0, | ||||
| 		) | ||||
| 	}) | ||||
| @@ -399,7 +400,7 @@ func TestObserverInstruments(t *testing.T) { | ||||
| 			result.Observe(42.1, labels...) | ||||
| 		}) | ||||
| 		mockSDK.RunAsyncInstruments() | ||||
| 		checkObserverBatch(t, labels, mockSDK, number.Float64Kind, metric.ValueObserverInstrumentKind, o.AsyncImpl(), | ||||
| 		checkObserverBatch(t, labels, mockSDK, number.Float64Kind, sdkapi.ValueObserverInstrumentKind, o.AsyncImpl(), | ||||
| 			42.1, | ||||
| 		) | ||||
| 	}) | ||||
| @@ -410,7 +411,7 @@ func TestObserverInstruments(t *testing.T) { | ||||
| 			result.Observe(-142, labels...) | ||||
| 		}) | ||||
| 		mockSDK.RunAsyncInstruments() | ||||
| 		checkObserverBatch(t, labels, mockSDK, number.Int64Kind, metric.ValueObserverInstrumentKind, o.AsyncImpl(), | ||||
| 		checkObserverBatch(t, labels, mockSDK, number.Int64Kind, sdkapi.ValueObserverInstrumentKind, o.AsyncImpl(), | ||||
| 			-142, | ||||
| 		) | ||||
| 	}) | ||||
| @@ -421,7 +422,7 @@ func TestObserverInstruments(t *testing.T) { | ||||
| 			result.Observe(42.1, labels...) | ||||
| 		}) | ||||
| 		mockSDK.RunAsyncInstruments() | ||||
| 		checkObserverBatch(t, labels, mockSDK, number.Float64Kind, metric.SumObserverInstrumentKind, o.AsyncImpl(), | ||||
| 		checkObserverBatch(t, labels, mockSDK, number.Float64Kind, sdkapi.SumObserverInstrumentKind, o.AsyncImpl(), | ||||
| 			42.1, | ||||
| 		) | ||||
| 	}) | ||||
| @@ -432,7 +433,7 @@ func TestObserverInstruments(t *testing.T) { | ||||
| 			result.Observe(-142, labels...) | ||||
| 		}) | ||||
| 		mockSDK.RunAsyncInstruments() | ||||
| 		checkObserverBatch(t, labels, mockSDK, number.Int64Kind, metric.SumObserverInstrumentKind, o.AsyncImpl(), | ||||
| 		checkObserverBatch(t, labels, mockSDK, number.Int64Kind, sdkapi.SumObserverInstrumentKind, o.AsyncImpl(), | ||||
| 			-142, | ||||
| 		) | ||||
| 	}) | ||||
| @@ -443,7 +444,7 @@ func TestObserverInstruments(t *testing.T) { | ||||
| 			result.Observe(42.1, labels...) | ||||
| 		}) | ||||
| 		mockSDK.RunAsyncInstruments() | ||||
| 		checkObserverBatch(t, labels, mockSDK, number.Float64Kind, metric.UpDownSumObserverInstrumentKind, o.AsyncImpl(), | ||||
| 		checkObserverBatch(t, labels, mockSDK, number.Float64Kind, sdkapi.UpDownSumObserverInstrumentKind, o.AsyncImpl(), | ||||
| 			42.1, | ||||
| 		) | ||||
| 	}) | ||||
| @@ -454,7 +455,7 @@ func TestObserverInstruments(t *testing.T) { | ||||
| 			result.Observe(-142, labels...) | ||||
| 		}) | ||||
| 		mockSDK.RunAsyncInstruments() | ||||
| 		checkObserverBatch(t, labels, mockSDK, number.Int64Kind, metric.UpDownSumObserverInstrumentKind, o.AsyncImpl(), | ||||
| 		checkObserverBatch(t, labels, mockSDK, number.Int64Kind, sdkapi.UpDownSumObserverInstrumentKind, o.AsyncImpl(), | ||||
| 			-142, | ||||
| 		) | ||||
| 	}) | ||||
| @@ -505,7 +506,7 @@ func TestBatchObserverInstruments(t *testing.T) { | ||||
| 	require.Equal(t, 0, m2.Number.CompareNumber(number.Float64Kind, metrictest.ResolveNumberByKind(t, number.Float64Kind, 42))) | ||||
| } | ||||
|  | ||||
| func checkObserverBatch(t *testing.T, labels []attribute.KeyValue, mock *metrictest.MeterImpl, nkind number.Kind, mkind metric.InstrumentKind, observer metric.AsyncImpl, expected float64) { | ||||
| func checkObserverBatch(t *testing.T, labels []attribute.KeyValue, mock *metrictest.MeterImpl, nkind number.Kind, mkind sdkapi.InstrumentKind, observer metric.AsyncImpl, expected float64) { | ||||
| 	t.Helper() | ||||
| 	assert.Len(t, mock.MeasurementBatches, 1) | ||||
| 	if len(mock.MeasurementBatches) < 1 { | ||||
|   | ||||
							
								
								
									
										80
									
								
								metric/sdkapi/instrumentkind.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								metric/sdkapi/instrumentkind.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,80 @@ | ||||
| // Copyright The OpenTelemetry Authors | ||||
| // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | ||||
| // | ||||
| //     http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | ||||
| // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| //go:generate stringer -type=InstrumentKind | ||||
|  | ||||
| package sdkapi // import "go.opentelemetry.io/otel/metric/sdkapi" | ||||
|  | ||||
| // InstrumentKind describes the kind of instrument. | ||||
| type InstrumentKind int8 | ||||
|  | ||||
| const ( | ||||
| 	// ValueRecorderInstrumentKind indicates a ValueRecorder instrument. | ||||
| 	ValueRecorderInstrumentKind InstrumentKind = iota | ||||
| 	// ValueObserverInstrumentKind indicates an ValueObserver instrument. | ||||
| 	ValueObserverInstrumentKind | ||||
|  | ||||
| 	// CounterInstrumentKind indicates a Counter instrument. | ||||
| 	CounterInstrumentKind | ||||
| 	// UpDownCounterInstrumentKind indicates a UpDownCounter instrument. | ||||
| 	UpDownCounterInstrumentKind | ||||
|  | ||||
| 	// SumObserverInstrumentKind indicates a SumObserver instrument. | ||||
| 	SumObserverInstrumentKind | ||||
| 	// UpDownSumObserverInstrumentKind indicates a UpDownSumObserver | ||||
| 	// instrument. | ||||
| 	UpDownSumObserverInstrumentKind | ||||
| ) | ||||
|  | ||||
| // Synchronous returns whether this is a synchronous kind of instrument. | ||||
| func (k InstrumentKind) Synchronous() bool { | ||||
| 	switch k { | ||||
| 	case CounterInstrumentKind, UpDownCounterInstrumentKind, ValueRecorderInstrumentKind: | ||||
| 		return true | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| // Asynchronous returns whether this is an asynchronous kind of instrument. | ||||
| func (k InstrumentKind) Asynchronous() bool { | ||||
| 	return !k.Synchronous() | ||||
| } | ||||
|  | ||||
| // Adding returns whether this kind of instrument adds its inputs (as opposed to Grouping). | ||||
| func (k InstrumentKind) Adding() bool { | ||||
| 	switch k { | ||||
| 	case CounterInstrumentKind, UpDownCounterInstrumentKind, SumObserverInstrumentKind, UpDownSumObserverInstrumentKind: | ||||
| 		return true | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| // Grouping returns whether this kind of instrument groups its inputs (as opposed to Adding). | ||||
| func (k InstrumentKind) Grouping() bool { | ||||
| 	return !k.Adding() | ||||
| } | ||||
|  | ||||
| // Monotonic returns whether this kind of instrument exposes a non-decreasing sum. | ||||
| func (k InstrumentKind) Monotonic() bool { | ||||
| 	switch k { | ||||
| 	case CounterInstrumentKind, SumObserverInstrumentKind: | ||||
| 		return true | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| // PrecomputedSum returns whether this kind of instrument receives precomputed sums. | ||||
| func (k InstrumentKind) PrecomputedSum() bool { | ||||
| 	return k.Adding() && k.Asynchronous() | ||||
| } | ||||
| @@ -1,6 +1,6 @@ | ||||
| // Code generated by "stringer -type=InstrumentKind"; DO NOT EDIT. | ||||
| 
 | ||||
| package metric | ||||
| package sdkapi | ||||
| 
 | ||||
| import "strconv" | ||||
| 
 | ||||
							
								
								
									
										32
									
								
								metric/sdkapi/instrumentkind_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								metric/sdkapi/instrumentkind_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| // Copyright The OpenTelemetry Authors | ||||
| // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | ||||
| // | ||||
| //     http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | ||||
| // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| package sdkapi_test | ||||
|  | ||||
| import ( | ||||
| 	"testing" | ||||
|  | ||||
| 	"github.com/stretchr/testify/require" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| ) | ||||
|  | ||||
| func TestInstrumentKinds(t *testing.T) { | ||||
| 	require.Equal(t, sdkapi.ValueRecorderInstrumentKind.String(), "ValueRecorderInstrumentKind") | ||||
| 	require.Equal(t, sdkapi.ValueObserverInstrumentKind.String(), "ValueObserverInstrumentKind") | ||||
| 	require.Equal(t, sdkapi.CounterInstrumentKind.String(), "CounterInstrumentKind") | ||||
| 	require.Equal(t, sdkapi.UpDownCounterInstrumentKind.String(), "UpDownCounterInstrumentKind") | ||||
| 	require.Equal(t, sdkapi.SumObserverInstrumentKind.String(), "SumObserverInstrumentKind") | ||||
| 	require.Equal(t, sdkapi.UpDownSumObserverInstrumentKind.String(), "UpDownSumObserverInstrumentKind") | ||||
| } | ||||
| @@ -21,6 +21,7 @@ import ( | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	"go.opentelemetry.io/otel/sdk/export/metric/aggregation" | ||||
| ) | ||||
|  | ||||
| @@ -29,16 +30,16 @@ func TestExportKindIncludes(t *testing.T) { | ||||
| 	require.True(t, DeltaExportKind.Includes(CumulativeExportKind|DeltaExportKind)) | ||||
| } | ||||
|  | ||||
| var deltaMemoryKinds = []metric.InstrumentKind{ | ||||
| 	metric.SumObserverInstrumentKind, | ||||
| 	metric.UpDownSumObserverInstrumentKind, | ||||
| var deltaMemoryKinds = []sdkapi.InstrumentKind{ | ||||
| 	sdkapi.SumObserverInstrumentKind, | ||||
| 	sdkapi.UpDownSumObserverInstrumentKind, | ||||
| } | ||||
|  | ||||
| var cumulativeMemoryKinds = []metric.InstrumentKind{ | ||||
| 	metric.ValueRecorderInstrumentKind, | ||||
| 	metric.ValueObserverInstrumentKind, | ||||
| 	metric.CounterInstrumentKind, | ||||
| 	metric.UpDownCounterInstrumentKind, | ||||
| var cumulativeMemoryKinds = []sdkapi.InstrumentKind{ | ||||
| 	sdkapi.ValueRecorderInstrumentKind, | ||||
| 	sdkapi.ValueObserverInstrumentKind, | ||||
| 	sdkapi.CounterInstrumentKind, | ||||
| 	sdkapi.UpDownCounterInstrumentKind, | ||||
| } | ||||
|  | ||||
| func TestExportKindMemoryRequired(t *testing.T) { | ||||
|   | ||||
| @@ -24,6 +24,7 @@ import ( | ||||
| 	"go.opentelemetry.io/otel/attribute" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	"go.opentelemetry.io/otel/sdk/export/metric/aggregation" | ||||
| 	"go.opentelemetry.io/otel/sdk/resource" | ||||
| ) | ||||
| @@ -379,14 +380,14 @@ func (kind ExportKind) Includes(has ExportKind) bool { | ||||
|  | ||||
| // MemoryRequired returns whether an exporter of this kind requires | ||||
| // memory to export correctly. | ||||
| func (kind ExportKind) MemoryRequired(mkind metric.InstrumentKind) bool { | ||||
| func (kind ExportKind) MemoryRequired(mkind sdkapi.InstrumentKind) bool { | ||||
| 	switch mkind { | ||||
| 	case metric.ValueRecorderInstrumentKind, metric.ValueObserverInstrumentKind, | ||||
| 		metric.CounterInstrumentKind, metric.UpDownCounterInstrumentKind: | ||||
| 	case sdkapi.ValueRecorderInstrumentKind, sdkapi.ValueObserverInstrumentKind, | ||||
| 		sdkapi.CounterInstrumentKind, sdkapi.UpDownCounterInstrumentKind: | ||||
| 		// Delta-oriented instruments: | ||||
| 		return kind.Includes(CumulativeExportKind) | ||||
|  | ||||
| 	case metric.SumObserverInstrumentKind, metric.UpDownSumObserverInstrumentKind: | ||||
| 	case sdkapi.SumObserverInstrumentKind, sdkapi.UpDownSumObserverInstrumentKind: | ||||
| 		// Cumulative-oriented instruments: | ||||
| 		return kind.Includes(DeltaExportKind) | ||||
| 	} | ||||
|   | ||||
| @@ -20,6 +20,7 @@ import ( | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| 	"go.opentelemetry.io/otel/sdk/export/metric/aggregation" | ||||
| ) | ||||
| @@ -43,7 +44,7 @@ func RangeTest(num number.Number, descriptor *metric.Descriptor) error { | ||||
| 	} | ||||
|  | ||||
| 	switch descriptor.InstrumentKind() { | ||||
| 	case metric.CounterInstrumentKind, metric.SumObserverInstrumentKind: | ||||
| 	case sdkapi.CounterInstrumentKind, sdkapi.SumObserverInstrumentKind: | ||||
| 		if num.IsNegative(numberKind) { | ||||
| 			return aggregation.ErrNegativeInput | ||||
| 		} | ||||
|   | ||||
| @@ -23,6 +23,7 @@ import ( | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	"go.opentelemetry.io/otel/sdk/export/metric/aggregation" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric/aggregator" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue" | ||||
| @@ -75,7 +76,7 @@ func TestRangeTest(t *testing.T) { | ||||
| 		t.Run(nkind.String(), func(t *testing.T) { | ||||
| 			desc := metric.NewDescriptor( | ||||
| 				"name", | ||||
| 				metric.CounterInstrumentKind, | ||||
| 				sdkapi.CounterInstrumentKind, | ||||
| 				nkind, | ||||
| 			) | ||||
| 			testRangeNegative(t, &desc) | ||||
| @@ -86,10 +87,10 @@ func TestRangeTest(t *testing.T) { | ||||
| func TestNaNTest(t *testing.T) { | ||||
| 	for _, nkind := range []number.Kind{number.Float64Kind, number.Int64Kind} { | ||||
| 		t.Run(nkind.String(), func(t *testing.T) { | ||||
| 			for _, mkind := range []metric.InstrumentKind{ | ||||
| 				metric.CounterInstrumentKind, | ||||
| 				metric.ValueRecorderInstrumentKind, | ||||
| 				metric.ValueObserverInstrumentKind, | ||||
| 			for _, mkind := range []sdkapi.InstrumentKind{ | ||||
| 				sdkapi.CounterInstrumentKind, | ||||
| 				sdkapi.ValueRecorderInstrumentKind, | ||||
| 				sdkapi.ValueObserverInstrumentKind, | ||||
| 			} { | ||||
| 				desc := metric.NewDescriptor( | ||||
| 					"name", | ||||
|   | ||||
| @@ -28,6 +28,7 @@ import ( | ||||
| 	ottest "go.opentelemetry.io/otel/internal/internaltest" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| 	"go.opentelemetry.io/otel/sdk/export/metric/aggregation" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric/aggregator" | ||||
| @@ -64,7 +65,7 @@ func newProfiles() []Profile { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func NewAggregatorTest(mkind metric.InstrumentKind, nkind number.Kind) *metric.Descriptor { | ||||
| func NewAggregatorTest(mkind sdkapi.InstrumentKind, nkind number.Kind) *metric.Descriptor { | ||||
| 	desc := metric.NewDescriptor("test.name", mkind, nkind) | ||||
| 	return &desc | ||||
| } | ||||
| @@ -191,7 +192,7 @@ func (NoopAggregator) Merge(export.Aggregator, *metric.Descriptor) error { | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func SynchronizedMoveResetTest(t *testing.T, mkind metric.InstrumentKind, nf func(*metric.Descriptor) export.Aggregator) { | ||||
| func SynchronizedMoveResetTest(t *testing.T, mkind sdkapi.InstrumentKind, nf func(*metric.Descriptor) export.Aggregator) { | ||||
| 	t.Run("reset on nil", func(t *testing.T) { | ||||
| 		// Ensures that SynchronizedMove(nil, descriptor) discards and | ||||
| 		// resets the aggregator. | ||||
|   | ||||
| @@ -24,6 +24,7 @@ import ( | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| 	"go.opentelemetry.io/otel/sdk/export/metric/aggregation" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric/aggregator/aggregatortest" | ||||
| @@ -66,7 +67,7 @@ func sumOf(samples []aggregation.Point, k number.Kind) number.Number { | ||||
| } | ||||
|  | ||||
| func (ut *updateTest) run(t *testing.T, profile aggregatortest.Profile) { | ||||
| 	descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
| 	descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
| 	agg, ckpt := new2() | ||||
|  | ||||
| 	all := aggregatortest.NewNumbers(profile.NumberKind) | ||||
| @@ -128,7 +129,7 @@ func advance() { | ||||
| } | ||||
|  | ||||
| func (mt *mergeTest) run(t *testing.T, profile aggregatortest.Profile) { | ||||
| 	descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
| 	descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
| 	agg1, agg2, ckpt1, ckpt2 := new4() | ||||
|  | ||||
| 	all := aggregatortest.NewNumbers(profile.NumberKind) | ||||
| @@ -214,7 +215,7 @@ func TestExactErrors(t *testing.T) { | ||||
| 	aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { | ||||
| 		agg, ckpt := new2() | ||||
|  | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
|  | ||||
| 		advance() | ||||
| 		aggregatortest.CheckedUpdate(t, agg, number.Number(0), descriptor) | ||||
| @@ -232,7 +233,7 @@ func TestExactErrors(t *testing.T) { | ||||
| } | ||||
|  | ||||
| func TestExactFloat64(t *testing.T) { | ||||
| 	descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, number.Float64Kind) | ||||
| 	descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, number.Float64Kind) | ||||
|  | ||||
| 	fpsf := func(sign int) []float64 { | ||||
| 		// Check behavior of a bunch of odd floating | ||||
| @@ -310,7 +311,7 @@ func TestExactFloat64(t *testing.T) { | ||||
| func TestSynchronizedMoveReset(t *testing.T) { | ||||
| 	aggregatortest.SynchronizedMoveResetTest( | ||||
| 		t, | ||||
| 		metric.ValueRecorderInstrumentKind, | ||||
| 		sdkapi.ValueRecorderInstrumentKind, | ||||
| 		func(desc *metric.Descriptor) export.Aggregator { | ||||
| 			return &New(1)[0] | ||||
| 		}, | ||||
| @@ -321,7 +322,7 @@ func TestMergeBehavior(t *testing.T) { | ||||
| 	aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { | ||||
| 		for _, forward := range []bool{false, true} { | ||||
| 			t.Run(fmt.Sprint("Forward=", forward), func(t *testing.T) { | ||||
| 				descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
| 				descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
| 				agg1, agg2, ckpt, _ := new4() | ||||
|  | ||||
| 				all := aggregatortest.NewNumbers(profile.NumberKind) | ||||
|   | ||||
| @@ -19,8 +19,8 @@ import ( | ||||
| 	"math/rand" | ||||
| 	"testing" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric/aggregator/aggregatortest" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram" | ||||
| ) | ||||
| @@ -38,7 +38,7 @@ func benchmarkHistogramSearchFloat64(b *testing.B, size int) { | ||||
| 	for i := range values { | ||||
| 		values[i] = rand.Float64() * inputRange | ||||
| 	} | ||||
| 	desc := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, number.Float64Kind) | ||||
| 	desc := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, number.Float64Kind) | ||||
| 	agg := &histogram.New(1, desc, histogram.WithExplicitBoundaries(boundaries))[0] | ||||
| 	ctx := context.Background() | ||||
|  | ||||
| @@ -89,7 +89,7 @@ func benchmarkHistogramSearchInt64(b *testing.B, size int) { | ||||
| 	for i := range values { | ||||
| 		values[i] = int64(rand.Float64() * inputRange) | ||||
| 	} | ||||
| 	desc := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, number.Int64Kind) | ||||
| 	desc := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, number.Int64Kind) | ||||
| 	agg := &histogram.New(1, desc, histogram.WithExplicitBoundaries(boundaries))[0] | ||||
| 	ctx := context.Background() | ||||
|  | ||||
|   | ||||
| @@ -25,6 +25,7 @@ import ( | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric/aggregator/aggregatortest" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram" | ||||
| @@ -111,7 +112,7 @@ func TestHistogramPositiveAndNegative(t *testing.T) { | ||||
|  | ||||
| // Validates count, sum and buckets for a given profile and policy | ||||
| func testHistogram(t *testing.T, profile aggregatortest.Profile, policy policy) { | ||||
| 	descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
| 	descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
|  | ||||
| 	agg, ckpt := new2(descriptor, histogram.WithExplicitBoundaries(testBoundaries)) | ||||
|  | ||||
| @@ -137,7 +138,7 @@ func testHistogram(t *testing.T, profile aggregatortest.Profile, policy policy) | ||||
|  | ||||
| func TestHistogramInitial(t *testing.T) { | ||||
| 	aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
|  | ||||
| 		agg := &histogram.New(1, descriptor, histogram.WithExplicitBoundaries(testBoundaries))[0] | ||||
| 		buckets, err := agg.Histogram() | ||||
| @@ -150,7 +151,7 @@ func TestHistogramInitial(t *testing.T) { | ||||
|  | ||||
| func TestHistogramMerge(t *testing.T) { | ||||
| 	aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
|  | ||||
| 		agg1, agg2, ckpt1, ckpt2 := new4(descriptor, histogram.WithExplicitBoundaries(testBoundaries)) | ||||
|  | ||||
| @@ -178,7 +179,7 @@ func TestHistogramMerge(t *testing.T) { | ||||
|  | ||||
| func TestHistogramNotSet(t *testing.T) { | ||||
| 	aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
|  | ||||
| 		agg, ckpt := new2(descriptor, histogram.WithExplicitBoundaries(testBoundaries)) | ||||
|  | ||||
| @@ -239,7 +240,7 @@ func checkHistogram(t *testing.T, all aggregatortest.Numbers, profile aggregator | ||||
| func TestSynchronizedMoveReset(t *testing.T) { | ||||
| 	aggregatortest.SynchronizedMoveResetTest( | ||||
| 		t, | ||||
| 		metric.ValueRecorderInstrumentKind, | ||||
| 		sdkapi.ValueRecorderInstrumentKind, | ||||
| 		func(desc *metric.Descriptor) export.Aggregator { | ||||
| 			return &histogram.New(1, desc, histogram.WithExplicitBoundaries(testBoundaries))[0] | ||||
| 		}, | ||||
| @@ -249,7 +250,7 @@ func TestSynchronizedMoveReset(t *testing.T) { | ||||
| func TestHistogramDefaultBoundaries(t *testing.T) { | ||||
| 	aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { | ||||
| 		ctx := context.Background() | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
|  | ||||
| 		agg, ckpt := new2(descriptor) | ||||
|  | ||||
|   | ||||
| @@ -27,6 +27,7 @@ import ( | ||||
| 	ottest "go.opentelemetry.io/otel/internal/internaltest" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| 	"go.opentelemetry.io/otel/sdk/export/metric/aggregation" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric/aggregator/aggregatortest" | ||||
| @@ -72,7 +73,7 @@ func TestLastValueUpdate(t *testing.T) { | ||||
| 	aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { | ||||
| 		agg, ckpt := new2() | ||||
|  | ||||
| 		record := aggregatortest.NewAggregatorTest(metric.ValueObserverInstrumentKind, profile.NumberKind) | ||||
| 		record := aggregatortest.NewAggregatorTest(sdkapi.ValueObserverInstrumentKind, profile.NumberKind) | ||||
|  | ||||
| 		var last number.Number | ||||
| 		for i := 0; i < count; i++ { | ||||
| @@ -94,7 +95,7 @@ func TestLastValueMerge(t *testing.T) { | ||||
| 	aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { | ||||
| 		agg1, agg2, ckpt1, ckpt2 := new4() | ||||
|  | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(metric.ValueObserverInstrumentKind, profile.NumberKind) | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueObserverInstrumentKind, profile.NumberKind) | ||||
|  | ||||
| 		first1 := profile.Random(+1) | ||||
| 		first2 := profile.Random(+1) | ||||
| @@ -127,7 +128,7 @@ func TestLastValueMerge(t *testing.T) { | ||||
| } | ||||
|  | ||||
| func TestLastValueNotSet(t *testing.T) { | ||||
| 	descriptor := aggregatortest.NewAggregatorTest(metric.ValueObserverInstrumentKind, number.Int64Kind) | ||||
| 	descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueObserverInstrumentKind, number.Int64Kind) | ||||
|  | ||||
| 	g, ckpt := new2() | ||||
| 	require.NoError(t, g.SynchronizedMove(ckpt, descriptor)) | ||||
| @@ -138,7 +139,7 @@ func TestLastValueNotSet(t *testing.T) { | ||||
| func TestSynchronizedMoveReset(t *testing.T) { | ||||
| 	aggregatortest.SynchronizedMoveResetTest( | ||||
| 		t, | ||||
| 		metric.ValueObserverInstrumentKind, | ||||
| 		sdkapi.ValueObserverInstrumentKind, | ||||
| 		func(desc *metric.Descriptor) export.Aggregator { | ||||
| 			return &New(1)[0] | ||||
| 		}, | ||||
|   | ||||
| @@ -24,6 +24,7 @@ import ( | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| 	"go.opentelemetry.io/otel/sdk/export/metric/aggregation" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric/aggregator/aggregatortest" | ||||
| @@ -110,7 +111,7 @@ func checkZero(t *testing.T, agg *Aggregator, desc *metric.Descriptor) { | ||||
|  | ||||
| // Validates min, max, sum and count for a given profile and policy | ||||
| func minMaxSumCount(t *testing.T, profile aggregatortest.Profile, policy policy) { | ||||
| 	descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
| 	descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
|  | ||||
| 	agg, ckpt := new2(descriptor) | ||||
|  | ||||
| @@ -158,7 +159,7 @@ func minMaxSumCount(t *testing.T, profile aggregatortest.Profile, policy policy) | ||||
|  | ||||
| func TestMinMaxSumCountMerge(t *testing.T) { | ||||
| 	aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
|  | ||||
| 		agg1, agg2, ckpt1, ckpt2 := new4(descriptor) | ||||
|  | ||||
| @@ -216,7 +217,7 @@ func TestMinMaxSumCountMerge(t *testing.T) { | ||||
|  | ||||
| func TestMaxSumCountNotSet(t *testing.T) { | ||||
| 	aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
|  | ||||
| 		alloc := New(2, descriptor) | ||||
| 		agg, ckpt := &alloc[0], &alloc[1] | ||||
| @@ -240,7 +241,7 @@ func TestMaxSumCountNotSet(t *testing.T) { | ||||
| func TestSynchronizedMoveReset(t *testing.T) { | ||||
| 	aggregatortest.SynchronizedMoveResetTest( | ||||
| 		t, | ||||
| 		metric.ValueRecorderInstrumentKind, | ||||
| 		sdkapi.ValueRecorderInstrumentKind, | ||||
| 		func(desc *metric.Descriptor) export.Aggregator { | ||||
| 			return &New(1, desc)[0] | ||||
| 		}, | ||||
|   | ||||
| @@ -24,6 +24,7 @@ import ( | ||||
| 	ottest "go.opentelemetry.io/otel/internal/internaltest" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric/aggregator/aggregatortest" | ||||
| ) | ||||
| @@ -67,7 +68,7 @@ func TestCounterSum(t *testing.T) { | ||||
| 	aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { | ||||
| 		agg, ckpt := new2() | ||||
|  | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(metric.CounterInstrumentKind, profile.NumberKind) | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(sdkapi.CounterInstrumentKind, profile.NumberKind) | ||||
|  | ||||
| 		sum := number.Number(0) | ||||
| 		for i := 0; i < count; i++ { | ||||
| @@ -91,7 +92,7 @@ func TestValueRecorderSum(t *testing.T) { | ||||
| 	aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { | ||||
| 		agg, ckpt := new2() | ||||
|  | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind) | ||||
|  | ||||
| 		sum := number.Number(0) | ||||
|  | ||||
| @@ -117,7 +118,7 @@ func TestCounterMerge(t *testing.T) { | ||||
| 	aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { | ||||
| 		agg1, agg2, ckpt1, ckpt2 := new4() | ||||
|  | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(metric.CounterInstrumentKind, profile.NumberKind) | ||||
| 		descriptor := aggregatortest.NewAggregatorTest(sdkapi.CounterInstrumentKind, profile.NumberKind) | ||||
|  | ||||
| 		sum := number.Number(0) | ||||
| 		for i := 0; i < count; i++ { | ||||
| @@ -146,7 +147,7 @@ func TestCounterMerge(t *testing.T) { | ||||
| func TestSynchronizedMoveReset(t *testing.T) { | ||||
| 	aggregatortest.SynchronizedMoveResetTest( | ||||
| 		t, | ||||
| 		metric.SumObserverInstrumentKind, | ||||
| 		sdkapi.SumObserverInstrumentKind, | ||||
| 		func(desc *metric.Descriptor) export.Aggregator { | ||||
| 			return &New(1)[0] | ||||
| 		}, | ||||
|   | ||||
| @@ -24,11 +24,12 @@ import ( | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram" | ||||
| ) | ||||
|  | ||||
| func TestStressInt64Histogram(t *testing.T) { | ||||
| 	desc := metric.NewDescriptor("some_metric", metric.ValueRecorderInstrumentKind, number.Int64Kind) | ||||
| 	desc := metric.NewDescriptor("some_metric", sdkapi.ValueRecorderInstrumentKind, number.Int64Kind) | ||||
|  | ||||
| 	alloc := histogram.New(2, &desc, histogram.WithExplicitBoundaries([]float64{25, 50, 75})) | ||||
| 	h, ckpt := &alloc[0], &alloc[1] | ||||
|   | ||||
| @@ -22,11 +22,12 @@ import ( | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount" | ||||
| ) | ||||
|  | ||||
| func TestStressInt64MinMaxSumCount(t *testing.T) { | ||||
| 	desc := metric.NewDescriptor("some_metric", metric.ValueRecorderInstrumentKind, number.Int64Kind) | ||||
| 	desc := metric.NewDescriptor("some_metric", sdkapi.ValueRecorderInstrumentKind, number.Int64Kind) | ||||
| 	alloc := minmaxsumcount.New(2, &desc) | ||||
| 	mmsc, ckpt := &alloc[0], &alloc[1] | ||||
|  | ||||
|   | ||||
| @@ -27,6 +27,7 @@ import ( | ||||
| 	"go.opentelemetry.io/otel/attribute" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| 	"go.opentelemetry.io/otel/sdk/export/metric/aggregation" | ||||
| 	sdk "go.opentelemetry.io/otel/sdk/metric" | ||||
| @@ -47,7 +48,7 @@ func TestProcessor(t *testing.T) { | ||||
| 		kind export.ExportKind | ||||
| 	} | ||||
| 	type instrumentCase struct { | ||||
| 		kind metric.InstrumentKind | ||||
| 		kind sdkapi.InstrumentKind | ||||
| 	} | ||||
| 	type numberCase struct { | ||||
| 		kind number.Kind | ||||
| @@ -62,12 +63,12 @@ func TestProcessor(t *testing.T) { | ||||
| 	} { | ||||
| 		t.Run(tc.kind.String(), func(t *testing.T) { | ||||
| 			for _, ic := range []instrumentCase{ | ||||
| 				{kind: metric.CounterInstrumentKind}, | ||||
| 				{kind: metric.UpDownCounterInstrumentKind}, | ||||
| 				{kind: metric.ValueRecorderInstrumentKind}, | ||||
| 				{kind: metric.SumObserverInstrumentKind}, | ||||
| 				{kind: metric.UpDownSumObserverInstrumentKind}, | ||||
| 				{kind: metric.ValueObserverInstrumentKind}, | ||||
| 				{kind: sdkapi.CounterInstrumentKind}, | ||||
| 				{kind: sdkapi.UpDownCounterInstrumentKind}, | ||||
| 				{kind: sdkapi.ValueRecorderInstrumentKind}, | ||||
| 				{kind: sdkapi.SumObserverInstrumentKind}, | ||||
| 				{kind: sdkapi.UpDownSumObserverInstrumentKind}, | ||||
| 				{kind: sdkapi.ValueObserverInstrumentKind}, | ||||
| 			} { | ||||
| 				t.Run(ic.kind.String(), func(t *testing.T) { | ||||
| 					for _, nc := range []numberCase{ | ||||
| @@ -119,7 +120,7 @@ func updateFor(t *testing.T, desc *metric.Descriptor, selector export.Aggregator | ||||
| func testProcessor( | ||||
| 	t *testing.T, | ||||
| 	ekind export.ExportKind, | ||||
| 	mkind metric.InstrumentKind, | ||||
| 	mkind sdkapi.InstrumentKind, | ||||
| 	nkind number.Kind, | ||||
| 	akind aggregation.Kind, | ||||
| ) { | ||||
| @@ -300,7 +301,7 @@ func TestBasicInconsistent(t *testing.T) { | ||||
| 	// Test no start | ||||
| 	b = basic.New(processorTest.AggregatorSelector(), export.StatelessExportKindSelector()) | ||||
|  | ||||
| 	desc := metric.NewDescriptor("inst", metric.CounterInstrumentKind, number.Int64Kind) | ||||
| 	desc := metric.NewDescriptor("inst", sdkapi.CounterInstrumentKind, number.Int64Kind) | ||||
| 	accum := export.NewAccumulation(&desc, attribute.EmptySet(), resource.Empty(), aggregatortest.NoopAggregator{}) | ||||
| 	require.Equal(t, basic.ErrInconsistentState, b.Process(accum)) | ||||
|  | ||||
| @@ -325,7 +326,7 @@ func TestBasicTimestamps(t *testing.T) { | ||||
| 	time.Sleep(time.Nanosecond) | ||||
| 	afterNew := time.Now() | ||||
|  | ||||
| 	desc := metric.NewDescriptor("inst", metric.CounterInstrumentKind, number.Int64Kind) | ||||
| 	desc := metric.NewDescriptor("inst", sdkapi.CounterInstrumentKind, number.Int64Kind) | ||||
| 	accum := export.NewAccumulation(&desc, attribute.EmptySet(), resource.Empty(), aggregatortest.NoopAggregator{}) | ||||
|  | ||||
| 	b.StartCollection() | ||||
| @@ -371,7 +372,7 @@ func TestStatefulNoMemoryCumulative(t *testing.T) { | ||||
| 	res := resource.NewSchemaless(attribute.String("R", "V")) | ||||
| 	ekindSel := export.CumulativeExportKindSelector() | ||||
|  | ||||
| 	desc := metric.NewDescriptor("inst.sum", metric.CounterInstrumentKind, number.Int64Kind) | ||||
| 	desc := metric.NewDescriptor("inst.sum", sdkapi.CounterInstrumentKind, number.Int64Kind) | ||||
| 	selector := processorTest.AggregatorSelector() | ||||
|  | ||||
| 	processor := basic.New(selector, ekindSel, basic.WithMemory(false)) | ||||
| @@ -405,7 +406,7 @@ func TestStatefulNoMemoryDelta(t *testing.T) { | ||||
| 	res := resource.NewSchemaless(attribute.String("R", "V")) | ||||
| 	ekindSel := export.DeltaExportKindSelector() | ||||
|  | ||||
| 	desc := metric.NewDescriptor("inst.sum", metric.SumObserverInstrumentKind, number.Int64Kind) | ||||
| 	desc := metric.NewDescriptor("inst.sum", sdkapi.SumObserverInstrumentKind, number.Int64Kind) | ||||
| 	selector := processorTest.AggregatorSelector() | ||||
|  | ||||
| 	processor := basic.New(selector, ekindSel, basic.WithMemory(false)) | ||||
| @@ -442,7 +443,7 @@ func TestMultiObserverSum(t *testing.T) { | ||||
| 	} { | ||||
|  | ||||
| 		res := resource.NewSchemaless(attribute.String("R", "V")) | ||||
| 		desc := metric.NewDescriptor("observe.sum", metric.SumObserverInstrumentKind, number.Int64Kind) | ||||
| 		desc := metric.NewDescriptor("observe.sum", sdkapi.SumObserverInstrumentKind, number.Int64Kind) | ||||
| 		selector := processorTest.AggregatorSelector() | ||||
|  | ||||
| 		processor := basic.New(selector, ekindSel, basic.WithMemory(false)) | ||||
|   | ||||
| @@ -16,6 +16,7 @@ package simple // import "go.opentelemetry.io/otel/sdk/metric/selector/simple" | ||||
|  | ||||
| import ( | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric/aggregator/exact" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram" | ||||
| @@ -79,9 +80,9 @@ func lastValueAggs(aggPtrs []*export.Aggregator) { | ||||
|  | ||||
| func (selectorInexpensive) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) { | ||||
| 	switch descriptor.InstrumentKind() { | ||||
| 	case metric.ValueObserverInstrumentKind: | ||||
| 	case sdkapi.ValueObserverInstrumentKind: | ||||
| 		lastValueAggs(aggPtrs) | ||||
| 	case metric.ValueRecorderInstrumentKind: | ||||
| 	case sdkapi.ValueRecorderInstrumentKind: | ||||
| 		aggs := minmaxsumcount.New(len(aggPtrs), descriptor) | ||||
| 		for i := range aggPtrs { | ||||
| 			*aggPtrs[i] = &aggs[i] | ||||
| @@ -93,9 +94,9 @@ func (selectorInexpensive) AggregatorFor(descriptor *metric.Descriptor, aggPtrs | ||||
|  | ||||
| func (selectorExact) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) { | ||||
| 	switch descriptor.InstrumentKind() { | ||||
| 	case metric.ValueObserverInstrumentKind: | ||||
| 	case sdkapi.ValueObserverInstrumentKind: | ||||
| 		lastValueAggs(aggPtrs) | ||||
| 	case metric.ValueRecorderInstrumentKind: | ||||
| 	case sdkapi.ValueRecorderInstrumentKind: | ||||
| 		aggs := exact.New(len(aggPtrs)) | ||||
| 		for i := range aggPtrs { | ||||
| 			*aggPtrs[i] = &aggs[i] | ||||
| @@ -107,9 +108,9 @@ func (selectorExact) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*ex | ||||
|  | ||||
| func (s selectorHistogram) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) { | ||||
| 	switch descriptor.InstrumentKind() { | ||||
| 	case metric.ValueObserverInstrumentKind: | ||||
| 	case sdkapi.ValueObserverInstrumentKind: | ||||
| 		lastValueAggs(aggPtrs) | ||||
| 	case metric.ValueRecorderInstrumentKind: | ||||
| 	case sdkapi.ValueRecorderInstrumentKind: | ||||
| 		aggs := histogram.New(len(aggPtrs), descriptor, s.options...) | ||||
| 		for i := range aggPtrs { | ||||
| 			*aggPtrs[i] = &aggs[i] | ||||
|   | ||||
| @@ -21,6 +21,7 @@ import ( | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric/aggregator/exact" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram" | ||||
| @@ -31,12 +32,12 @@ import ( | ||||
| ) | ||||
|  | ||||
| var ( | ||||
| 	testCounterDesc           = metric.NewDescriptor("counter", metric.CounterInstrumentKind, number.Int64Kind) | ||||
| 	testUpDownCounterDesc     = metric.NewDescriptor("updowncounter", metric.UpDownCounterInstrumentKind, number.Int64Kind) | ||||
| 	testSumObserverDesc       = metric.NewDescriptor("sumobserver", metric.SumObserverInstrumentKind, number.Int64Kind) | ||||
| 	testUpDownSumObserverDesc = metric.NewDescriptor("updownsumobserver", metric.UpDownSumObserverInstrumentKind, number.Int64Kind) | ||||
| 	testValueRecorderDesc     = metric.NewDescriptor("valuerecorder", metric.ValueRecorderInstrumentKind, number.Int64Kind) | ||||
| 	testValueObserverDesc     = metric.NewDescriptor("valueobserver", metric.ValueObserverInstrumentKind, number.Int64Kind) | ||||
| 	testCounterDesc           = metric.NewDescriptor("counter", sdkapi.CounterInstrumentKind, number.Int64Kind) | ||||
| 	testUpDownCounterDesc     = metric.NewDescriptor("updowncounter", sdkapi.UpDownCounterInstrumentKind, number.Int64Kind) | ||||
| 	testSumObserverDesc       = metric.NewDescriptor("sumobserver", sdkapi.SumObserverInstrumentKind, number.Int64Kind) | ||||
| 	testUpDownSumObserverDesc = metric.NewDescriptor("updownsumobserver", sdkapi.UpDownSumObserverInstrumentKind, number.Int64Kind) | ||||
| 	testValueRecorderDesc     = metric.NewDescriptor("valuerecorder", sdkapi.ValueRecorderInstrumentKind, number.Int64Kind) | ||||
| 	testValueObserverDesc     = metric.NewDescriptor("valueobserver", sdkapi.ValueObserverInstrumentKind, number.Int64Kind) | ||||
| ) | ||||
|  | ||||
| func oneAgg(sel export.AggregatorSelector, desc *metric.Descriptor) export.Aggregator { | ||||
|   | ||||
| @@ -34,6 +34,7 @@ import ( | ||||
| 	"go.opentelemetry.io/otel/attribute" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| 	"go.opentelemetry.io/otel/metric/sdkapi" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| 	"go.opentelemetry.io/otel/sdk/export/metric/aggregation" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric/processor/processortest" | ||||
| @@ -265,13 +266,13 @@ func (f *testFixture) Process(accumulation export.Accumulation) error { | ||||
|  | ||||
| 	agg := accumulation.Aggregator() | ||||
| 	switch accumulation.Descriptor().InstrumentKind() { | ||||
| 	case metric.CounterInstrumentKind: | ||||
| 	case sdkapi.CounterInstrumentKind: | ||||
| 		sum, err := agg.(aggregation.Sum).Sum() | ||||
| 		if err != nil { | ||||
| 			f.T.Fatal("Sum error: ", err) | ||||
| 		} | ||||
| 		f.impl.storeCollect(actual, sum, time.Time{}) | ||||
| 	case metric.ValueRecorderInstrumentKind: | ||||
| 	case sdkapi.ValueRecorderInstrumentKind: | ||||
| 		lv, ts, err := agg.(aggregation.LastValue).LastValue() | ||||
| 		if err != nil && err != aggregation.ErrNoData { | ||||
| 			f.T.Fatal("Last value error: ", err) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user