diff --git a/api/global/internal/meter.go b/api/global/internal/meter.go index b45f4c94490..f57d80e3a55 100644 --- a/api/global/internal/meter.go +++ b/api/global/internal/meter.go @@ -123,6 +123,9 @@ func (inst *instrument) Descriptor() metric.Descriptor { return inst.descriptor } +func (inst *instrument) Unref() { +} + // MeterProvider interface and delegation func newMeterProvider() *meterProvider { diff --git a/api/metric/metrictest/meter.go b/api/metric/metrictest/meter.go index 40524cac33c..83dd2253a3a 100644 --- a/api/metric/metrictest/meter.go +++ b/api/metric/metrictest/meter.go @@ -80,6 +80,9 @@ func (i Instrument) Descriptor() apimetric.Descriptor { return i.descriptor } +func (i Instrument) Unref() { +} + func (a *Async) Implementation() interface{} { return a } diff --git a/api/metric/noop.go b/api/metric/noop.go index 97867d9b7d6..5612cb1b74b 100644 --- a/api/metric/noop.go +++ b/api/metric/noop.go @@ -40,6 +40,9 @@ func (noopInstrument) Implementation() interface{} { return nil } +func (noopInstrument) Unref() { +} + func (noopInstrument) Descriptor() Descriptor { return Descriptor{} } diff --git a/api/metric/sdkapi.go b/api/metric/sdkapi.go index 122c9ba6d2f..48b952fa30d 100644 --- a/api/metric/sdkapi.go +++ b/api/metric/sdkapi.go @@ -50,6 +50,9 @@ type InstrumentImpl interface { // Descriptor returns a copy of the instrument's Descriptor. Descriptor() Descriptor + + // @@@ + Unref() } // SyncImpl is the implementation-level interface to a generic diff --git a/sdk/metric/sdk.go b/sdk/metric/sdk.go index 4e16f279828..da9625c8dc4 100644 --- a/sdk/metric/sdk.go +++ b/sdk/metric/sdk.go @@ -154,6 +154,10 @@ func (inst *instrument) Descriptor() api.Descriptor { return inst.descriptor } +func (inst *instrument) Unref() { + // This is a no-op for the standard Accumulator. +} + func (a *asyncInstrument) Implementation() interface{} { return a } diff --git a/sdk/metric/transient/transient.go b/sdk/metric/transient/transient.go new file mode 100644 index 00000000000..7d93f6a4bb1 --- /dev/null +++ b/sdk/metric/transient/transient.go @@ -0,0 +1,60 @@ +// 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 transient + +import ( + "context" + "fmt" + + "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/label" + export "go.opentelemetry.io/otel/sdk/export/metric" + sdk "go.opentelemetry.io/otel/sdk/metric" +) + +type Accumulator struct { + standard *sdk.Accumulator +} + +var ( + ErrAsyncNotSupported = fmt.Errorf("transient asynchronous instruments not supported") + + _ metric.MeterImpl = &Accumulator{} +) + +func NewAccumulator(processor export.Processor, opts ...sdk.Option) *Accumulator { + return &Accumulator{ + standard: sdk.NewAccumulator(processor, opts...), + } +} + +func (a *Accumulator) RecordBatch(ctx context.Context, labels []label.KeyValue, measurements ...metric.Measurement) { + a.standard.RecordBatch(ctx, labels, measurements...) +} + +func (a *Accumulator) NewSyncInstrument(descriptor metric.Descriptor) (metric.SyncImpl, error) { + return a.standard.NewSyncInstrument(descriptor) +} + +func (a *Accumulator) NewAsyncInstrument( + descriptor metric.Descriptor, + runner metric.AsyncRunner, +) (metric.AsyncImpl, error) { + return metric.NoopAsync{}, ErrAsyncNotSupported +} + +func (m *Accumulator) Collect(ctx context.Context) int { + return 0 +}