Class: Datadog::CI::Span
- Inherits:
-
Object
- Object
- Datadog::CI::Span
- Includes:
- DRb::DRbUndumped
- 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
-
#base_commit_sha ⇒ String?
Returns the base commit SHA for the pull request, if available.
-
#clear_tag(key) ⇒ void
Removes tag by key.
-
#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_metric(key) ⇒ Numeric
Gets metric value by key.
-
#get_tag(key) ⇒ String
Gets tag value by key.
-
#git_branch ⇒ String
Returns the git branch name extracted from the environment.
-
#git_commit_message ⇒ String
Returns the git commit message 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.
-
#git_tag ⇒ String?
Returns the git tag 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.
-
#original_git_commit_message ⇒ String
Returns the original last git commit message extracted from the environment.
-
#original_git_commit_sha ⇒ String
Returns the original last git commit SHA extracted from the environment.
-
#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.
-
#source_file ⇒ String?
Source file path where the test or test suite defined (relative to git repository root).
-
#status ⇒ String?
Returns the current status of the span.
- #to_s ⇒ Object
-
#trace_id ⇒ Integer
The trace ID of the trace this span belongs to.
-
#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.
22 23 24 |
# File 'lib/datadog/ci/span.rb', line 22 def initialize(tracer_span) @tracer_span = tracer_span end |
Instance Attribute Details
#tracer_span ⇒ Object (readonly)
Returns the value of attribute tracer_span.
20 21 22 |
# File 'lib/datadog/ci/span.rb', line 20 def tracer_span @tracer_span end |
Instance Method Details
#base_commit_sha ⇒ String?
Returns the base commit SHA for the pull request, if available.
206 207 208 |
# File 'lib/datadog/ci/span.rb', line 206 def base_commit_sha tracer_span.get_tag(Ext::Git::TAG_PULL_REQUEST_BASE_BRANCH_SHA) end |
#clear_tag(key) ⇒ void
This method returns an undefined value.
Removes tag by key.
124 125 126 |
# File 'lib/datadog/ci/span.rb', line 124 def clear_tag(key) tracer_span.clear_tag(key) end |
#failed!(exception: nil) ⇒ void
This method returns an undefined value.
Sets the status of the span to "fail".
90 91 92 93 94 |
# File 'lib/datadog/ci/span.rb', line 90 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.
65 66 67 |
# File 'lib/datadog/ci/span.rb', line 65 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.
145 146 147 |
# File 'lib/datadog/ci/span.rb', line 145 def finish tracer_span.finish end |
#get_metric(key) ⇒ Numeric
Gets metric value by key.
131 132 133 |
# File 'lib/datadog/ci/span.rb', line 131 def get_metric(key) tracer_span.get_metric(key) end |
#get_tag(key) ⇒ String
Gets tag value by key.
109 110 111 |
# File 'lib/datadog/ci/span.rb', line 109 def get_tag(key) tracer_span.get_tag(key) end |
#git_branch ⇒ String
Returns the git branch name extracted from the environment.
194 195 196 |
# File 'lib/datadog/ci/span.rb', line 194 def git_branch tracer_span.get_tag(Ext::Git::TAG_BRANCH) end |
#git_commit_message ⇒ String
Returns the git commit message extracted from the environment.
170 171 172 |
# File 'lib/datadog/ci/span.rb', line 170 def get_tag(Ext::Git::TAG_COMMIT_MESSAGE) end |
#git_commit_sha ⇒ String
Returns the latest commit SHA extracted from the environment.
164 165 166 |
# File 'lib/datadog/ci/span.rb', line 164 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.
158 159 160 |
# File 'lib/datadog/ci/span.rb', line 158 def git_repository_url tracer_span.get_tag(Ext::Git::TAG_REPOSITORY_URL) end |
#git_tag ⇒ String?
Returns the git tag extracted from the environment.
200 201 202 |
# File 'lib/datadog/ci/span.rb', line 200 def git_tag tracer_span.get_tag(Ext::Git::TAG_TAG) end |
#id ⇒ Integer
Returns the ID of the span.
27 28 29 |
# File 'lib/datadog/ci/span.rb', line 27 def id tracer_span.id end |
#name ⇒ String
Returns the name of the span.
37 38 39 |
# File 'lib/datadog/ci/span.rb', line 37 def name tracer_span.name end |
#original_git_commit_message ⇒ String
Returns the original last git commit message extracted from the environment. Original here means that it is the last commit that was pushed by the user, not the artifical merge commit created by CI provider
188 189 190 |
# File 'lib/datadog/ci/span.rb', line 188 def get_tag(Ext::Git::TAG_COMMIT_HEAD_MESSAGE) || end |
#original_git_commit_sha ⇒ String
Returns the original last git commit SHA extracted from the environment. Original here means that it is the last commit that was pushed by the user, not the artifical merge commit created by CI provider
179 180 181 |
# File 'lib/datadog/ci/span.rb', line 179 def original_git_commit_sha get_tag(Ext::Git::TAG_COMMIT_HEAD_SHA) || git_commit_sha end |
#os_architecture ⇒ String
Returns the OS architecture extracted from the environment.
212 213 214 |
# File 'lib/datadog/ci/span.rb', line 212 def os_architecture tracer_span.get_tag(Ext::Test::TAG_OS_ARCHITECTURE) end |
#os_platform ⇒ String
Returns the OS platform extracted from the environment.
218 219 220 |
# File 'lib/datadog/ci/span.rb', line 218 def os_platform tracer_span.get_tag(Ext::Test::TAG_OS_PLATFORM) end |
#os_version ⇒ String
Returns the OS version extracted from the environment.
224 225 226 |
# File 'lib/datadog/ci/span.rb', line 224 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".
83 84 85 |
# File 'lib/datadog/ci/span.rb', line 83 def passed! tracer_span.set_tag(Ext::Test::TAG_STATUS, Ext::Test::Status::PASS) end |
#passed? ⇒ bool
Checks whether span status is PASS.
59 60 61 |
# File 'lib/datadog/ci/span.rb', line 59 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.
230 231 232 |
# File 'lib/datadog/ci/span.rb', line 230 def runtime_name tracer_span.get_tag(Ext::Test::TAG_RUNTIME_NAME) end |
#runtime_version ⇒ String
Returns the runtime version extracted from the environment.
236 237 238 |
# File 'lib/datadog/ci/span.rb', line 236 def runtime_version tracer_span.get_tag(Ext::Test::TAG_RUNTIME_VERSION) end |
#service ⇒ String
Returns the service name of the span.
42 43 44 |
# File 'lib/datadog/ci/span.rb', line 42 def service tracer_span.service end |
#set_default_tags ⇒ Object
256 257 258 |
# File 'lib/datadog/ci/span.rb', line 256 def tracer_span.set_tag(Ext::Test::TAG_SPAN_KIND, Ext::Test::SPAN_KIND_TEST) end |
#set_environment_runtime_tags ⇒ Object
247 248 249 250 251 252 253 254 |
# File 'lib/datadog/ci/span.rb', line 247 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.
139 140 141 |
# File 'lib/datadog/ci/span.rb', line 139 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.
117 118 119 |
# File 'lib/datadog/ci/span.rb', line 117 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.
152 153 154 |
# File 'lib/datadog/ci/span.rb', line 152 def () tracer_span.() end |
#skipped!(exception: nil, reason: nil) ⇒ void
This method returns an undefined value.
Sets the status of the span to "skip".
100 101 102 103 104 |
# File 'lib/datadog/ci/span.rb', line 100 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.
71 72 73 |
# File 'lib/datadog/ci/span.rb', line 71 def skipped? tracer_span.get_tag(Ext::Test::TAG_STATUS) == Ext::Test::Status::SKIP end |
#source_file ⇒ String?
Source file path where the test or test suite defined (relative to git repository root).
243 244 245 |
# File 'lib/datadog/ci/span.rb', line 243 def source_file get_tag(Ext::Test::TAG_SOURCE_FILE) end |
#status ⇒ String?
Returns the current status of the span.
77 78 79 |
# File 'lib/datadog/ci/span.rb', line 77 def status tracer_span.get_tag(Ext::Test::TAG_STATUS) end |
#to_s ⇒ Object
260 261 262 |
# File 'lib/datadog/ci/span.rb', line 260 def to_s "#{self.class}(name:#{name},tracer_span:#{@tracer_span})" end |
#trace_id ⇒ Integer
Returns the trace ID of the trace this span belongs to.
32 33 34 |
# File 'lib/datadog/ci/span.rb', line 32 def trace_id tracer_span.trace_id end |
#type ⇒ String
Returns the type of the span (for example "test" or type that was provided to [Datadog::CI.trace]).
47 48 49 |
# File 'lib/datadog/ci/span.rb', line 47 def type tracer_span.type end |
#undefined? ⇒ bool
Checks whether span status is not set yet.
53 54 55 |
# File 'lib/datadog/ci/span.rb', line 53 def undefined? tracer_span.get_tag(Ext::Test::TAG_STATUS).nil? end |