2021-08-09 07:19:24 +00:00
|
|
|
// Copyright The OpenTelemetry Authors
|
2024-08-19 08:01:33 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2021-08-09 07:19:24 +00:00
|
|
|
|
|
|
|
package otel // import "go.opentelemetry.io/otel"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go.opentelemetry.io/otel/internal/global"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Tracer creates a named tracer that implements Tracer interface.
|
|
|
|
// If the name is an empty string then provider uses default name.
|
|
|
|
//
|
2023-02-01 17:06:36 +00:00
|
|
|
// This is short for GetTracerProvider().Tracer(name, opts...)
|
|
|
|
func Tracer(name string, opts ...trace.TracerOption) trace.Tracer {
|
|
|
|
return GetTracerProvider().Tracer(name, opts...)
|
2021-08-09 07:19:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetTracerProvider returns the registered global trace provider.
|
|
|
|
// If none is registered then an instance of NoopTracerProvider is returned.
|
|
|
|
//
|
|
|
|
// Use the trace provider to create a named tracer. E.g.
|
2023-02-01 17:06:36 +00:00
|
|
|
//
|
|
|
|
// tracer := otel.GetTracerProvider().Tracer("example.com/foo")
|
|
|
|
//
|
2021-08-09 07:19:24 +00:00
|
|
|
// or
|
2023-02-01 17:06:36 +00:00
|
|
|
//
|
|
|
|
// tracer := otel.Tracer("example.com/foo")
|
2021-08-09 07:19:24 +00:00
|
|
|
func GetTracerProvider() trace.TracerProvider {
|
|
|
|
return global.TracerProvider()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTracerProvider registers `tp` as the global trace provider.
|
|
|
|
func SetTracerProvider(tp trace.TracerProvider) {
|
|
|
|
global.SetTracerProvider(tp)
|
|
|
|
}
|