Class: Datadog::CI::Span
- Inherits:
-
Object
- Object
- Datadog::CI::Span
- Defined in:
- lib/datadog/ci/span.rb
Overview
Represents a single part of a test run. Could be a session, suite, test, or any custom span.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#tracer_span ⇒ Object
readonly
Returns the value of attribute tracer_span.
Instance Method Summary collapse
-
#failed!(exception: nil) ⇒ void
Sets the status of the span to “fail”.
-
#failed? ⇒ bool
Checks whether span status is FAIL.
-
#finish ⇒ void
Finishes the span.
-
#get_tag(key) ⇒ String
Gets tag value by key.
-
#git_branch ⇒ String
Returns the git branch name extracted from the environment.
-
#git_commit_sha ⇒ String
Returns the latest commit SHA extracted from the environment.
-
#git_repository_url ⇒ String
Returns the git repository URL extracted from the environment.
-
#id ⇒ Integer
The ID of the span.
-
#initialize(tracer_span) ⇒ Span
constructor
A new instance of Span.
-
#name ⇒ String
The name of the span.
-
#os_architecture ⇒ String
Returns the OS architecture extracted from the environment.
-
#os_platform ⇒ String
Returns the OS platform extracted from the environment.
-
#os_version ⇒ String
Returns the OS version extracted from the environment.
-
#passed! ⇒ void
Sets the status of the span to “pass”.
-
#passed? ⇒ bool
Checks whether span status is PASS.
-
#runtime_name ⇒ String
Returns the runtime name extracted from the environment.
-
#runtime_version ⇒ String
Returns the runtime version extracted from the environment.
-
#service ⇒ String
The service name of the span.
- #set_default_tags ⇒ Object
- #set_environment_runtime_tags ⇒ Object
-
#set_metric(key, value) ⇒ void
Sets metric value by key.
-
#set_tag(key, value) ⇒ void
Sets tag value by key.
-
#set_tags(tags) ⇒ void
Sets multiple tags at once.
-
#skipped!(exception: nil, reason: nil) ⇒ void
Sets the status of the span to “skip”.
-
#skipped? ⇒ bool
Checks whether span status is SKIP.
- #to_s ⇒ Object
-
#type ⇒ String
The type of the span (for example “test” or type that was provided to [Datadog::CI.trace]).
-
#undefined? ⇒ bool
Checks whether span status is not set yet.
Constructor Details
#initialize(tracer_span) ⇒ Span
Returns a new instance of Span.
17 18 19 |
# File 'lib/datadog/ci/span.rb', line 17 def initialize(tracer_span) @tracer_span = tracer_span end |
Instance Attribute Details
#tracer_span ⇒ Object (readonly)
Returns the value of attribute tracer_span.
15 16 17 |
# File 'lib/datadog/ci/span.rb', line 15 def tracer_span @tracer_span end |
Instance Method Details
#failed!(exception: nil) ⇒ void
This method returns an undefined value.
Sets the status of the span to “fail”.
74 75 76 77 78 |
# File 'lib/datadog/ci/span.rb', line 74 def failed!(exception: nil) 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 |
#failed? ⇒ bool
Checks whether span status is FAIL.
55 56 57 |
# File 'lib/datadog/ci/span.rb', line 55 def failed? tracer_span.get_tag(Ext::Test::TAG_STATUS) == Ext::Test::Status::FAIL end |
#finish ⇒ void
This method returns an undefined value.
Finishes the span.
115 116 117 |
# File 'lib/datadog/ci/span.rb', line 115 def finish tracer_span.finish end |
#get_tag(key) ⇒ String
Gets tag value by key.
93 94 95 |
# File 'lib/datadog/ci/span.rb', line 93 def get_tag(key) tracer_span.get_tag(key) end |
#git_branch ⇒ String
Returns the git branch name extracted from the environment.
140 141 142 |
# File 'lib/datadog/ci/span.rb', line 140 def git_branch tracer_span.get_tag(Ext::Git::TAG_BRANCH) end |
#git_commit_sha ⇒ String
Returns the latest commit SHA extracted from the environment.
134 135 136 |
# File 'lib/datadog/ci/span.rb', line 134 def git_commit_sha tracer_span.get_tag(Ext::Git::TAG_COMMIT_SHA) end |
#git_repository_url ⇒ String
Returns the git repository URL extracted from the environment.
128 129 130 |
# File 'lib/datadog/ci/span.rb', line 128 def git_repository_url tracer_span.get_tag(Ext::Git::TAG_REPOSITORY_URL) end |
#id ⇒ Integer
Returns the ID of the span.
22 23 24 |
# File 'lib/datadog/ci/span.rb', line 22 def id tracer_span.id end |
#name ⇒ String
Returns the name of the span.
27 28 29 |
# File 'lib/datadog/ci/span.rb', line 27 def name tracer_span.name end |
#os_architecture ⇒ String
Returns the OS architecture extracted from the environment.
146 147 148 |
# File 'lib/datadog/ci/span.rb', line 146 def os_architecture tracer_span.get_tag(Ext::Test::TAG_OS_ARCHITECTURE) end |
#os_platform ⇒ String
Returns the OS platform extracted from the environment.
152 153 154 |
# File 'lib/datadog/ci/span.rb', line 152 def os_platform tracer_span.get_tag(Ext::Test::TAG_OS_PLATFORM) end |
#os_version ⇒ String
Returns the OS version extracted from the environment.
158 159 160 |
# File 'lib/datadog/ci/span.rb', line 158 def os_version tracer_span.get_tag(Ext::Test::TAG_OS_VERSION) end |
#passed! ⇒ void
This method returns an undefined value.
Sets the status of the span to “pass”.
67 68 69 |
# File 'lib/datadog/ci/span.rb', line 67 def passed! tracer_span.set_tag(Ext::Test::TAG_STATUS, Ext::Test::Status::PASS) end |
#passed? ⇒ bool
Checks whether span status is PASS.
49 50 51 |
# File 'lib/datadog/ci/span.rb', line 49 def passed? tracer_span.get_tag(Ext::Test::TAG_STATUS) == Ext::Test::Status::PASS end |
#runtime_name ⇒ String
Returns the runtime name extracted from the environment.
164 165 166 |
# File 'lib/datadog/ci/span.rb', line 164 def runtime_name tracer_span.get_tag(Ext::Test::TAG_RUNTIME_NAME) end |
#runtime_version ⇒ String
Returns the runtime version extracted from the environment.
170 171 172 |
# File 'lib/datadog/ci/span.rb', line 170 def runtime_version tracer_span.get_tag(Ext::Test::TAG_RUNTIME_VERSION) end |
#service ⇒ String
Returns the service name of the span.
32 33 34 |
# File 'lib/datadog/ci/span.rb', line 32 def service tracer_span.service end |
#set_default_tags ⇒ Object
183 184 185 |
# File 'lib/datadog/ci/span.rb', line 183 def tracer_span.set_tag(Ext::Test::TAG_SPAN_KIND, Ext::Test::SPAN_KIND_TEST) end |
#set_environment_runtime_tags ⇒ Object
174 175 176 177 178 179 180 181 |
# File 'lib/datadog/ci/span.rb', line 174 def tracer_span.set_tag(Ext::Test::TAG_OS_ARCHITECTURE, ::RbConfig::CONFIG["host_cpu"]) tracer_span.set_tag(Ext::Test::TAG_OS_PLATFORM, ::RbConfig::CONFIG["host_os"]) tracer_span.set_tag(Ext::Test::TAG_OS_VERSION, Core::Environment::Platform.kernel_release) tracer_span.set_tag(Ext::Test::TAG_RUNTIME_NAME, Core::Environment::Ext::LANG_ENGINE) tracer_span.set_tag(Ext::Test::TAG_RUNTIME_VERSION, Core::Environment::Ext::ENGINE_VERSION) tracer_span.set_tag(Ext::Test::TAG_COMMAND, Utils::TestRun.command) end |
#set_metric(key, value) ⇒ void
This method returns an undefined value.
Sets metric value by key.
109 110 111 |
# File 'lib/datadog/ci/span.rb', line 109 def set_metric(key, value) tracer_span.set_metric(key, value) end |
#set_tag(key, value) ⇒ void
This method returns an undefined value.
Sets tag value by key.
101 102 103 |
# File 'lib/datadog/ci/span.rb', line 101 def set_tag(key, value) tracer_span.set_tag(key, value) end |
#set_tags(tags) ⇒ void
This method returns an undefined value.
Sets multiple tags at once.
122 123 124 |
# File 'lib/datadog/ci/span.rb', line 122 def () tracer_span.() end |
#skipped!(exception: nil, reason: nil) ⇒ void
This method returns an undefined value.
Sets the status of the span to “skip”.
84 85 86 87 88 |
# File 'lib/datadog/ci/span.rb', line 84 def skipped!(exception: nil, reason: nil) tracer_span.set_tag(Ext::Test::TAG_STATUS, Ext::Test::Status::SKIP) tracer_span.set_error(exception) unless exception.nil? tracer_span.set_tag(Ext::Test::TAG_SKIP_REASON, reason) unless reason.nil? end |
#skipped? ⇒ bool
Checks whether span status is SKIP.
61 62 63 |
# File 'lib/datadog/ci/span.rb', line 61 def skipped? tracer_span.get_tag(Ext::Test::TAG_STATUS) == Ext::Test::Status::SKIP end |
#to_s ⇒ Object
187 188 189 |
# File 'lib/datadog/ci/span.rb', line 187 def to_s "#{self.class}(name:#{name},tracer_span:#{@tracer_span})" end |
#type ⇒ String
Returns the type of the span (for example “test” or type that was provided to [Datadog::CI.trace]).
37 38 39 |
# File 'lib/datadog/ci/span.rb', line 37 def type tracer_span.type end |
#undefined? ⇒ bool
Checks whether span status is not set yet.
43 44 45 |
# File 'lib/datadog/ci/span.rb', line 43 def undefined? tracer_span.get_tag(Ext::Test::TAG_STATUS).nil? end |