metric.go raw

   1  // Copyright The OpenTelemetry Authors
   2  // SPDX-License-Identifier: Apache-2.0
   3  
   4  package otel // import "go.opentelemetry.io/otel"
   5  
   6  import (
   7  	"go.opentelemetry.io/otel/internal/global"
   8  	"go.opentelemetry.io/otel/metric"
   9  )
  10  
  11  // Meter returns a Meter from the global MeterProvider. The name must be the
  12  // name of the library providing instrumentation. This name may be the same as
  13  // the instrumented code only if that code provides built-in instrumentation.
  14  // If the name is empty, then a implementation defined default name will be
  15  // used instead.
  16  //
  17  // If this is called before a global MeterProvider is registered the returned
  18  // Meter will be a No-op implementation of a Meter. When a global MeterProvider
  19  // is registered for the first time, the returned Meter, and all the
  20  // instruments it has created or will create, are recreated automatically from
  21  // the new MeterProvider.
  22  //
  23  // This is short for GetMeterProvider().Meter(name).
  24  func Meter(name string, opts ...metric.MeterOption) metric.Meter {
  25  	return GetMeterProvider().Meter(name, opts...)
  26  }
  27  
  28  // GetMeterProvider returns the registered global meter provider.
  29  //
  30  // If no global GetMeterProvider has been registered, a No-op GetMeterProvider
  31  // implementation is returned. When a global GetMeterProvider is registered for
  32  // the first time, the returned GetMeterProvider, and all the Meters it has
  33  // created or will create, are recreated automatically from the new
  34  // GetMeterProvider.
  35  func GetMeterProvider() metric.MeterProvider {
  36  	return global.MeterProvider()
  37  }
  38  
  39  // SetMeterProvider registers mp as the global MeterProvider.
  40  func SetMeterProvider(mp metric.MeterProvider) {
  41  	global.SetMeterProvider(mp)
  42  }
  43