Module: Datadog::CI::Test

Defined in:
lib/datadog/ci/test.rb

Overview

Common behavior for CI tests

Class Method Summary collapse

Class Method Details

.failed!(span, exception = nil) ⇒ Object



62
63
64
65
66
# File 'lib/datadog/ci/test.rb', line 62

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

.passed!(span) ⇒ Object



58
59
60
# File 'lib/datadog/ci/test.rb', line 58

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

.set_tags!(span, tags = {}) ⇒ Object

Adds tags to a CI test span.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/datadog/ci/test.rb', line 34

def self.set_tags!(span, tags = {})
  tags ||= {}

  # Set default tags
  span.context.origin = Ext::Test::CONTEXT_ORIGIN if span.context
  Datadog::Contrib::Analytics.set_measured(span)
  span.set_tag(Ext::Test::TAG_SPAN_KIND, Ext::AppTypes::TEST)

  # Set environment tags
  @environment_tags ||= Ext::Environment.tags(ENV)
  @environment_tags.each { |k, v| span.set_tag(k, v) }

  # Set contextual tags
  span.set_tag(Ext::Test::TAG_FRAMEWORK, tags[:framework]) if tags[:framework]
  span.set_tag(Ext::Test::TAG_FRAMEWORK_VERSION, tags[:framework_version]) if tags[:framework_version]
  span.set_tag(Ext::Test::TAG_NAME, tags[:test_name]) if tags[:test_name]
  span.set_tag(Ext::Test::TAG_SUITE, tags[:test_suite]) if tags[:test_suite]
  span.set_tag(Ext::Test::TAG_TYPE, tags[:test_type]) if tags[:test_type]

  set_environment_runtime_tags!(span)

  span
end

.skipped!(span, exception = nil) ⇒ Object



68
69
70
71
# File 'lib/datadog/ci/test.rb', line 68

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

.trace(tracer, span_name, options = {}) ⇒ Object

Creates a new span for a CI test



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/datadog/ci/test.rb', line 16

def self.trace(tracer, span_name, options = {})
  span_options = {
    span_type: Ext::AppTypes::TEST
  }.merge(options[:span_options] || {})

  if block_given?
    tracer.trace(span_name, span_options) do |span|
      set_tags!(span, options)
      yield(span)
    end
  else
    span = tracer.trace(span_name, span_options)
    set_tags!(span, options)
    span
  end
end