Skip to content

Commit

Permalink
Fix trace_context propagation and prefer in_span.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jan 11, 2025
1 parent 9723ec4 commit 7614680
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
3 changes: 3 additions & 0 deletions config/sus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@

require "covered/sus"
include Covered::Sus

require "opentelemetry/sdk"
OpenTelemetry::SDK.configure
20 changes: 3 additions & 17 deletions lib/traces/backend/open_telemetry/interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,7 @@ module OpenTelemetry

module Interface
def trace(name, attributes: nil, &block)
span = TRACER.start_span(name, attributes: attributes&.transform_keys(&:to_s))

begin
if block.arity.zero?
yield
else
yield span
end
rescue Exception => error
span&.record_exception(error)
span&.status = ::OpenTelemetry::Trace::Status.error("Unhandled exception of type: #{error.class}")
raise
ensure
span&.finish
end
TRACER.in_span(name, attributes: attributes&.transform_keys(&:to_s), &block)
end

def trace_context=(context)
Expand All @@ -44,8 +30,8 @@ def trace_context=(context)
)

span = ::OpenTelemetry::Trace.non_recording_span(span_context)

return ::OpenTelemetry::Trace.context_with_span(span)
context = ::OpenTelemetry::Trace.context_with_span(span)
::OpenTelemetry::Context.attach(context)
end

def trace_context(span = ::OpenTelemetry::Trace.current_span)
Expand Down
6 changes: 3 additions & 3 deletions test/traces/backend/open_telemetry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def my_span_and_context
)

# It seems like OpenTelemetry doesn't really do anything in the testing environment, so we can't really check the parent_id?
# expect(span).to have_attributes(
# parent_id: be == context.parent_id
# )
expect(span).to have_attributes(
parent_span_id: be == context.parent_id
)
end
end
end
Expand Down

0 comments on commit 7614680

Please sign in to comment.