metric.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. package otel // import "go.opentelemetry.io/otel"
  15. import (
  16. "go.opentelemetry.io/otel/internal/global"
  17. "go.opentelemetry.io/otel/metric"
  18. )
  19. // Meter returns a Meter from the global MeterProvider. The name must be the
  20. // name of the library providing instrumentation. This name may be the same as
  21. // the instrumented code only if that code provides built-in instrumentation.
  22. // If the name is empty, then a implementation defined default name will be
  23. // used instead.
  24. //
  25. // If this is called before a global MeterProvider is registered the returned
  26. // Meter will be a No-op implementation of a Meter. When a global MeterProvider
  27. // is registered for the first time, the returned Meter, and all the
  28. // instruments it has created or will create, are recreated automatically from
  29. // the new MeterProvider.
  30. //
  31. // This is short for GetMeterProvider().Meter(name).
  32. func Meter(name string, opts ...metric.MeterOption) metric.Meter {
  33. return GetMeterProvider().Meter(name, opts...)
  34. }
  35. // GetMeterProvider returns the registered global meter provider.
  36. //
  37. // If no global GetMeterProvider has been registered, a No-op GetMeterProvider
  38. // implementation is returned. When a global GetMeterProvider is registered for
  39. // the first time, the returned GetMeterProvider, and all the Meters it has
  40. // created or will create, are recreated automatically from the new
  41. // GetMeterProvider.
  42. func GetMeterProvider() metric.MeterProvider {
  43. return global.MeterProvider()
  44. }
  45. // SetMeterProvider registers mp as the global MeterProvider.
  46. func SetMeterProvider(mp metric.MeterProvider) {
  47. global.SetMeterProvider(mp)
  48. }