snapshot.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 trace // import "go.opentelemetry.io/otel/sdk/trace"
  15. import (
  16. "time"
  17. "go.opentelemetry.io/otel/attribute"
  18. "go.opentelemetry.io/otel/sdk/instrumentation"
  19. "go.opentelemetry.io/otel/sdk/resource"
  20. "go.opentelemetry.io/otel/trace"
  21. )
  22. // snapshot is an record of a spans state at a particular checkpointed time.
  23. // It is used as a read-only representation of that state.
  24. type snapshot struct {
  25. name string
  26. spanContext trace.SpanContext
  27. parent trace.SpanContext
  28. spanKind trace.SpanKind
  29. startTime time.Time
  30. endTime time.Time
  31. attributes []attribute.KeyValue
  32. events []Event
  33. links []Link
  34. status Status
  35. childSpanCount int
  36. droppedAttributeCount int
  37. droppedEventCount int
  38. droppedLinkCount int
  39. resource *resource.Resource
  40. instrumentationScope instrumentation.Scope
  41. }
  42. var _ ReadOnlySpan = snapshot{}
  43. func (s snapshot) private() {}
  44. // Name returns the name of the span.
  45. func (s snapshot) Name() string {
  46. return s.name
  47. }
  48. // SpanContext returns the unique SpanContext that identifies the span.
  49. func (s snapshot) SpanContext() trace.SpanContext {
  50. return s.spanContext
  51. }
  52. // Parent returns the unique SpanContext that identifies the parent of the
  53. // span if one exists. If the span has no parent the returned SpanContext
  54. // will be invalid.
  55. func (s snapshot) Parent() trace.SpanContext {
  56. return s.parent
  57. }
  58. // SpanKind returns the role the span plays in a Trace.
  59. func (s snapshot) SpanKind() trace.SpanKind {
  60. return s.spanKind
  61. }
  62. // StartTime returns the time the span started recording.
  63. func (s snapshot) StartTime() time.Time {
  64. return s.startTime
  65. }
  66. // EndTime returns the time the span stopped recording. It will be zero if
  67. // the span has not ended.
  68. func (s snapshot) EndTime() time.Time {
  69. return s.endTime
  70. }
  71. // Attributes returns the defining attributes of the span.
  72. func (s snapshot) Attributes() []attribute.KeyValue {
  73. return s.attributes
  74. }
  75. // Links returns all the links the span has to other spans.
  76. func (s snapshot) Links() []Link {
  77. return s.links
  78. }
  79. // Events returns all the events that occurred within in the spans
  80. // lifetime.
  81. func (s snapshot) Events() []Event {
  82. return s.events
  83. }
  84. // Status returns the spans status.
  85. func (s snapshot) Status() Status {
  86. return s.status
  87. }
  88. // InstrumentationScope returns information about the instrumentation
  89. // scope that created the span.
  90. func (s snapshot) InstrumentationScope() instrumentation.Scope {
  91. return s.instrumentationScope
  92. }
  93. // InstrumentationLibrary returns information about the instrumentation
  94. // library that created the span.
  95. func (s snapshot) InstrumentationLibrary() instrumentation.Library {
  96. return s.instrumentationScope
  97. }
  98. // Resource returns information about the entity that produced the span.
  99. func (s snapshot) Resource() *resource.Resource {
  100. return s.resource
  101. }
  102. // DroppedAttributes returns the number of attributes dropped by the span
  103. // due to limits being reached.
  104. func (s snapshot) DroppedAttributes() int {
  105. return s.droppedAttributeCount
  106. }
  107. // DroppedLinks returns the number of links dropped by the span due to limits
  108. // being reached.
  109. func (s snapshot) DroppedLinks() int {
  110. return s.droppedLinkCount
  111. }
  112. // DroppedEvents returns the number of events dropped by the span due to
  113. // limits being reached.
  114. func (s snapshot) DroppedEvents() int {
  115. return s.droppedEventCount
  116. }
  117. // ChildSpanCount returns the count of spans that consider the span a
  118. // direct parent.
  119. func (s snapshot) ChildSpanCount() int {
  120. return s.childSpanCount
  121. }