tracer_provider.go 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package sdk
  4. import (
  5. "go.opentelemetry.io/otel/trace"
  6. "go.opentelemetry.io/otel/trace/noop"
  7. )
  8. // TracerProvider returns an auto-instrumentable [trace.TracerProvider].
  9. //
  10. // If an [go.opentelemetry.io/auto.Instrumentation] is configured to instrument
  11. // the process using the returned TracerProvider, all of the telemetry it
  12. // produces will be processed and handled by that Instrumentation. By default,
  13. // if no Instrumentation instruments the TracerProvider it will not generate
  14. // any trace telemetry.
  15. func TracerProvider() trace.TracerProvider { return tracerProviderInstance }
  16. var tracerProviderInstance = new(tracerProvider)
  17. type tracerProvider struct{ noop.TracerProvider }
  18. var _ trace.TracerProvider = tracerProvider{}
  19. func (p tracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.Tracer {
  20. cfg := trace.NewTracerConfig(opts...)
  21. return tracer{
  22. name: name,
  23. version: cfg.InstrumentationVersion(),
  24. schemaURL: cfg.SchemaURL(),
  25. }
  26. }