File tree Expand file tree Collapse file tree 3 files changed +9
-21
lines changed
lib/traces/backend/open_telemetry Expand file tree Collapse file tree 3 files changed +9
-21
lines changed Original file line number Diff line number Diff line change 7
7
8
8
require "covered/sus"
9
9
include Covered ::Sus
10
+
11
+ require "opentelemetry/sdk"
12
+ OpenTelemetry ::SDK . configure
Original file line number Diff line number Diff line change @@ -17,21 +17,7 @@ module OpenTelemetry
17
17
18
18
module Interface
19
19
def trace ( name , attributes : nil , &block )
20
- span = TRACER . start_span ( name , attributes : attributes &.transform_keys ( &:to_s ) )
21
-
22
- begin
23
- if block . arity . zero?
24
- yield
25
- else
26
- yield span
27
- end
28
- rescue Exception => error
29
- span &.record_exception ( error )
30
- span &.status = ::OpenTelemetry ::Trace ::Status . error ( "Unhandled exception of type: #{ error . class } " )
31
- raise
32
- ensure
33
- span &.finish
34
- end
20
+ TRACER . in_span ( name , attributes : attributes &.transform_keys ( &:to_s ) , &block )
35
21
end
36
22
37
23
def trace_context = ( context )
@@ -44,8 +30,8 @@ def trace_context=(context)
44
30
)
45
31
46
32
span = ::OpenTelemetry ::Trace . non_recording_span ( span_context )
47
-
48
- return ::OpenTelemetry ::Trace . context_with_span ( span )
33
+ context = :: OpenTelemetry :: Trace . context_with_span ( span )
34
+ ::OpenTelemetry ::Context . attach ( context )
49
35
end
50
36
51
37
def trace_context ( span = ::OpenTelemetry ::Trace . current_span )
Original file line number Diff line number Diff line change @@ -100,10 +100,9 @@ def my_span_and_context
100
100
trace_id : be == context . trace_id ,
101
101
)
102
102
103
- # It seems like OpenTelemetry doesn't really do anything in the testing environment, so we can't really check the parent_id?
104
- # expect(span).to have_attributes(
105
- # parent_id: be == context.parent_id
106
- # )
103
+ expect ( span ) . to have_attributes (
104
+ parent_span_id : be == context . parent_id
105
+ )
107
106
end
108
107
end
109
108
end
You can’t perform that action at this time.
0 commit comments