Skip to content

Commit 7614680

Browse files
committed
Fix trace_context propagation and prefer in_span.
1 parent 9723ec4 commit 7614680

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

config/sus.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77

88
require "covered/sus"
99
include Covered::Sus
10+
11+
require "opentelemetry/sdk"
12+
OpenTelemetry::SDK.configure

lib/traces/backend/open_telemetry/interface.rb

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,7 @@ module OpenTelemetry
1717

1818
module Interface
1919
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)
3521
end
3622

3723
def trace_context=(context)
@@ -44,8 +30,8 @@ def trace_context=(context)
4430
)
4531

4632
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)
4935
end
5036

5137
def trace_context(span = ::OpenTelemetry::Trace.current_span)

test/traces/backend/open_telemetry.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ def my_span_and_context
101101
)
102102

103103
# 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-
# )
104+
expect(span).to have_attributes(
105+
parent_span_id: be == context.parent_id
106+
)
107107
end
108108
end
109109
end

0 commit comments

Comments
 (0)