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