Module: Datadog::CI::TestVisibility::Telemetry

Defined in:
lib/datadog/ci/test_visibility/telemetry.rb

Overview

Telemetry for test visibility

Constant Summary collapse

SPAN_TYPE_TO_TELEMETRY_EVENT_TYPE =
{
  Ext::AppTypes::TYPE_TEST => Ext::Telemetry::EventType::TEST,
  Ext::AppTypes::TYPE_TEST_SUITE => Ext::Telemetry::EventType::SUITE,
  Ext::AppTypes::TYPE_TEST_MODULE => Ext::Telemetry::EventType::MODULE,
  Ext::AppTypes::TYPE_TEST_SESSION => Ext::Telemetry::EventType::SESSION
}.freeze

Class Method Summary collapse

Class Method Details

.add_browser_tags!(span, tags) ⇒ Object



72
73
74
75
76
# File 'lib/datadog/ci/test_visibility/telemetry.rb', line 72

def self.add_browser_tags!(span, tags)
  tags[Ext::Telemetry::TAG_IS_RUM] = "true" if span.get_tag(Ext::Test::TAG_IS_RUM_ACTIVE)
  browser_driver = span.get_tag(Ext::Test::TAG_BROWSER_DRIVER)
  tags[Ext::Telemetry::TAG_BROWSER_DRIVER] = browser_driver if browser_driver
end

.event_created(span) ⇒ Object



22
23
24
# File 'lib/datadog/ci/test_visibility/telemetry.rb', line 22

def self.event_created(span)
  Utils::Telemetry.inc(Ext::Telemetry::METRIC_EVENT_CREATED, 1, event_tags_from_span(span))
end

.event_finished(span) ⇒ Object



26
27
28
29
30
# File 'lib/datadog/ci/test_visibility/telemetry.rb', line 26

def self.event_finished(span)
  tags = event_tags_from_span(span)
  add_browser_tags!(span, tags)
  Utils::Telemetry.inc(Ext::Telemetry::METRIC_EVENT_FINISHED, 1, tags)
end

.event_tags_from_span(span) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/datadog/ci/test_visibility/telemetry.rb', line 43

def self.event_tags_from_span(span)
  # base tags for span
  # @type var tags: Hash[String, String]
  tags = {
    Ext::Telemetry::TAG_EVENT_TYPE => SPAN_TYPE_TO_TELEMETRY_EVENT_TYPE.fetch(span.type, "unknown"),
    Ext::Telemetry::TAG_TEST_FRAMEWORK => span.get_tag(Ext::Test::TAG_FRAMEWORK)
  }

  # ci provider tag
  tags[Ext::Telemetry::TAG_IS_UNSUPPORTED_CI] = "true" if span.get_tag(Ext::Environment::TAG_PROVIDER_NAME).nil?

  # codeowner tag
  tags[Ext::Telemetry::TAG_HAS_CODEOWNER] = "true" if span.get_tag(Ext::Test::TAG_CODEOWNERS)

  # set is_retry tag if span represents a retried test
  tags[Ext::Telemetry::TAG_IS_RETRY] = "true" if span.get_tag(Ext::Test::TAG_IS_RETRY)

  # is_new
  tags[Ext::Telemetry::TAG_IS_NEW] = "true" if span.get_tag(Ext::Test::TAG_IS_NEW)

  # session-level tag - early_flake_detection_abort_reason
  early_flake_detection_abort_reason = span.get_tag(Ext::Test::TAG_EARLY_FLAKE_ABORT_REASON)
  if early_flake_detection_abort_reason
    tags[Ext::Telemetry::TAG_EARLY_FLAKE_DETECTION_ABORT_REASON] = early_flake_detection_abort_reason
  end

  tags
end

.test_session_started(test_session) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/datadog/ci/test_visibility/telemetry.rb', line 32

def self.test_session_started(test_session)
  Utils::Telemetry.inc(
    Ext::Telemetry::METRIC_TEST_SESSION,
    1,
    {
      Ext::Telemetry::TAG_AUTO_INJECTED => Contrib::Instrumentation.auto_instrumented?.to_s,
      Ext::Telemetry::TAG_PROVIDER => test_session.ci_provider || Ext::Telemetry::Provider::UNSUPPORTED
    }
  )
end