metric.go 1.6 KB

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