@@ -22,9 +22,23 @@ def my_method_without_attributes(arguments)
2222 def my_method_with_exception
2323 Traces . trace ( "my_method_with_exception" ) { raise "Error" }
2424 end
25+
26+ def my_span
27+ Traces . trace ( 'my_span' ) { |span | return span }
28+ end
29+
30+ def my_context
31+ Traces . trace ( 'my_context' ) { |span | return Traces . trace_context }
32+ end
33+
34+ def my_span_and_context
35+ Traces . trace ( 'my_span_and_context' ) { |span | return span , Traces . trace_context }
36+ end
2537end
2638
2739describe Traces ::Backend ::OpenTelemetry do
40+ let ( :instance ) { MyClass . new }
41+
2842 it "has a version number" do
2943 expect ( Traces ::Backend ::OpenTelemetry ::VERSION ) . not . to be == nil
3044 end
@@ -56,4 +70,30 @@ def my_method_with_exception
5670 instance . my_method_with_exception
5771 end . to raise_exception ( RuntimeError , message : be == "Error" )
5872 end
73+
74+ describe OpenTelemetry ::Trace ::Span do
75+ let ( :span ) { instance . my_span }
76+
77+ it "can assign name" do
78+ span . name = "new_name"
79+ end
80+
81+ it "can assign attributes" do
82+ span [ "my_key" ] = "tag_value"
83+ end
84+ end
85+
86+ describe OpenTelemetry ::Trace ::SpanContext do
87+ let ( :span_and_context ) { instance . my_span_and_context }
88+ let ( :span ) { span_and_context . first }
89+ let ( :context ) { span_and_context . last }
90+
91+ with '#trace_context' do
92+ it "has a valid trace id" do
93+ expect ( context ) . to have_attributes (
94+ trace_id : be != nil
95+ )
96+ end
97+ end
98+ end
5999end
0 commit comments