provider.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package trace // import "go.opentelemetry.io/otel/trace"
  4. import "go.opentelemetry.io/otel/trace/embedded"
  5. // TracerProvider provides Tracers that are used by instrumentation code to
  6. // trace computational workflows.
  7. //
  8. // A TracerProvider is the collection destination of all Spans from Tracers it
  9. // provides, it represents a unique telemetry collection pipeline. How that
  10. // pipeline is defined, meaning how those Spans are collected, processed, and
  11. // where they are exported, depends on its implementation. Instrumentation
  12. // authors do not need to define this implementation, rather just use the
  13. // provided Tracers to instrument code.
  14. //
  15. // Commonly, instrumentation code will accept a TracerProvider implementation
  16. // at runtime from its users or it can simply use the globally registered one
  17. // (see https://pkg.go.dev/go.opentelemetry.io/otel#GetTracerProvider).
  18. //
  19. // Warning: Methods may be added to this interface in minor releases. See
  20. // package documentation on API implementation for information on how to set
  21. // default behavior for unimplemented methods.
  22. type TracerProvider interface {
  23. // Users of the interface can ignore this. This embedded type is only used
  24. // by implementations of this interface. See the "API Implementations"
  25. // section of the package documentation for more information.
  26. embedded.TracerProvider
  27. // Tracer returns a unique Tracer scoped to be used by instrumentation code
  28. // to trace computational workflows. The scope and identity of that
  29. // instrumentation code is uniquely defined by the name and options passed.
  30. //
  31. // The passed name needs to uniquely identify instrumentation code.
  32. // Therefore, it is recommended that name is the Go package name of the
  33. // library providing instrumentation (note: not the code being
  34. // instrumented). Instrumentation libraries can have multiple versions,
  35. // therefore, the WithInstrumentationVersion option should be used to
  36. // distinguish these different codebases. Additionally, instrumentation
  37. // libraries may sometimes use traces to communicate different domains of
  38. // workflow data (i.e. using spans to communicate workflow events only). If
  39. // this is the case, the WithScopeAttributes option should be used to
  40. // uniquely identify Tracers that handle the different domains of workflow
  41. // data.
  42. //
  43. // If the same name and options are passed multiple times, the same Tracer
  44. // will be returned (it is up to the implementation if this will be the
  45. // same underlying instance of that Tracer or not). It is not necessary to
  46. // call this multiple times with the same name and options to get an
  47. // up-to-date Tracer. All implementations will ensure any TracerProvider
  48. // configuration changes are propagated to all provided Tracers.
  49. //
  50. // If name is empty, then an implementation defined default name will be
  51. // used instead.
  52. //
  53. // This method is safe to call concurrently.
  54. Tracer(name string, options ...TracerOption) Tracer
  55. }