Class: Datadog::CI::Span

Inherits:
Object
  • Object
show all
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

Test

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tracer_span) ⇒ Span

Returns a new instance of Span.



14
15
16
# File 'lib/datadog/ci/span.rb', line 14

def initialize(tracer_span)
  @tracer_span = tracer_span
end

Instance Attribute Details

#tracer_spanObject (readonly)

Returns the value of attribute tracer_span.



12
13
14
# File 'lib/datadog/ci/span.rb', line 12

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”.

Parameters:

  • exception (Exception) (defaults to: nil)

    the exception that caused the test to fail.



37
38
39
40
41
# File 'lib/datadog/ci/span.rb', line 37

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

#finishvoid

This method returns an undefined value.

Finishes the span.



78
79
80
# File 'lib/datadog/ci/span.rb', line 78

def finish
  tracer_span.finish
end

#get_tag(key) ⇒ String

Gets tag value by key.

Parameters:

  • key (String)

    the key of the tag.

Returns:

  • (String)

    the value of the tag.



56
57
58
# File 'lib/datadog/ci/span.rb', line 56

def get_tag(key)
  tracer_span.get_tag(key)
end

#nameString

Returns the name of the span.

Returns:

  • (String)

    the name of the span.



19
20
21
# File 'lib/datadog/ci/span.rb', line 19

def name
  tracer_span.name
end

#passed!void

This method returns an undefined value.

Sets the status of the span to “pass”.



30
31
32
# File 'lib/datadog/ci/span.rb', line 30

def passed!
  tracer_span.set_tag(Ext::Test::TAG_STATUS, Ext::Test::Status::PASS)
end

#set_default_tagsObject



98
99
100
# File 'lib/datadog/ci/span.rb', line 98

def set_default_tags
  tracer_span.set_tag(Ext::Test::TAG_SPAN_KIND, Ext::AppTypes::TYPE_TEST)
end

#set_environment_runtime_tagsObject



91
92
93
94
95
96
# File 'lib/datadog/ci/span.rb', line 91

def set_environment_runtime_tags
  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_RUNTIME_NAME, Core::Environment::Ext::LANG_ENGINE)
  tracer_span.set_tag(Ext::Test::TAG_RUNTIME_VERSION, Core::Environment::Ext::ENGINE_VERSION)
end

#set_metric(key, value) ⇒ void

This method returns an undefined value.

Sets metric value by key.

Parameters:

  • key (String)

    the key of the metric.

  • value (Numeric)

    the value of the metric.



72
73
74
# File 'lib/datadog/ci/span.rb', line 72

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.

Parameters:

  • key (String)

    the key of the tag.

  • value (String)

    the value of the tag.



64
65
66
# File 'lib/datadog/ci/span.rb', line 64

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.

Parameters:

  • tags (Hash[String, String])

    the tags to set.



85
86
87
88
89
# File 'lib/datadog/ci/span.rb', line 85

def set_tags(tags)
  tags.each do |key, value|
    tracer_span.set_tag(key, value)
  end
end

#skipped!(exception: nil, reason: nil) ⇒ void

This method returns an undefined value.

Sets the status of the span to “skip”.

Parameters:

  • exception (Exception) (defaults to: nil)

    the exception that caused the test to fail.

  • reason (String) (defaults to: nil)

    the reason why the test was skipped.



47
48
49
50
51
# File 'lib/datadog/ci/span.rb', line 47

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

#span_typeString

Returns the type of the span (for example “test” or type that was provided to [Datadog::CI.trace]).

Returns:

  • (String)

    the type of the span (for example “test” or type that was provided to [Datadog::CI.trace]).



24
25
26
# File 'lib/datadog/ci/span.rb', line 24

def span_type
  tracer_span.type
end

#to_sObject



102
103
104
# File 'lib/datadog/ci/span.rb', line 102

def to_s
  "#{self.class}(name:#{name},tracer_span:#{@tracer_span})"
end