blob: f1695bb7aa06b41de001adaa6edbf190434a4053 [file] [log] [blame]
Joey Armstronga6af1522023-01-17 16:06:16 -05001// 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
15package global
16
17import (
18 "go.opentelemetry.io/otel/api/global/internal"
19 "go.opentelemetry.io/otel/api/metric"
20)
21
22// Meter creates an implementation of the Meter interface from the global
23// MeterProvider. The instrumentationName must be the name of the library
24// providing instrumentation. This name may be the same as the instrumented
25// code only if that code provides built-in instrumentation. If the
26// instrumentationName is empty, then a implementation defined default name
27// will be used instead.
28//
29// This is short for MeterProvider().Meter(name)
30func Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter {
31 return MeterProvider().Meter(instrumentationName, opts...)
32}
33
34// MeterProvider returns the registered global meter provider. If
35// none is registered then a default meter provider is returned that
36// forwards the Meter interface to the first registered Meter.
37//
38// Use the meter provider to create a named meter. E.g.
39// meter := global.MeterProvider().Meter("example.com/foo")
40// or
41// meter := global.Meter("example.com/foo")
42func MeterProvider() metric.MeterProvider {
43 return internal.MeterProvider()
44}
45
46// SetMeterProvider registers `mp` as the global meter provider.
47func SetMeterProvider(mp metric.MeterProvider) {
48 internal.SetMeterProvider(mp)
49}