Class: Datadog::CI::Span
- Inherits:
-
Object
- Object
- Datadog::CI::Span
- Defined in:
- lib/datadog/ci/span.rb,
sig/datadog/ci/span.rbs
Overview
Represents a single part of a test run. Could be a session, suite, test, or any custom span.
Direct Known Subclasses
Constant Summary collapse
- ENVIRONMENT_RUNTIME_TAGS =
{ Ext::Test::TAG_OS_ARCHITECTURE => ::RbConfig::CONFIG["host_cpu"], Ext::Test::TAG_OS_PLATFORM => ::RbConfig::CONFIG["host_os"], Ext::Test::TAG_OS_VERSION => Core::Environment::Platform.kernel_release, Ext::Test::TAG_RUNTIME_NAME => Core::Environment::Ext::LANG_ENGINE, Ext::Test::TAG_RUNTIME_VERSION => Core::Environment::Ext::ENGINE_VERSION }.freeze
- EMPTY_TAGS =
{}.freeze
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_internal_tag(key) ⇒ void
-
#clear_tag(key) ⇒ void
Removes a custom tag.
-
#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 ⇒ void
- #set_environment_runtime_tags ⇒ void
- #set_internal_metric(key, value) ⇒ void
- #set_internal_tag(key, value) ⇒ void
- #set_internal_tags(tags) ⇒ void
-
#set_metric(key, value) ⇒ void
Sets a custom metric.
- #set_parameters ⇒ void
-
#set_tag(key, value) ⇒ void
Sets a custom tag.
-
#set_tags(tags) ⇒ void
Sets multiple tags at once.
- #shared_tags ⇒ Hash[String, String]
-
#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.
-
#test_tracing ⇒ Object
provides access to the test tracing component for CI models to deactivate themselves.
- #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.
34 35 36 |
# File 'lib/datadog/ci/span.rb', line 34 def initialize(tracer_span) @tracer_span = tracer_span end |
Instance Attribute Details
#tracer_span ⇒ Object (readonly)
Returns the value of attribute tracer_span.
32 33 34 |
# File 'lib/datadog/ci/span.rb', line 32 def tracer_span @tracer_span end |
Instance Method Details
#base_commit_sha ⇒ String?
Returns the base commit SHA for the pull request, if available.
244 245 246 |
# File 'lib/datadog/ci/span.rb', line 244 def base_commit_sha get_tag(Ext::Git::TAG_PULL_REQUEST_BASE_BRANCH_SHA) end |
#clear_internal_tag(key) ⇒ void
This method returns an undefined value.
150 151 152 |
# File 'lib/datadog/ci/span.rb', line 150 def clear_internal_tag(key) tracer_span.clear_tag(key) end |
#clear_tag(key) ⇒ void
This method returns an undefined value.
Removes a custom tag. SDK-owned fields are read-only through this method.
143 144 145 146 147 |
# File 'lib/datadog/ci/span.rb', line 143 def clear_tag(key) return if Utils::ProtectedTags.reject?(key, :clear_tag) clear_internal_tag(key) end |
#failed!(exception: nil) ⇒ void
This method returns an undefined value.
Sets the status of the span to "fail".
102 103 104 105 106 |
# File 'lib/datadog/ci/span.rb', line 102 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.
77 78 79 |
# File 'lib/datadog/ci/span.rb', line 77 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.
178 179 180 |
# File 'lib/datadog/ci/span.rb', line 178 def finish tracer_span.finish end |
#get_metric(key) ⇒ Numeric
Gets metric value by key.
157 158 159 |
# File 'lib/datadog/ci/span.rb', line 157 def get_metric(key) [key] || tracer_span.get_metric(key) end |
#get_tag(key) ⇒ String
Gets tag value by key.
121 122 123 |
# File 'lib/datadog/ci/span.rb', line 121 def get_tag(key) [key] || tracer_span.get_tag(key) end |
#git_branch ⇒ String
Returns the git branch name extracted from the environment.
232 233 234 |
# File 'lib/datadog/ci/span.rb', line 232 def git_branch get_tag(Ext::Git::TAG_BRANCH) end |
#git_commit_message ⇒ String
Returns the git commit message extracted from the environment.
208 209 210 |
# File 'lib/datadog/ci/span.rb', line 208 def get_tag(Ext::Git::TAG_COMMIT_MESSAGE) end |
#git_commit_sha ⇒ String
Returns the latest commit SHA extracted from the environment.
202 203 204 |
# File 'lib/datadog/ci/span.rb', line 202 def git_commit_sha get_tag(Ext::Git::TAG_COMMIT_SHA) end |
#git_repository_url ⇒ String
Returns the git repository URL extracted from the environment.
196 197 198 |
# File 'lib/datadog/ci/span.rb', line 196 def git_repository_url get_tag(Ext::Git::TAG_REPOSITORY_URL) end |
#git_tag ⇒ String?
Returns the git tag extracted from the environment.
238 239 240 |
# File 'lib/datadog/ci/span.rb', line 238 def git_tag get_tag(Ext::Git::TAG_TAG) end |
#id ⇒ Integer
Returns the ID of the span.
39 40 41 |
# File 'lib/datadog/ci/span.rb', line 39 def id tracer_span.id end |
#name ⇒ String
Returns the name of the span.
49 50 51 |
# File 'lib/datadog/ci/span.rb', line 49 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
226 227 228 |
# File 'lib/datadog/ci/span.rb', line 226 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
217 218 219 |
# File 'lib/datadog/ci/span.rb', line 217 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.
250 251 252 |
# File 'lib/datadog/ci/span.rb', line 250 def os_architecture tracer_span.get_tag(Ext::Test::TAG_OS_ARCHITECTURE) end |
#os_platform ⇒ String
Returns the OS platform extracted from the environment.
256 257 258 |
# File 'lib/datadog/ci/span.rb', line 256 def os_platform tracer_span.get_tag(Ext::Test::TAG_OS_PLATFORM) end |
#os_version ⇒ String
Returns the OS version extracted from the environment.
262 263 264 |
# File 'lib/datadog/ci/span.rb', line 262 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".
95 96 97 |
# File 'lib/datadog/ci/span.rb', line 95 def passed! tracer_span.set_tag(Ext::Test::TAG_STATUS, Ext::Test::Status::PASS) end |
#passed? ⇒ bool
Checks whether span status is PASS.
71 72 73 |
# File 'lib/datadog/ci/span.rb', line 71 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.
268 269 270 |
# File 'lib/datadog/ci/span.rb', line 268 def runtime_name tracer_span.get_tag(Ext::Test::TAG_RUNTIME_NAME) end |
#runtime_version ⇒ String
Returns the runtime version extracted from the environment.
274 275 276 |
# File 'lib/datadog/ci/span.rb', line 274 def runtime_version tracer_span.get_tag(Ext::Test::TAG_RUNTIME_VERSION) end |
#service ⇒ String
Returns the service name of the span.
54 55 56 |
# File 'lib/datadog/ci/span.rb', line 54 def service tracer_span.service end |
#set_default_tags ⇒ void
This method returns an undefined value.
290 291 292 |
# File 'lib/datadog/ci/span.rb', line 290 def tracer_span.set_tag(Ext::Test::TAG_SPAN_KIND, Ext::Test::SPAN_KIND_TEST) end |
#set_environment_runtime_tags ⇒ void
This method returns an undefined value.
285 286 287 288 |
# File 'lib/datadog/ci/span.rb', line 285 def tracer_span.(ENVIRONMENT_RUNTIME_TAGS) tracer_span.set_tag(Ext::Test::TAG_COMMAND, Utils::TestRun.command) end |
#set_internal_metric(key, value) ⇒ void
This method returns an undefined value.
172 173 174 |
# File 'lib/datadog/ci/span.rb', line 172 def set_internal_metric(key, value) tracer_span.set_metric(key, value) end |
#set_internal_tag(key, value) ⇒ void
This method returns an undefined value.
136 137 138 |
# File 'lib/datadog/ci/span.rb', line 136 def set_internal_tag(key, value) tracer_span.set_tag(key, value) end |
#set_internal_tags(tags) ⇒ void
This method returns an undefined value.
190 191 192 |
# File 'lib/datadog/ci/span.rb', line 190 def () tracer_span.() end |
#set_metric(key, value) ⇒ void
This method returns an undefined value.
Sets a custom metric. SDK-owned fields are read-only through this method.
165 166 167 168 169 |
# File 'lib/datadog/ci/span.rb', line 165 def set_metric(key, value) return if Utils::ProtectedTags.reject?(key, :set_metric) set_internal_metric(key, value) end |
#set_parameters ⇒ void
This method returns an undefined value.
63 |
# File 'sig/datadog/ci/span.rbs', line 63
def set_parameters: (Hash[String, Object] arguments, ?Hash[String, Object] metadata) -> void
|
#set_tag(key, value) ⇒ void
This method returns an undefined value.
Sets a custom tag. SDK-owned fields are read-only through this method.
129 130 131 132 133 |
# File 'lib/datadog/ci/span.rb', line 129 def set_tag(key, value) return if Utils::ProtectedTags.reject?(key, :set_tag) set_internal_tag(key, value) end |
#set_tags(tags) ⇒ void
This method returns an undefined value.
Sets multiple tags at once.
185 186 187 |
# File 'lib/datadog/ci/span.rb', line 185 def () .each { |key, value| set_tag(key, value) } end |
#shared_tags ⇒ Hash[String, String]
300 301 302 303 304 |
# File 'lib/datadog/ci/span.rb', line 300 def return EMPTY_TAGS unless Ext::AppTypes::CI_SPAN_TYPES.include?(type) test_tracing. end |
#skipped!(exception: nil, reason: nil) ⇒ void
This method returns an undefined value.
Sets the status of the span to "skip".
112 113 114 115 116 |
# File 'lib/datadog/ci/span.rb', line 112 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.
83 84 85 |
# File 'lib/datadog/ci/span.rb', line 83 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).
281 282 283 |
# File 'lib/datadog/ci/span.rb', line 281 def source_file get_tag(Ext::Test::TAG_SOURCE_FILE) end |
#status ⇒ String?
Returns the current status of the span.
89 90 91 |
# File 'lib/datadog/ci/span.rb', line 89 def status tracer_span.get_tag(Ext::Test::TAG_STATUS) end |
#test_tracing ⇒ Object
provides access to the test tracing component for CI models to deactivate themselves
307 308 309 |
# File 'lib/datadog/ci/span.rb', line 307 def test_tracing Datadog.send(:components).test_tracing end |
#to_s ⇒ Object
294 295 296 |
# File 'lib/datadog/ci/span.rb', line 294 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.
44 45 46 |
# File 'lib/datadog/ci/span.rb', line 44 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]).
59 60 61 |
# File 'lib/datadog/ci/span.rb', line 59 def type tracer_span.type end |
#undefined? ⇒ bool
Checks whether span status is not set yet.
65 66 67 |
# File 'lib/datadog/ci/span.rb', line 65 def undefined? tracer_span.get_tag(Ext::Test::TAG_STATUS).nil? end |