Skip to content

Commit 6ad67ce

Browse files
feat: add noop for Trace::Span attributes and events (#1881)
* fix: add two noop function for span * add test case --------- Co-authored-by: Kayla Reopelle <[email protected]>
1 parent 8ba003b commit 6ad67ce

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

api/lib/opentelemetry/trace/span.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ def add_attributes(attributes)
7878
self
7979
end
8080

81+
# Retrieve attributes
82+
#
83+
# Note that the OpenTelemetry project
84+
# {https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-semantic-conventions.md
85+
# documents} certain "standard attributes" that have prescribed semantic
86+
# meanings.
87+
#
88+
# @return [hash] returns empty hash
89+
def attributes
90+
{}
91+
end
92+
8193
# Add a link to a {Span}.
8294
#
8395
# Adding links at span creation using the `links` option is preferred
@@ -123,6 +135,18 @@ def add_event(name, attributes: nil, timestamp: nil)
123135
self
124136
end
125137

138+
# Retrieve events
139+
#
140+
# Note that the OpenTelemetry project
141+
# {https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-semantic-conventions.md
142+
# documents} certain "standard event names and keys" which have
143+
# prescribed semantic meanings.
144+
#
145+
# @return [array] returns empty array
146+
def events
147+
[]
148+
end
149+
126150
# Record an exception during the execution of this span. Multiple exceptions
127151
# can be recorded on a span.
128152
#

api/test/opentelemetry/trace/span_test.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@
3636
end
3737
end
3838

39+
describe '#attributes' do
40+
it 'returns empty hash' do
41+
_(span.attributes).must_equal({})
42+
end
43+
44+
it 'returns empty hash even after modification attempts' do
45+
span.attributes['test'] = 'value'
46+
_(span.attributes).must_equal({})
47+
end
48+
end
49+
3950
describe '#add_link' do
4051
it 'returns self' do
4152
_(span.add_link(OpenTelemetry::Trace::Link.new(span_context))).must_equal(span)
@@ -60,6 +71,17 @@
6071
end
6172
end
6273

74+
describe '#events' do
75+
it 'returns empty array' do
76+
_(span.events).must_equal([])
77+
end
78+
79+
it 'returns empty array even after modification attempts' do
80+
span.events << 'test event'
81+
_(span.events).must_equal([])
82+
end
83+
end
84+
6385
describe '#record_exception' do
6486
it 'returns nil' do
6587
_(span.record_exception(StandardError.new('oops'))).must_be_nil

0 commit comments

Comments
 (0)