tracer.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package trace // import "go.opentelemetry.io/otel/trace"
  4. import (
  5. "context"
  6. "go.opentelemetry.io/otel/trace/embedded"
  7. )
  8. // Tracer is the creator of Spans.
  9. //
  10. // Warning: Methods may be added to this interface in minor releases. See
  11. // package documentation on API implementation for information on how to set
  12. // default behavior for unimplemented methods.
  13. type Tracer interface {
  14. // Users of the interface can ignore this. This embedded type is only used
  15. // by implementations of this interface. See the "API Implementations"
  16. // section of the package documentation for more information.
  17. embedded.Tracer
  18. // Start creates a span and a context.Context containing the newly-created span.
  19. //
  20. // If the context.Context provided in `ctx` contains a Span then the newly-created
  21. // Span will be a child of that span, otherwise it will be a root span. This behavior
  22. // can be overridden by providing `WithNewRoot()` as a SpanOption, causing the
  23. // newly-created Span to be a root span even if `ctx` contains a Span.
  24. //
  25. // When creating a Span it is recommended to provide all known span attributes using
  26. // the `WithAttributes()` SpanOption as samplers will only have access to the
  27. // attributes provided when a Span is created.
  28. //
  29. // Any Span that is created MUST also be ended. This is the responsibility of the user.
  30. // Implementations of this API may leak memory or other resources if Spans are not ended.
  31. Start(ctx context.Context, spanName string, opts ...SpanStartOption) (context.Context, Span)
  32. }