2020-03-24 07:41:10 +02:00
|
|
|
// Copyright The OpenTelemetry Authors
|
2024-02-29 08:05:28 +02:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2019-06-14 22:09:41 +02:00
|
|
|
|
2020-11-16 19:30:54 +02:00
|
|
|
package otel // import "go.opentelemetry.io/otel"
|
2019-06-14 20:37:05 +02:00
|
|
|
|
2019-10-25 20:38:52 +02:00
|
|
|
import (
|
2020-11-16 19:30:54 +02:00
|
|
|
"go.opentelemetry.io/otel/internal/global"
|
2020-11-07 00:13:31 +02:00
|
|
|
"go.opentelemetry.io/otel/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.
|
|
|
|
//
|
2021-05-13 23:43:19 +02: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 17:23:32 +02:00
|
|
|
}
|
|
|
|
|
2021-01-06 20:17:36 +02:00
|
|
|
// GetTracerProvider returns the registered global trace provider.
|
2020-09-24 00:16:13 +02:00
|
|
|
// If none is registered then an instance of NoopTracerProvider 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.
|
2022-08-25 04:42:28 +02:00
|
|
|
//
|
|
|
|
// tracer := otel.GetTracerProvider().Tracer("example.com/foo")
|
|
|
|
//
|
2020-03-11 17:23:32 +02:00
|
|
|
// or
|
2022-08-25 04:42:28 +02:00
|
|
|
//
|
|
|
|
// tracer := otel.Tracer("example.com/foo")
|
2020-11-16 19:30:54 +02:00
|
|
|
func GetTracerProvider() trace.TracerProvider {
|
|
|
|
return global.TracerProvider()
|
2019-10-31 08:35:02 +02:00
|
|
|
}
|
|
|
|
|
2020-08-31 19:02:04 +02:00
|
|
|
// SetTracerProvider registers `tp` as the global trace provider.
|
2020-11-07 00:13:31 +02:00
|
|
|
func SetTracerProvider(tp trace.TracerProvider) {
|
2020-11-16 19:30:54 +02:00
|
|
|
global.SetTracerProvider(tp)
|
2019-10-31 08:35:02 +02:00
|
|
|
}
|