You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

trace.go 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // 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. package otel // import "go.opentelemetry.io/otel"
  15. import (
  16. "go.opentelemetry.io/otel/internal/global"
  17. "go.opentelemetry.io/otel/trace"
  18. )
  19. // Tracer creates a named tracer that implements Tracer interface.
  20. // If the name is an empty string then provider uses default name.
  21. //
  22. // This is short for GetTracerProvider().Tracer(name)
  23. func Tracer(name string) trace.Tracer {
  24. return GetTracerProvider().Tracer(name)
  25. }
  26. // GetTracerProvider returns the registered global trace provider.
  27. // If none is registered then an instance of NoopTracerProvider is returned.
  28. //
  29. // Use the trace provider to create a named tracer. E.g.
  30. // tracer := global.GetTracerProvider().Tracer("example.com/foo")
  31. // or
  32. // tracer := global.Tracer("example.com/foo")
  33. func GetTracerProvider() trace.TracerProvider {
  34. return global.TracerProvider()
  35. }
  36. // SetTracerProvider registers `tp` as the global trace provider.
  37. func SetTracerProvider(tp trace.TracerProvider) {
  38. global.SetTracerProvider(tp)
  39. }