Class: Datadog::CI::TestVisibility::Context
- Inherits:
-
Object
- Object
- Datadog::CI::TestVisibility::Context
- Defined in:
- lib/datadog/ci/test_visibility/context.rb
Overview
Manages current in-memory context for test visibility (such as active test session, suite, test, etc.). Its responsibility includes building domain models for test visibility as well. Internally it uses Datadog::Tracing module to create spans.
Instance Method Summary collapse
- #active_span ⇒ Object
- #active_test ⇒ Object
- #active_test_module ⇒ Object
- #active_test_session ⇒ Object
- #active_test_suite(test_suite_name) ⇒ Object
- #deactivate_test ⇒ Object
- #deactivate_test_module ⇒ Object
- #deactivate_test_session ⇒ Object
- #deactivate_test_suite(test_suite_name) ⇒ Object
-
#initialize ⇒ Context
constructor
A new instance of Context.
- #single_active_test_suite ⇒ Object
- #start_test_module(test_module_name, service: nil, tags: {}) ⇒ Object
- #start_test_session(service: nil, tags: {}) ⇒ Object
- #start_test_suite(test_suite_name, service: nil, tags: {}) ⇒ Object
- #trace(span_name, type: "span", tags: {}, &block) ⇒ Object
- #trace_test(test_name, test_suite_name, service: nil, tags: {}, &block) ⇒ Object
Constructor Details
Instance Method Details
#active_span ⇒ Object
125 126 127 128 |
# File 'lib/datadog/ci/test_visibility/context.rb', line 125 def active_span tracer_span = Datadog::Tracing.active_span Span.new(tracer_span) if tracer_span end |
#active_test ⇒ Object
130 131 132 |
# File 'lib/datadog/ci/test_visibility/context.rb', line 130 def active_test @local_context.active_test end |
#active_test_module ⇒ Object
138 139 140 |
# File 'lib/datadog/ci/test_visibility/context.rb', line 138 def active_test_module @global_context.active_test_module end |
#active_test_session ⇒ Object
134 135 136 |
# File 'lib/datadog/ci/test_visibility/context.rb', line 134 def active_test_session @global_context.active_test_session end |
#active_test_suite(test_suite_name) ⇒ Object
142 143 144 |
# File 'lib/datadog/ci/test_visibility/context.rb', line 142 def active_test_suite(test_suite_name) @global_context.active_test_suite(test_suite_name) end |
#deactivate_test ⇒ Object
150 151 152 |
# File 'lib/datadog/ci/test_visibility/context.rb', line 150 def deactivate_test @local_context.deactivate_test end |
#deactivate_test_module ⇒ Object
158 159 160 |
# File 'lib/datadog/ci/test_visibility/context.rb', line 158 def deactivate_test_module @global_context.deactivate_test_module! end |
#deactivate_test_session ⇒ Object
154 155 156 |
# File 'lib/datadog/ci/test_visibility/context.rb', line 154 def deactivate_test_session @global_context.deactivate_test_session! end |
#deactivate_test_suite(test_suite_name) ⇒ Object
162 163 164 |
# File 'lib/datadog/ci/test_visibility/context.rb', line 162 def deactivate_test_suite(test_suite_name) @global_context.deactivate_test_suite!(test_suite_name) end |
#single_active_test_suite ⇒ Object
146 147 148 |
# File 'lib/datadog/ci/test_visibility/context.rb', line 146 def single_active_test_suite @global_context.fetch_single_test_suite end |
#start_test_module(test_module_name, service: nil, tags: {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/datadog/ci/test_visibility/context.rb', line 45 def start_test_module(test_module_name, service: nil, tags: {}) @global_context.fetch_or_activate_test_module do set_inherited_globals() set_session_context() tracer_span = start_datadog_tracer_span( test_module_name, (service, Ext::AppTypes::TYPE_TEST_MODULE) ) set_module_context(, tracer_span) build_test_module(tracer_span, ) end end |
#start_test_session(service: nil, tags: {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/datadog/ci/test_visibility/context.rb', line 34 def start_test_session(service: nil, tags: {}) @global_context.fetch_or_activate_test_session do tracer_span = start_datadog_tracer_span( "test.session", (service, Ext::AppTypes::TYPE_TEST_SESSION) ) set_session_context(, tracer_span) build_test_session(tracer_span, ) end end |
#start_test_suite(test_suite_name, service: nil, tags: {}) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/datadog/ci/test_visibility/context.rb', line 59 def start_test_suite(test_suite_name, service: nil, tags: {}) @global_context.fetch_or_activate_test_suite(test_suite_name) do set_inherited_globals() set_session_context() set_module_context() tracer_span = start_datadog_tracer_span( test_suite_name, (service, Ext::AppTypes::TYPE_TEST_SUITE) ) set_suite_context(, span: tracer_span) build_test_suite(tracer_span, ) end end |
#trace(span_name, type: "span", tags: {}, &block) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/datadog/ci/test_visibility/context.rb', line 107 def trace(span_name, type: "span", tags: {}, &block) = ( nil, # service name is completely optional for custom spans type, {resource: span_name} ) if block start_datadog_tracer_span(span_name, ) do |tracer_span| block.call(build_span(tracer_span, )) end else tracer_span = start_datadog_tracer_span(span_name, ) build_span(tracer_span, ) end end |
#trace_test(test_name, test_suite_name, service: nil, tags: {}, &block) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/datadog/ci/test_visibility/context.rb', line 74 def trace_test(test_name, test_suite_name, service: nil, tags: {}, &block) set_inherited_globals() set_session_context() set_module_context() set_suite_context(, name: test_suite_name) [Ext::Test::TAG_NAME] = test_name [Ext::Test::TAG_TYPE] ||= Ext::Test::Type::TEST = ( service, Ext::AppTypes::TYPE_TEST, # :resource is needed for the agent APM protocol to work correctly (for older agent versions) # :continue_from is required to start a new trace for each test {resource: test_name, continue_from: Datadog::Tracing::TraceDigest.new} ) if block start_datadog_tracer_span(test_name, ) do |tracer_span| test = build_test(tracer_span, ) @local_context.activate_test(test) do block.call(test) end end else tracer_span = start_datadog_tracer_span(test_name, ) test = build_test(tracer_span, ) @local_context.activate_test(test) test end end |