Class: Datadog::CI::TestTracing::Serializers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/ci/test_tracing/serializers/base.rb

Direct Known Subclasses

Span, TestModule, TestSession, TestSuite, TestV1

Constant Summary collapse

MINIMUM_TIMESTAMP_NANO =
946684800000000000
MINIMUM_DURATION_NANO =
0
MAXIMUM_DURATION_NANO =
9223372036854775807
CONTENT_FIELDS =
[
  "name", "resource", "service",
  "error", "start", "duration",
  "meta", "metrics",
  "type" => "span_type"
].freeze
REQUIRED_FIELDS =
%w[error name resource start duration].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(trace, span, options: {}) ⇒ Base

Returns a new instance of Base.



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 28

def initialize(trace, span, options: {})
  @trace = trace
  @span = span
  @options = options

  @meta = MetaTruncation.truncate_string_values(
    @span.meta.reject { |key, _| Ext::Test::TRANSIENT_TAGS.include?(key) }
  )

  @errors = {}
  @validated = false
end

Instance Attribute Details

#metaObject (readonly)

Returns the value of attribute meta.



26
27
28
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 26

def meta
  @meta
end

#optionsObject (readonly)

Returns the value of attribute options.



26
27
28
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 26

def options
  @options
end

#spanObject (readonly)

Returns the value of attribute span.



26
27
28
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 26

def span
  @span
end

#traceObject (readonly)

Returns the value of attribute trace.



26
27
28
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 26

def trace
  @trace
end

Class Method Details

.calculate_content_map_size(fields_list) ⇒ Object



160
161
162
163
164
165
166
167
168
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 160

def self.calculate_content_map_size(fields_list)
  fields_list.reduce(0) do |size, field|
    if field.is_a?(Hash)
      size + field.size
    else
      size + 1
    end
  end
end

Instance Method Details

#content_fieldsObject



84
85
86
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 84

def content_fields
  []
end

#content_map_sizeObject



88
89
90
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 88

def content_map_size
  0
end

#durationObject



148
149
150
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 148

def duration
  @duration ||= duration_nano(@span.duration)
end

#errorObject



156
157
158
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 156

def error
  @span.status
end

#event_typeObject



128
129
130
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 128

def event_type
  "span"
end

#metricsObject



152
153
154
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 152

def metrics
  @span.metrics
end

#nameObject



132
133
134
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 132

def name
  @span.name
end

#parent_idObject



104
105
106
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 104

def parent_id
  @span.parent_id
end

#resourceObject



136
137
138
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 136

def resource
  @span.resource
end

#runtime_idObject



92
93
94
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 92

def runtime_id
  @trace.runtime_id
end

#serviceObject



140
141
142
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 140

def service
  @span.service
end

#span_idObject



100
101
102
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 100

def span_id
  @span.id
end

#span_typeObject



124
125
126
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 124

def span_type
  @span.type
end

#startObject



144
145
146
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 144

def start
  @start ||= time_nano(@span.start_time)
end

#test_module_idObject



112
113
114
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 112

def test_module_id
  to_integer(@span.get_tag(Ext::Test::TAG_TEST_MODULE_ID))
end

#test_session_idObject



108
109
110
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 108

def test_session_id
  to_integer(@span.get_tag(Ext::Test::TAG_TEST_SESSION_ID))
end

#test_suite_idObject



116
117
118
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 116

def test_suite_id
  to_integer(@span.get_tag(Ext::Test::TAG_TEST_SUITE_ID))
end

#to_msgpack(packer = nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 41

def to_msgpack(packer = nil)
  packer ||= MessagePack::Packer.new

  packer.write_map_header(3)

  write_field(packer, "type", "event_type")
  write_field(packer, "version")

  packer.write("content")
  packer.write_map_header(content_map_size)

  content_fields.each do |field|
    if field.is_a?(Hash)
      field.each do |field_name, method|
        write_field(packer, field_name, method)
      end
    else
      write_field(packer, field)
    end
  end
end

#trace_idObject



96
97
98
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 96

def trace_id
  @trace.id
end

#valid?Boolean

validates according to citestcycle json schema

Returns:

  • (Boolean)


64
65
66
67
68
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 64

def valid?
  validate! unless @validated

  @errors.empty?
end

#validate!Object



70
71
72
73
74
75
76
77
78
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 70

def validate!
  @errors.clear

  validate_required_fields!
  validate_start_time!
  validate_duration!

  @validated = true
end

#validation_errorsObject



80
81
82
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 80

def validation_errors
  @errors
end

#versionObject



120
121
122
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 120

def version
  1
end