// 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 metric // import "go.opentelemetry.io/otel/sdk/metric" import ( "context" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/instrument" "go.opentelemetry.io/otel/metric/instrument/asyncfloat64" "go.opentelemetry.io/otel/metric/instrument/asyncint64" "go.opentelemetry.io/otel/metric/instrument/syncfloat64" "go.opentelemetry.io/otel/metric/instrument/syncint64" "go.opentelemetry.io/otel/sdk/instrumentation" ) // meter handles the creation and coordination of all metric instruments. A // meter represents a single instrumentation scope; all metric telemetry // produced by an instrumentation scope will use metric instruments from a // single meter. type meter struct { instrumentation.Scope // *Resolvers are used by the provided instrument providers to resolve new // instruments aggregators and maintain a cache across instruments this // meter owns. int64Resolver resolver[int64] float64Resolver resolver[float64] pipes pipelines } func newMeter(s instrumentation.Scope, p pipelines) *meter { // viewCache ensures instrument conflicts, including number conflicts, this // meter is asked to create are logged to the user. var viewCache cache[string, instrumentID] // Passing nil as the ac parameter to newInstrumentCache will have each // create its own aggregator cache. ic := newInstrumentCache[int64](nil, &viewCache) fc := newInstrumentCache[float64](nil, &viewCache) return &meter{ Scope: s, pipes: p, int64Resolver: newResolver(p, ic), float64Resolver: newResolver(p, fc), } } // Compile-time check meter implements metric.Meter. var _ metric.Meter = (*meter)(nil) // AsyncInt64 returns the asynchronous integer instrument provider. func (m *meter) AsyncInt64() asyncint64.InstrumentProvider { return asyncInt64Provider{scope: m.Scope, resolve: &m.int64Resolver} } // AsyncFloat64 returns the asynchronous floating-point instrument provider. func (m *meter) AsyncFloat64() asyncfloat64.InstrumentProvider { return asyncFloat64Provider{scope: m.Scope, resolve: &m.float64Resolver} } // RegisterCallback registers the function f to be called when any of the // insts Collect method is called. func (m *meter) RegisterCallback(insts []instrument.Asynchronous, f func(context.Context)) error { m.pipes.registerCallback(f) return nil } // SyncInt64 returns the synchronous integer instrument provider. func (m *meter) SyncInt64() syncint64.InstrumentProvider { return syncInt64Provider{scope: m.Scope, resolve: &m.int64Resolver} } // SyncFloat64 returns the synchronous floating-point instrument provider. func (m *meter) SyncFloat64() syncfloat64.InstrumentProvider { return syncFloat64Provider{scope: m.Scope, resolve: &m.float64Resolver} }