2020-03-24 07:41:10 +02:00
|
|
|
// Copyright The OpenTelemetry Authors
|
2019-06-14 22:09:41 +02: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.
|
|
|
|
|
2019-10-25 20:38:52 +02:00
|
|
|
package global
|
2019-06-14 20:37:05 +02:00
|
|
|
|
2019-10-25 20:38:52 +02:00
|
|
|
import (
|
2019-12-24 09:03:04 +02:00
|
|
|
"go.opentelemetry.io/otel/api/global/internal"
|
2019-11-01 20:40:29 +02:00
|
|
|
"go.opentelemetry.io/otel/api/trace"
|
2019-10-25 20:38:52 +02:00
|
|
|
)
|
2019-06-14 20:37:05 +02:00
|
|
|
|
2020-03-11 17:23:32 +02:00
|
|
|
// Tracer creates a named tracer that implements Tracer interface.
|
|
|
|
// If the name is an empty string then provider uses default name.
|
|
|
|
//
|
|
|
|
// This is short for TraceProvider().Tracer(name)
|
|
|
|
func Tracer(name string) trace.Tracer {
|
|
|
|
return TraceProvider().Tracer(name)
|
|
|
|
}
|
|
|
|
|
2019-10-25 20:38:52 +02:00
|
|
|
// TraceProvider returns the registered global trace provider.
|
2019-10-31 08:35:02 +02:00
|
|
|
// If none is registered then an instance of trace.NoopProvider is returned.
|
2019-12-24 09:03:04 +02:00
|
|
|
//
|
2019-10-22 22:19:11 +02:00
|
|
|
// Use the trace provider to create a named tracer. E.g.
|
2019-11-25 19:46:07 +02:00
|
|
|
// tracer := global.TraceProvider().Tracer("example.com/foo")
|
2020-03-11 17:23:32 +02:00
|
|
|
// or
|
|
|
|
// tracer := global.Tracer("example.com/foo")
|
2019-10-25 20:38:52 +02:00
|
|
|
func TraceProvider() trace.Provider {
|
2019-12-24 09:03:04 +02:00
|
|
|
return internal.TraceProvider()
|
2019-10-31 08:35:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetTraceProvider registers `tp` as the global trace provider.
|
|
|
|
func SetTraceProvider(tp trace.Provider) {
|
2019-12-24 09:03:04 +02:00
|
|
|
internal.SetTraceProvider(tp)
|
2019-10-31 08:35:02 +02:00
|
|
|
}
|