tracing.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Package tracing defines tracing APIs to be used by Smithy clients.
  2. package tracing
  3. import (
  4. "context"
  5. "github.com/aws/smithy-go"
  6. )
  7. // SpanStatus records the "success" state of an observed span.
  8. type SpanStatus int
  9. // Enumeration of SpanStatus.
  10. const (
  11. SpanStatusUnset SpanStatus = iota
  12. SpanStatusOK
  13. SpanStatusError
  14. )
  15. // SpanKind indicates the nature of the work being performed.
  16. type SpanKind int
  17. // Enumeration of SpanKind.
  18. const (
  19. SpanKindInternal SpanKind = iota
  20. SpanKindClient
  21. SpanKindServer
  22. SpanKindProducer
  23. SpanKindConsumer
  24. )
  25. // TracerProvider is the entry point for creating client traces.
  26. type TracerProvider interface {
  27. Tracer(scope string, opts ...TracerOption) Tracer
  28. }
  29. // TracerOption applies configuration to a tracer.
  30. type TracerOption func(o *TracerOptions)
  31. // TracerOptions represent configuration for tracers.
  32. type TracerOptions struct {
  33. Properties smithy.Properties
  34. }
  35. // Tracer is the entry point for creating observed client Spans.
  36. //
  37. // Spans created by tracers propagate by existing on the Context. Consumers of
  38. // the API can use [GetSpan] to pull the active Span from a Context.
  39. //
  40. // Creation of child Spans is implicit through Context persistence. If
  41. // CreateSpan is called with a Context that holds a Span, the result will be a
  42. // child of that Span.
  43. type Tracer interface {
  44. StartSpan(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span)
  45. }
  46. // SpanOption applies configuration to a span.
  47. type SpanOption func(o *SpanOptions)
  48. // SpanOptions represent configuration for span events.
  49. type SpanOptions struct {
  50. Kind SpanKind
  51. Properties smithy.Properties
  52. }
  53. // Span records a conceptually individual unit of work that takes place in a
  54. // Smithy client operation.
  55. type Span interface {
  56. Name() string
  57. Context() SpanContext
  58. AddEvent(name string, opts ...EventOption)
  59. SetStatus(status SpanStatus)
  60. SetProperty(k, v any)
  61. End()
  62. }
  63. // EventOption applies configuration to a span event.
  64. type EventOption func(o *EventOptions)
  65. // EventOptions represent configuration for span events.
  66. type EventOptions struct {
  67. Properties smithy.Properties
  68. }
  69. // SpanContext uniquely identifies a Span.
  70. type SpanContext struct {
  71. TraceID string
  72. SpanID string
  73. IsRemote bool
  74. }
  75. // IsValid is true when a span has nonzero trace and span IDs.
  76. func (ctx *SpanContext) IsValid() bool {
  77. return len(ctx.TraceID) != 0 && len(ctx.SpanID) != 0
  78. }