Module: Datadog::CI::Contrib::Minitest::Hooks

Defined in:
lib/datadog/ci/contrib/minitest/hooks.rb

Overview

Lifecycle hooks to instrument Minitest::Test

Instance Method Summary collapse

Instance Method Details

#after_teardownObject



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

def after_teardown
  span = Thread.current[:_datadog_test_span]
  return super unless span

  Thread.current[:_datadog_test_span] = nil

  case result_code
  when "."
    CI::Test.passed!(span)
  when "E", "F"
    CI::Test.failed!(span, failure)
  when "S"
    CI::Test.skipped!(span)
    span.set_tag(CI::Ext::Test::TAG_SKIP_REASON, failure.message)
  end

  span.finish

  super
end

#before_setupObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/datadog/ci/contrib/minitest/hooks.rb', line 9

def before_setup
  super
  return unless configuration[:enabled]

  test_name = "#{class_name}##{name}"

  path, = method(name).source_location
  test_suite = Pathname.new(path.to_s).relative_path_from(Pathname.pwd).to_s

  span = CI::Test.trace(
    configuration[:operation_name],
    {
      span_options: {
        resource: test_name,
        service: configuration[:service_name]
      },
      framework: Ext::FRAMEWORK,
      framework_version: CI::Contrib::Minitest::Integration.version.to_s,
      test_name: test_name,
      test_suite: test_suite,
      test_type: Ext::TEST_TYPE
    }
  )

  Thread.current[:_datadog_test_span] = span
end