Class: Datadog::CI::TestTracing::Serializers::Base
- Inherits:
-
Object
- Object
- Datadog::CI::TestTracing::Serializers::Base
show all
- Defined in:
- lib/datadog/ci/test_tracing/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.
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
Returns the value of attribute meta.
26
27
28
|
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 26
def meta
@meta
end
|
#options ⇒ Object
Returns the value of attribute options.
26
27
28
|
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 26
def options
@options
end
|
#span ⇒ Object
Returns the value of attribute span.
26
27
28
|
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 26
def span
@span
end
|
#trace ⇒ Object
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_fields ⇒ Object
84
85
86
|
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 84
def content_fields
[]
end
|
#content_map_size ⇒ Object
88
89
90
|
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 88
def content_map_size
0
end
|
#duration ⇒ Object
148
149
150
|
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 148
def duration
@duration ||= duration_nano(@span.duration)
end
|
#error ⇒ Object
156
157
158
|
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 156
def error
@span.status
end
|
#event_type ⇒ Object
128
129
130
|
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 128
def event_type
"span"
end
|
#metrics ⇒ Object
152
153
154
|
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 152
def metrics
@span.metrics
end
|
#name ⇒ Object
132
133
134
|
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 132
def name
@span.name
end
|
#parent_id ⇒ Object
104
105
106
|
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 104
def parent_id
@span.parent_id
end
|
#resource ⇒ Object
136
137
138
|
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 136
def resource
@span.resource
end
|
#runtime_id ⇒ Object
92
93
94
|
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 92
def runtime_id
@trace.runtime_id
end
|
#service ⇒ Object
140
141
142
|
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 140
def service
@span.service
end
|
#span_id ⇒ Object
100
101
102
|
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 100
def span_id
@span.id
end
|
#span_type ⇒ Object
124
125
126
|
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 124
def span_type
@span.type
end
|
#start ⇒ Object
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_id ⇒ Object
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_id ⇒ Object
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_id ⇒ Object
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.(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
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
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_errors ⇒ Object
80
81
82
|
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 80
def validation_errors
@errors
end
|
#version ⇒ Object
120
121
122
|
# File 'lib/datadog/ci/test_tracing/serializers/base.rb', line 120
def version
1
end
|