metric.go (2192B)
1 // Copyright The OpenTelemetry Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package otel // import "go.opentelemetry.io/otel" 16 17 import ( 18 "go.opentelemetry.io/otel/internal/global" 19 "go.opentelemetry.io/otel/metric" 20 ) 21 22 // Meter returns a Meter from the global MeterProvider. The name must be the 23 // name of the library providing instrumentation. This name may be the same as 24 // the instrumented code only if that code provides built-in instrumentation. 25 // If the name is empty, then a implementation defined default name will be 26 // used instead. 27 // 28 // If this is called before a global MeterProvider is registered the returned 29 // Meter will be a No-op implementation of a Meter. When a global MeterProvider 30 // is registered for the first time, the returned Meter, and all the 31 // instruments it has created or will create, are recreated automatically from 32 // the new MeterProvider. 33 // 34 // This is short for GetMeterProvider().Meter(name). 35 func Meter(name string, opts ...metric.MeterOption) metric.Meter { 36 return GetMeterProvider().Meter(name, opts...) 37 } 38 39 // GetMeterProvider returns the registered global meter provider. 40 // 41 // If no global GetMeterProvider has been registered, a No-op GetMeterProvider 42 // implementation is returned. When a global GetMeterProvider is registered for 43 // the first time, the returned GetMeterProvider, and all the Meters it has 44 // created or will create, are recreated automatically from the new 45 // GetMeterProvider. 46 func GetMeterProvider() metric.MeterProvider { 47 return global.MeterProvider() 48 } 49 50 // SetMeterProvider registers mp as the global MeterProvider. 51 func SetMeterProvider(mp metric.MeterProvider) { 52 global.SetMeterProvider(mp) 53 }