2020-03-23 22:41:10 -07:00
|
|
|
// Copyright The OpenTelemetry Authors
|
2019-06-14 13:09:41 -07:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2020-11-16 18:30:54 +01:00
|
|
|
package otel // import "go.opentelemetry.io/otel"
|
2019-06-14 11:37:05 -07:00
|
|
|
|
2019-10-25 11:38:52 -07:00
|
|
|
import (
|
2020-11-16 18:30:54 +01:00
|
|
|
"go.opentelemetry.io/otel/internal/global"
|
2020-11-06 23:13:31 +01:00
|
|
|
"go.opentelemetry.io/otel/trace"
|
2019-10-25 11:38:52 -07:00
|
|
|
)
|
2019-06-14 11:37:05 -07:00
|
|
|
|
2020-03-11 12:23:32 -03:00
|
|
|
// Tracer creates a named tracer that implements Tracer interface.
|
|
|
|
// If the name is an empty string then provider uses default name.
|
|
|
|
//
|
2021-05-13 21:43:19 +00:00
|
|
|
// This is short for GetTracerProvider().Tracer(name, opts...)
|
|
|
|
func Tracer(name string, opts ...trace.TracerOption) trace.Tracer {
|
|
|
|
return GetTracerProvider().Tracer(name, opts...)
|
2020-03-11 12:23:32 -03:00
|
|
|
}
|
|
|
|
|
2021-01-07 02:17:36 +08:00
|
|
|
// GetTracerProvider returns the registered global trace provider.
|
2020-09-23 15:16:13 -07:00
|
|
|
// If none is registered then an instance of NoopTracerProvider is returned.
|
2019-12-23 23:03:04 -08:00
|
|
|
//
|
2019-10-22 13:19:11 -07:00
|
|
|
// Use the trace provider to create a named tracer. E.g.
|
2021-07-31 00:00:58 +09:00
|
|
|
// tracer := otel.GetTracerProvider().Tracer("example.com/foo")
|
2020-03-11 12:23:32 -03:00
|
|
|
// or
|
2021-07-31 00:00:58 +09:00
|
|
|
// tracer := otel.Tracer("example.com/foo")
|
2020-11-16 18:30:54 +01:00
|
|
|
func GetTracerProvider() trace.TracerProvider {
|
|
|
|
return global.TracerProvider()
|
2019-10-30 23:35:02 -07:00
|
|
|
}
|
|
|
|
|
2020-08-31 10:02:04 -07:00
|
|
|
// SetTracerProvider registers `tp` as the global trace provider.
|
2020-11-06 23:13:31 +01:00
|
|
|
func SetTracerProvider(tp trace.TracerProvider) {
|
2020-11-16 18:30:54 +01:00
|
|
|
global.SetTracerProvider(tp)
|
2019-10-30 23:35:02 -07:00
|
|
|
}
|