Class: Datadog::CI::TestVisibility::Serializers::Base
- Inherits:
-
Object
- Object
- Datadog::CI::TestVisibility::Serializers::Base
show all
- Defined in:
- lib/datadog/ci/test_visibility/serializers/base.rb
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.
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 27
def initialize(trace, span, options: {})
@trace = trace
@span = span
@options = options
@meta = @span.meta.reject { |key, _| Ext::Test::TRANSIENT_TAGS.include?(key) }
@errors = {}
@validated = false
end
|
Instance Attribute Details
Returns the value of attribute meta.
25
26
27
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 25
def meta
@meta
end
|
#options ⇒ Object
Returns the value of attribute options.
25
26
27
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 25
def options
@options
end
|
#span ⇒ Object
Returns the value of attribute span.
25
26
27
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 25
def span
@span
end
|
#trace ⇒ Object
Returns the value of attribute trace.
25
26
27
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 25
def trace
@trace
end
|
Class Method Details
.calculate_content_map_size(fields_list) ⇒ Object
157
158
159
160
161
162
163
164
165
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 157
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_fields ⇒ Object
81
82
83
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 81
def content_fields
[]
end
|
#content_map_size ⇒ Object
85
86
87
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 85
def content_map_size
0
end
|
#duration ⇒ Object
145
146
147
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 145
def duration
@duration ||= duration_nano(@span.duration)
end
|
#error ⇒ Object
153
154
155
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 153
def error
@span.status
end
|
#event_type ⇒ Object
125
126
127
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 125
def event_type
"span"
end
|
#metrics ⇒ Object
149
150
151
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 149
def metrics
@span.metrics
end
|
#name ⇒ Object
129
130
131
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 129
def name
@span.name
end
|
#parent_id ⇒ Object
101
102
103
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 101
def parent_id
@span.parent_id
end
|
#resource ⇒ Object
133
134
135
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 133
def resource
@span.resource
end
|
#runtime_id ⇒ Object
89
90
91
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 89
def runtime_id
@trace.runtime_id
end
|
#service ⇒ Object
137
138
139
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 137
def service
@span.service
end
|
#span_id ⇒ Object
97
98
99
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 97
def span_id
@span.id
end
|
#span_type ⇒ Object
121
122
123
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 121
def span_type
@span.type
end
|
#start ⇒ Object
141
142
143
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 141
def start
@start ||= time_nano(@span.start_time)
end
|
#test_module_id ⇒ Object
109
110
111
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 109
def test_module_id
to_integer(@span.get_tag(Ext::Test::TAG_TEST_MODULE_ID))
end
|
#test_session_id ⇒ Object
105
106
107
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 105
def test_session_id
to_integer(@span.get_tag(Ext::Test::TAG_TEST_SESSION_ID))
end
|
#test_suite_id ⇒ Object
113
114
115
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 113
def test_suite_id
to_integer(@span.get_tag(Ext::Test::TAG_TEST_SUITE_ID))
end
|
#to_msgpack(packer = nil) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 38
def to_msgpack(packer = nil)
packer ||= MessagePack::Packer.new
packer.(3)
write_field(packer, "type", "event_type")
write_field(packer, "version")
packer.write("content")
packer.(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_id ⇒ Object
93
94
95
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 93
def trace_id
@trace.id
end
|
#valid? ⇒ Boolean
validates according to citestcycle json schema
61
62
63
64
65
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 61
def valid?
validate! unless @validated
@errors.empty?
end
|
#validate! ⇒ Object
67
68
69
70
71
72
73
74
75
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 67
def validate!
@errors.clear
validate_required_fields!
validate_start_time!
validate_duration!
@validated = true
end
|
#validation_errors ⇒ Object
77
78
79
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 77
def validation_errors
@errors
end
|
#version ⇒ Object
117
118
119
|
# File 'lib/datadog/ci/test_visibility/serializers/base.rb', line 117
def version
1
end
|