Skip to content

Commit

Permalink
move status methods out of Recorder to Span
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Oct 30, 2023
1 parent b55d93a commit fd0a7a0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/datadog/ci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def trace(span_type, span_name, span_options = {})
span_options[:span_type] = span_type

if block_given?
Datadog::Tracing.trace(span_name, **span_options) do |tracer_span|
::Datadog::Tracing.trace(span_name, **span_options) do |tracer_span|
yield Span.new(tracer_span)
end
else
tracer_span = Datadog::Tracing.trace(span_name, **span_options)
tracer_span = ::Datadog::Tracing.trace(span_name, **span_options)
Span.new(tracer_span)
end
end
Expand Down
16 changes: 0 additions & 16 deletions lib/datadog/ci/recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,6 @@ def self.set_tags!(trace, span, tags = {})
span
end

def self.passed!(span)
span.set_tag(Ext::Test::TAG_STATUS, Ext::Test::Status::PASS)
end

def self.failed!(span, exception = nil)
span.status = 1
span.set_tag(Ext::Test::TAG_STATUS, Ext::Test::Status::FAIL)
span.set_error(exception) unless exception.nil?
end

def self.skipped!(span, exception = nil, reason = nil)
span.set_tag(Ext::Test::TAG_STATUS, Ext::Test::Status::SKIP)
span.set_error(exception) unless exception.nil?
span.set_tag(CI::Ext::Test::TAG_SKIP_REASON, reason) unless reason.nil?
end

private_class_method def self.set_environment_runtime_tags!(span)
span.set_tag(Ext::Test::TAG_OS_ARCHITECTURE, ::RbConfig::CONFIG["host_cpu"])
span.set_tag(Ext::Test::TAG_OS_PLATFORM, ::RbConfig::CONFIG["host_os"])
Expand Down
10 changes: 7 additions & 3 deletions lib/datadog/ci/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ def initialize(tracer_span)
end

def passed!
CI::Recorder.passed!(@tracer_span)
tracer_span.set_tag(Ext::Test::TAG_STATUS, Ext::Test::Status::PASS)
end

def failed!(exception = nil)
CI::Recorder.failed!(@tracer_span, exception)
tracer_span.status = 1
tracer_span.set_tag(Ext::Test::TAG_STATUS, Ext::Test::Status::FAIL)
tracer_span.set_error(exception) unless exception.nil?
end

def skipped!(exception = nil, reason = nil)
CI::Recorder.skipped!(@tracer_span, exception, reason)
tracer_span.set_tag(Ext::Test::TAG_STATUS, Ext::Test::Status::SKIP)
tracer_span.set_error(exception) unless exception.nil?
tracer_span.set_tag(CI::Ext::Test::TAG_SKIP_REASON, reason) unless reason.nil?
end

def finish
Expand Down

0 comments on commit fd0a7a0

Please sign in to comment.