bugsnag-maze-runner 6.27.0 → 7.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/download-logs +14 -16
- data/bin/maze-runner +53 -15
- data/bin/upload-app +6 -6
- data/lib/features/steps/breadcrumb_steps.rb +44 -14
- data/lib/features/steps/error_reporting_steps.rb +16 -0
- data/lib/features/steps/network_steps.rb +66 -6
- data/lib/features/steps/payload_steps.rb +23 -0
- data/lib/features/steps/request_assertion_steps.rb +87 -8
- data/lib/features/steps/runner_steps.rb +22 -0
- data/lib/features/steps/session_tracking_steps.rb +1 -1
- data/lib/features/steps/trace_steps.rb +254 -0
- data/lib/features/support/internal_hooks.rb +31 -84
- data/lib/maze/api/appium/file_manager.rb +29 -0
- data/lib/maze/aws_public_ip.rb +53 -0
- data/lib/maze/checks/assert_check.rb +9 -31
- data/lib/maze/client/appium/base_client.rb +131 -0
- data/lib/maze/client/appium/bb_client.rb +102 -0
- data/lib/maze/client/appium/bb_devices.rb +127 -0
- data/lib/maze/client/appium/bs_client.rb +91 -0
- data/lib/maze/client/appium/bs_devices.rb +141 -0
- data/lib/maze/client/appium/bs_legacy_client.rb +31 -0
- data/lib/maze/client/appium/local_client.rb +67 -0
- data/lib/maze/client/appium.rb +23 -0
- data/lib/maze/client/bb_api_client.rb +102 -0
- data/lib/maze/client/bb_client_utils.rb +181 -0
- data/lib/maze/client/bs_client_utils.rb +168 -0
- data/lib/maze/client/selenium/base_client.rb +15 -0
- data/lib/maze/client/selenium/bb_browsers.yml +188 -0
- data/lib/maze/client/selenium/bb_client.rb +38 -0
- data/lib/maze/client/selenium/bs_browsers.yml +257 -0
- data/lib/maze/client/selenium/bs_client.rb +89 -0
- data/lib/maze/client/selenium/local_client.rb +16 -0
- data/lib/maze/client/selenium.rb +16 -0
- data/lib/maze/configuration.rb +18 -10
- data/lib/maze/docker.rb +40 -1
- data/lib/maze/driver/appium.rb +5 -24
- data/lib/maze/driver/browser.rb +12 -26
- data/lib/maze/errors.rb +32 -0
- data/lib/maze/generator.rb +55 -0
- data/lib/maze/helper.rb +7 -3
- data/lib/maze/hooks/appium_hooks.rb +29 -190
- data/lib/maze/hooks/browser_hooks.rb +2 -55
- data/lib/maze/hooks/error_code_hook.rb +49 -0
- data/lib/maze/hooks/hooks.rb +2 -2
- data/lib/maze/http_request.rb +21 -0
- data/lib/maze/logger.rb +16 -3
- data/lib/maze/maze_output.rb +88 -0
- data/lib/maze/option/parser.rb +17 -22
- data/lib/maze/option/processor.rb +21 -34
- data/lib/maze/option/validator.rb +38 -67
- data/lib/maze/option.rb +16 -18
- data/lib/maze/plugins/cucumber_report_plugin.rb +1 -1
- data/lib/maze/plugins/error_code_plugin.rb +21 -0
- data/lib/maze/request_list.rb +10 -5
- data/lib/maze/request_repeater.rb +49 -0
- data/lib/maze/retry_handler.rb +4 -13
- data/lib/maze/schemas/OtelTraceSchema.json +390 -0
- data/lib/maze/schemas/trace_schema.rb +7 -0
- data/lib/maze/schemas/trace_validator.rb +98 -0
- data/lib/maze/server.rb +74 -30
- data/lib/maze/servlets/base_servlet.rb +10 -5
- data/lib/maze/servlets/command_servlet.rb +10 -7
- data/lib/maze/servlets/log_servlet.rb +2 -2
- data/lib/maze/servlets/reflective_servlet.rb +12 -11
- data/lib/maze/servlets/servlet.rb +47 -8
- data/lib/maze/servlets/temp.rb +0 -0
- data/lib/maze/servlets/trace_servlet.rb +13 -0
- data/lib/maze.rb +2 -2
- data/lib/utils/deep_merge.rb +17 -0
- data/lib/utils/selenium_money_patch.rb +17 -0
- metadata +97 -17
- data/lib/maze/bitbar_devices.rb +0 -84
- data/lib/maze/bitbar_utils.rb +0 -112
- data/lib/maze/browser_stack_devices.rb +0 -160
- data/lib/maze/browser_stack_utils.rb +0 -164
- data/lib/maze/browsers_bs.yml +0 -220
- data/lib/maze/browsers_cbt.yml +0 -100
- data/lib/maze/capabilities.rb +0 -126
- data/lib/maze/driver/resilient_appium.rb +0 -51
- data/lib/maze/sauce_labs_utils.rb +0 -96
- data/lib/maze/smart_bear_utils.rb +0 -71
data/lib/maze/request_list.rb
CHANGED
@@ -10,12 +10,8 @@ module Maze
|
|
10
10
|
@count = 0
|
11
11
|
end
|
12
12
|
|
13
|
-
def empty?
|
14
|
-
@requests.empty?
|
15
|
-
end
|
16
|
-
|
17
13
|
# The number of unprocessed/remaining requests in the list (not the total number actually held)
|
18
|
-
def
|
14
|
+
def size_remaining
|
19
15
|
@count
|
20
16
|
end
|
21
17
|
|
@@ -78,5 +74,14 @@ module Maze
|
|
78
74
|
sub_list.sort_by! { |r| DateTime.parse(r[:request][header]) }
|
79
75
|
sub_list.each_with_index { |r, i| @requests[@current + i] = r }
|
80
76
|
end
|
77
|
+
|
78
|
+
# Sorts the remaining elements of the list by the field given, if present in all of those elements
|
79
|
+
def sort_by!(key_path)
|
80
|
+
list = remaining
|
81
|
+
|
82
|
+
# Sort the list and overwrite in the main list
|
83
|
+
list.sort_by! { |r| Maze::Helper.read_key_path(r[:body], key_path) }
|
84
|
+
list.each_with_index { |r, i| @requests[@current + i] = r }
|
85
|
+
end
|
81
86
|
end
|
82
87
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Maze
|
2
|
+
# Repeats POST requests
|
3
|
+
module RequestRepeater
|
4
|
+
|
5
|
+
def do_POST(request, response)
|
6
|
+
repeat(request) if enabled?
|
7
|
+
|
8
|
+
super(request, response)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def enabled?
|
14
|
+
# enabled if the config option is on and this request type should be repeated
|
15
|
+
Maze.config.repeater_api_key && url_for_request_type
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param request [HTTPRequest] The request to be repeated
|
19
|
+
def repeat(request)
|
20
|
+
|
21
|
+
# TODO Forwarding of internal errors to be considered later
|
22
|
+
return if request.header.keys.any? { |key| key.downcase == 'bugsnag-internal-error' }
|
23
|
+
|
24
|
+
url = url_for_request_type
|
25
|
+
http = Net::HTTP.new(url.host)
|
26
|
+
bugsnag_request = Net::HTTP::Post.new(url.path)
|
27
|
+
|
28
|
+
# Set all headers that are present
|
29
|
+
bugsnag_request.body = request.body
|
30
|
+
request.header.each {|key,value| bugsnag_request[key] = value }
|
31
|
+
bugsnag_request['bugsnag-api-key'] = Maze.config.repeater_api_key
|
32
|
+
|
33
|
+
# TODO Also overwrite apiKey in the payload, if present, recalculate the integrity header (handling
|
34
|
+
# compressed payloads if the content-encoding header is set accordingly)
|
35
|
+
|
36
|
+
http.request(bugsnag_request)
|
37
|
+
end
|
38
|
+
|
39
|
+
def url_for_request_type
|
40
|
+
url = case @request_type
|
41
|
+
when :errors then 'https://notify.bugsnag.com/'
|
42
|
+
when :sessions then 'https://sessions.bugsnag.com/'
|
43
|
+
when :traces then 'https://otlp.bugsnag.com/v1/traces'
|
44
|
+
else return nil
|
45
|
+
end
|
46
|
+
URI.parse(url)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/maze/retry_handler.rb
CHANGED
@@ -8,17 +8,6 @@ module Maze
|
|
8
8
|
class RetryHandler
|
9
9
|
class << self
|
10
10
|
|
11
|
-
# Errors which indicate a selenium/appium driver has crashed and needs to be restarted
|
12
|
-
DRIVER_ERRORS = [
|
13
|
-
Maze::Error::AppiumElementNotFoundError,
|
14
|
-
|
15
|
-
Selenium::WebDriver::Error::NoSuchElementError,
|
16
|
-
Selenium::WebDriver::Error::StaleElementReferenceError,
|
17
|
-
Selenium::WebDriver::Error::TimeoutError,
|
18
|
-
Selenium::WebDriver::Error::UnknownError,
|
19
|
-
Selenium::WebDriver::Error::WebDriverError
|
20
|
-
].freeze
|
21
|
-
|
22
11
|
# Acceptable tags to indicate a test should be restarted
|
23
12
|
RETRY_TAGS = %w[@retry @retryable @retriable].freeze
|
24
13
|
|
@@ -32,7 +21,7 @@ module Maze
|
|
32
21
|
|
33
22
|
if retry_on_driver_error?(event)
|
34
23
|
$logger.warn "Retrying #{test_case.name} due to driver error: #{event.result.exception}"
|
35
|
-
if Maze.driver.is_a?(Maze::Driver::Appium)
|
24
|
+
if Maze.driver.is_a?(Maze::Driver::Appium)
|
36
25
|
Maze.driver.restart
|
37
26
|
elsif Maze.driver.is_a?(Maze::Driver::Browser)
|
38
27
|
Maze.driver.refresh
|
@@ -59,7 +48,9 @@ module Maze
|
|
59
48
|
end
|
60
49
|
|
61
50
|
def retry_on_driver_error?(event)
|
62
|
-
|
51
|
+
error_class = event.result.exception.class
|
52
|
+
maze_errors = Maze::Error::ERROR_CODES
|
53
|
+
Maze.driver && maze_errors.include?(error_class) && maze_errors[error_class][:retry]
|
63
54
|
end
|
64
55
|
|
65
56
|
def retry_on_tag?(test_case)
|
@@ -0,0 +1,390 @@
|
|
1
|
+
{
|
2
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
3
|
+
"$ref": "#/definitions/TracesData",
|
4
|
+
"definitions": {
|
5
|
+
"TracesData": {
|
6
|
+
"properties": {
|
7
|
+
"resourceSpans": {
|
8
|
+
"items": {
|
9
|
+
"$ref": "#/definitions/opentelemetry.proto.trace.v1.ResourceSpans"
|
10
|
+
},
|
11
|
+
"type": "array",
|
12
|
+
"description": "An array of ResourceSpans. For data coming from a single resource this array will typically contain one element. Intermediary nodes that receive data from multiple origins typically batch the data before forwarding further and in that case this array will contain multiple elements."
|
13
|
+
}
|
14
|
+
},
|
15
|
+
"additionalProperties": false,
|
16
|
+
"type": "object",
|
17
|
+
"title": "Traces Data",
|
18
|
+
"description": "TracesData represents the traces data that can be stored in a persistent storage, OR can be embedded by other protocols that transfer OTLP traces data but do not implement the OTLP protocol. The main difference between this message and collector protocol is that in this message there will not be any \"control\" or \"metadata\" specific to OTLP protocol. When new fields are added into this message, the OTLP request MUST be updated as well."
|
19
|
+
},
|
20
|
+
"opentelemetry.proto.common.v1.AnyValue": {
|
21
|
+
"properties": {
|
22
|
+
"stringValue": {
|
23
|
+
"type": "string"
|
24
|
+
},
|
25
|
+
"boolValue": {
|
26
|
+
"type": "boolean"
|
27
|
+
},
|
28
|
+
"intValue": {
|
29
|
+
"type": "string"
|
30
|
+
},
|
31
|
+
"doubleValue": {
|
32
|
+
"type": "number"
|
33
|
+
},
|
34
|
+
"arrayValue": {
|
35
|
+
"$ref": "#/definitions/opentelemetry.proto.common.v1.ArrayValue",
|
36
|
+
"additionalProperties": false
|
37
|
+
},
|
38
|
+
"kvlistValue": {
|
39
|
+
"$ref": "#/definitions/opentelemetry.proto.common.v1.KeyValueList",
|
40
|
+
"additionalProperties": false
|
41
|
+
},
|
42
|
+
"bytesValue": {
|
43
|
+
"type": "string",
|
44
|
+
"format": "binary",
|
45
|
+
"binaryEncoding": "base64"
|
46
|
+
}
|
47
|
+
},
|
48
|
+
"additionalProperties": false,
|
49
|
+
"type": "object",
|
50
|
+
"title": "Any Value",
|
51
|
+
"description": "AnyValue is used to represent any type of attribute value. AnyValue may contain a primitive value such as a string or integer or it may contain an arbitrary nested object containing arrays, key-value lists and primitives."
|
52
|
+
},
|
53
|
+
"opentelemetry.proto.common.v1.ArrayValue": {
|
54
|
+
"properties": {
|
55
|
+
"values": {
|
56
|
+
"items": {
|
57
|
+
"$ref": "#/definitions/opentelemetry.proto.common.v1.AnyValue"
|
58
|
+
},
|
59
|
+
"type": "array",
|
60
|
+
"description": "Array of values. The array may be empty (contain 0 elements)."
|
61
|
+
}
|
62
|
+
},
|
63
|
+
"additionalProperties": false,
|
64
|
+
"type": "object",
|
65
|
+
"title": "Array Value",
|
66
|
+
"description": "ArrayValue is a list of AnyValue messages. We need ArrayValue as a message since oneof in AnyValue does not allow repeated fields."
|
67
|
+
},
|
68
|
+
"opentelemetry.proto.common.v1.InstrumentationScope": {
|
69
|
+
"properties": {
|
70
|
+
"name": {
|
71
|
+
"type": "string",
|
72
|
+
"description": "An empty instrumentation scope name means the name is unknown."
|
73
|
+
},
|
74
|
+
"version": {
|
75
|
+
"type": "string"
|
76
|
+
},
|
77
|
+
"attributes": {
|
78
|
+
"items": {
|
79
|
+
"$ref": "#/definitions/opentelemetry.proto.common.v1.KeyValue"
|
80
|
+
},
|
81
|
+
"type": "array"
|
82
|
+
},
|
83
|
+
"droppedAttributesCount": {
|
84
|
+
"type": "integer"
|
85
|
+
}
|
86
|
+
},
|
87
|
+
"additionalProperties": false,
|
88
|
+
"type": "object",
|
89
|
+
"title": "Instrumentation Scope",
|
90
|
+
"description": "InstrumentationScope is a message representing the instrumentation scope information such as the fully qualified name and version."
|
91
|
+
},
|
92
|
+
"opentelemetry.proto.common.v1.KeyValue": {
|
93
|
+
"properties": {
|
94
|
+
"key": {
|
95
|
+
"type": "string"
|
96
|
+
},
|
97
|
+
"value": {
|
98
|
+
"$ref": "#/definitions/opentelemetry.proto.common.v1.AnyValue",
|
99
|
+
"additionalProperties": false
|
100
|
+
}
|
101
|
+
},
|
102
|
+
"additionalProperties": false,
|
103
|
+
"type": "object",
|
104
|
+
"title": "Key Value",
|
105
|
+
"description": "KeyValue is a key-value pair that is used to store Span attributes, Link attributes, etc."
|
106
|
+
},
|
107
|
+
"opentelemetry.proto.common.v1.KeyValueList": {
|
108
|
+
"properties": {
|
109
|
+
"values": {
|
110
|
+
"items": {
|
111
|
+
"$ref": "#/definitions/opentelemetry.proto.common.v1.KeyValue"
|
112
|
+
},
|
113
|
+
"type": "array",
|
114
|
+
"description": "A collection of key/value pairs of key-value pairs. The list may be empty (may contain 0 elements). The keys MUST be unique (it is not allowed to have more than one value with the same key)."
|
115
|
+
}
|
116
|
+
},
|
117
|
+
"additionalProperties": false,
|
118
|
+
"type": "object",
|
119
|
+
"title": "Key Value List",
|
120
|
+
"description": "KeyValueList is a list of KeyValue messages. We need KeyValueList as a message since `oneof` in AnyValue does not allow repeated fields. Everywhere else where we need a list of KeyValue messages (e.g. in Span) we use `repeated KeyValue` directly to avoid unnecessary extra wrapping (which slows down the protocol). The 2 approaches are semantically equivalent."
|
121
|
+
},
|
122
|
+
"opentelemetry.proto.resource.v1.Resource": {
|
123
|
+
"properties": {
|
124
|
+
"attributes": {
|
125
|
+
"items": {
|
126
|
+
"$ref": "#/definitions/opentelemetry.proto.common.v1.KeyValue"
|
127
|
+
},
|
128
|
+
"type": "array",
|
129
|
+
"description": "Set of attributes that describe the resource. Attribute keys MUST be unique (it is not allowed to have more than one attribute with the same key)."
|
130
|
+
},
|
131
|
+
"droppedAttributesCount": {
|
132
|
+
"type": "integer",
|
133
|
+
"description": "dropped_attributes_count is the number of dropped attributes. If the value is 0, then no attributes were dropped."
|
134
|
+
}
|
135
|
+
},
|
136
|
+
"additionalProperties": false,
|
137
|
+
"type": "object",
|
138
|
+
"title": "Resource",
|
139
|
+
"description": "Resource information."
|
140
|
+
},
|
141
|
+
"opentelemetry.proto.trace.v1.ResourceSpans": {
|
142
|
+
"properties": {
|
143
|
+
"resource": {
|
144
|
+
"$ref": "#/definitions/opentelemetry.proto.resource.v1.Resource",
|
145
|
+
"additionalProperties": false,
|
146
|
+
"description": "The resource for the spans in this message. If this field is not set then no resource info is known."
|
147
|
+
},
|
148
|
+
"scopeSpans": {
|
149
|
+
"items": {
|
150
|
+
"$ref": "#/definitions/opentelemetry.proto.trace.v1.ScopeSpans"
|
151
|
+
},
|
152
|
+
"type": "array",
|
153
|
+
"description": "A list of ScopeSpans that originate from a resource."
|
154
|
+
},
|
155
|
+
"schemaUrl": {
|
156
|
+
"type": "string",
|
157
|
+
"description": "This schema_url applies to the data in the \"resource\" field. It does not apply to the data in the \"scope_spans\" field which have their own schema_url field."
|
158
|
+
}
|
159
|
+
},
|
160
|
+
"additionalProperties": false,
|
161
|
+
"type": "object",
|
162
|
+
"title": "Resource Spans",
|
163
|
+
"description": "A collection of ScopeSpans from a Resource."
|
164
|
+
},
|
165
|
+
"opentelemetry.proto.trace.v1.ScopeSpans": {
|
166
|
+
"properties": {
|
167
|
+
"scope": {
|
168
|
+
"$ref": "#/definitions/opentelemetry.proto.common.v1.InstrumentationScope",
|
169
|
+
"additionalProperties": false,
|
170
|
+
"description": "The instrumentation scope information for the spans in this message. Semantically when InstrumentationScope isn't set, it is equivalent with an empty instrumentation scope name (unknown)."
|
171
|
+
},
|
172
|
+
"spans": {
|
173
|
+
"items": {
|
174
|
+
"$ref": "#/definitions/opentelemetry.proto.trace.v1.Span"
|
175
|
+
},
|
176
|
+
"type": "array",
|
177
|
+
"description": "A list of Spans that originate from an instrumentation scope."
|
178
|
+
},
|
179
|
+
"schemaUrl": {
|
180
|
+
"type": "string",
|
181
|
+
"description": "This schema_url applies to all spans and span events in the \"spans\" field."
|
182
|
+
}
|
183
|
+
},
|
184
|
+
"additionalProperties": false,
|
185
|
+
"type": "object",
|
186
|
+
"title": "Scope Spans",
|
187
|
+
"description": "A collection of Spans produced by an InstrumentationScope."
|
188
|
+
},
|
189
|
+
"opentelemetry.proto.trace.v1.Span": {
|
190
|
+
"properties": {
|
191
|
+
"traceId": {
|
192
|
+
"type": "string",
|
193
|
+
"description": "A unique identifier for a trace. All spans from the same trace share the same `trace_id`. The ID is a 16-byte array. An ID with all zeroes is considered invalid. This field is semantically required. Receiver should generate new random trace_id if empty or invalid trace_id was received. This field is required.",
|
194
|
+
"format": "hex",
|
195
|
+
"pattern": "^[0-9a-fA-F]{32}$"
|
196
|
+
},
|
197
|
+
"spanId": {
|
198
|
+
"type": "string",
|
199
|
+
"description": "A unique identifier for a span within a trace, assigned when the span is created. The ID is an 8-byte array. An ID with all zeroes is considered invalid. This field is semantically required. Receiver should generate new random span_id if empty or invalid span_id was received. This field is required.",
|
200
|
+
"format": "hex",
|
201
|
+
"pattern": "^[0-9a-fA-F]{16}$"
|
202
|
+
},
|
203
|
+
"traceState": {
|
204
|
+
"type": "string",
|
205
|
+
"description": "trace_state conveys information about request position in multiple distributed tracing graphs. It is a trace_state in w3c-trace-context format: https://www.w3.org/TR/trace-context/#tracestate-header See also https://github.com/w3c/distributed-tracing for more details about this field."
|
206
|
+
},
|
207
|
+
"parentSpanId": {
|
208
|
+
"type": "string",
|
209
|
+
"description": "The `span_id` of this span's parent span. If this is a root span, then this field must be empty. The ID is an 8-byte array.",
|
210
|
+
"format": "hex",
|
211
|
+
"pattern": "^[0-9a-fA-F]{16}$"
|
212
|
+
},
|
213
|
+
"name": {
|
214
|
+
"type": "string",
|
215
|
+
"description": "A description of the span's operation. For example, the name can be a qualified method name or a file name and a line number where the operation is called. A best practice is to use the same display name at the same call point in an application. This makes it easier to correlate spans in different traces. This field is semantically required to be set to non-empty string. Empty value is equivalent to an unknown span name. This field is required."
|
216
|
+
},
|
217
|
+
"kind": {
|
218
|
+
"enum": [
|
219
|
+
"SPAN_KIND_UNSPECIFIED",
|
220
|
+
0,
|
221
|
+
"SPAN_KIND_INTERNAL",
|
222
|
+
1,
|
223
|
+
"SPAN_KIND_SERVER",
|
224
|
+
2,
|
225
|
+
"SPAN_KIND_CLIENT",
|
226
|
+
3,
|
227
|
+
"SPAN_KIND_PRODUCER",
|
228
|
+
4,
|
229
|
+
"SPAN_KIND_CONSUMER",
|
230
|
+
5
|
231
|
+
],
|
232
|
+
"oneOf": [
|
233
|
+
{
|
234
|
+
"type": "string"
|
235
|
+
},
|
236
|
+
{
|
237
|
+
"type": "integer"
|
238
|
+
}
|
239
|
+
],
|
240
|
+
"title": "Span Kind",
|
241
|
+
"description": "SpanKind is the type of span. Can be used to specify additional relationships between spans in addition to a parent/child relationship."
|
242
|
+
},
|
243
|
+
"startTimeUnixNano": {
|
244
|
+
"type": "string",
|
245
|
+
"description": "start_time_unix_nano is the start time of the span. On the client side, this is the time kept by the local machine where the span execution starts. On the server side, this is the time when the server's application handler starts running. Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. This field is semantically required and it is expected that end_time \u003e= start_time."
|
246
|
+
},
|
247
|
+
"endTimeUnixNano": {
|
248
|
+
"type": "string",
|
249
|
+
"description": "end_time_unix_nano is the end time of the span. On the client side, this is the time kept by the local machine where the span execution ends. On the server side, this is the time when the server application handler stops running. Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. This field is semantically required and it is expected that end_time \u003e= start_time."
|
250
|
+
},
|
251
|
+
"attributes": {
|
252
|
+
"items": {
|
253
|
+
"$ref": "#/definitions/opentelemetry.proto.common.v1.KeyValue"
|
254
|
+
},
|
255
|
+
"type": "array",
|
256
|
+
"description": "attributes is a collection of key/value pairs. Note, global attributes like server name can be set using the resource API. Examples of attributes: \"/http/user_agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36\" \"/http/server_latency\": 300 \"abc.com/myattribute\": true \"abc.com/score\": 10.239 The OpenTelemetry API specification further restricts the allowed value types: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/README.md#attribute Attribute keys MUST be unique (it is not allowed to have more than one attribute with the same key)."
|
257
|
+
},
|
258
|
+
"droppedAttributesCount": {
|
259
|
+
"type": "integer",
|
260
|
+
"description": "dropped_attributes_count is the number of attributes that were discarded. Attributes can be discarded because their keys are too long or because there are too many attributes. If this value is 0, then no attributes were dropped."
|
261
|
+
},
|
262
|
+
"events": {
|
263
|
+
"items": {
|
264
|
+
"$ref": "#/definitions/opentelemetry.proto.trace.v1.Span.Event"
|
265
|
+
},
|
266
|
+
"type": "array",
|
267
|
+
"description": "events is a collection of Event items."
|
268
|
+
},
|
269
|
+
"droppedEventsCount": {
|
270
|
+
"type": "integer",
|
271
|
+
"description": "dropped_events_count is the number of dropped events. If the value is 0, then no events were dropped."
|
272
|
+
},
|
273
|
+
"links": {
|
274
|
+
"items": {
|
275
|
+
"$ref": "#/definitions/opentelemetry.proto.trace.v1.Span.Link"
|
276
|
+
},
|
277
|
+
"type": "array",
|
278
|
+
"description": "links is a collection of Links, which are references from this span to a span in the same or different trace."
|
279
|
+
},
|
280
|
+
"droppedLinksCount": {
|
281
|
+
"type": "integer",
|
282
|
+
"description": "dropped_links_count is the number of dropped links after the maximum size was enforced. If this value is 0, then no links were dropped."
|
283
|
+
},
|
284
|
+
"status": {
|
285
|
+
"$ref": "#/definitions/opentelemetry.proto.trace.v1.Status",
|
286
|
+
"additionalProperties": false,
|
287
|
+
"description": "An optional final status for this span. Semantically when Status isn't set, it means span's status code is unset, i.e. assume STATUS_CODE_UNSET (code = 0)."
|
288
|
+
}
|
289
|
+
},
|
290
|
+
"additionalProperties": false,
|
291
|
+
"type": "object",
|
292
|
+
"title": "Span",
|
293
|
+
"description": "A Span represents a single operation performed by a single component of the system. The next available field id is 17."
|
294
|
+
},
|
295
|
+
"opentelemetry.proto.trace.v1.Span.Event": {
|
296
|
+
"properties": {
|
297
|
+
"timeUnixNano": {
|
298
|
+
"type": "string",
|
299
|
+
"description": "time_unix_nano is the time the event occurred."
|
300
|
+
},
|
301
|
+
"name": {
|
302
|
+
"type": "string",
|
303
|
+
"description": "name of the event. This field is semantically required to be set to non-empty string."
|
304
|
+
},
|
305
|
+
"attributes": {
|
306
|
+
"items": {
|
307
|
+
"$ref": "#/definitions/opentelemetry.proto.common.v1.KeyValue"
|
308
|
+
},
|
309
|
+
"type": "array",
|
310
|
+
"description": "attributes is a collection of attribute key/value pairs on the event. Attribute keys MUST be unique (it is not allowed to have more than one attribute with the same key)."
|
311
|
+
},
|
312
|
+
"droppedAttributesCount": {
|
313
|
+
"type": "integer",
|
314
|
+
"description": "dropped_attributes_count is the number of dropped attributes. If the value is 0, then no attributes were dropped."
|
315
|
+
}
|
316
|
+
},
|
317
|
+
"additionalProperties": false,
|
318
|
+
"type": "object",
|
319
|
+
"title": "Event",
|
320
|
+
"description": "Event is a time-stamped annotation of the span, consisting of user-supplied text description and key-value pairs."
|
321
|
+
},
|
322
|
+
"opentelemetry.proto.trace.v1.Span.Link": {
|
323
|
+
"properties": {
|
324
|
+
"traceId": {
|
325
|
+
"type": "string",
|
326
|
+
"description": "A unique identifier of a trace that this linked span is part of. The ID is a 16-byte array.",
|
327
|
+
"format": "hex",
|
328
|
+
"pattern": "^[0-9a-fA-F]{32}$"
|
329
|
+
},
|
330
|
+
"spanId": {
|
331
|
+
"type": "string",
|
332
|
+
"description": "A unique identifier for the linked span. The ID is an 8-byte array.",
|
333
|
+
"format": "hex",
|
334
|
+
"pattern": "^[0-9a-fA-F]{16}$"
|
335
|
+
},
|
336
|
+
"traceState": {
|
337
|
+
"type": "string",
|
338
|
+
"description": "The trace_state associated with the link."
|
339
|
+
},
|
340
|
+
"attributes": {
|
341
|
+
"items": {
|
342
|
+
"$ref": "#/definitions/opentelemetry.proto.common.v1.KeyValue"
|
343
|
+
},
|
344
|
+
"type": "array",
|
345
|
+
"description": "attributes is a collection of attribute key/value pairs on the link. Attribute keys MUST be unique (it is not allowed to have more than one attribute with the same key)."
|
346
|
+
},
|
347
|
+
"droppedAttributesCount": {
|
348
|
+
"type": "integer",
|
349
|
+
"description": "dropped_attributes_count is the number of dropped attributes. If the value is 0, then no attributes were dropped."
|
350
|
+
}
|
351
|
+
},
|
352
|
+
"additionalProperties": false,
|
353
|
+
"type": "object",
|
354
|
+
"title": "Link",
|
355
|
+
"description": "A pointer from the current span to another span in the same trace or in a different trace. For example, this can be used in batching operations, where a single batch handler processes multiple requests from different traces or when the handler receives a request from a different project."
|
356
|
+
},
|
357
|
+
"opentelemetry.proto.trace.v1.Status": {
|
358
|
+
"properties": {
|
359
|
+
"message": {
|
360
|
+
"type": "string",
|
361
|
+
"description": "A developer-facing human readable error message."
|
362
|
+
},
|
363
|
+
"code": {
|
364
|
+
"enum": [
|
365
|
+
"STATUS_CODE_UNSET",
|
366
|
+
0,
|
367
|
+
"STATUS_CODE_OK",
|
368
|
+
1,
|
369
|
+
"STATUS_CODE_ERROR",
|
370
|
+
2
|
371
|
+
],
|
372
|
+
"oneOf": [
|
373
|
+
{
|
374
|
+
"type": "string"
|
375
|
+
},
|
376
|
+
{
|
377
|
+
"type": "integer"
|
378
|
+
}
|
379
|
+
],
|
380
|
+
"title": "Status Code",
|
381
|
+
"description": "For the semantics of status codes see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#set-status"
|
382
|
+
}
|
383
|
+
},
|
384
|
+
"additionalProperties": false,
|
385
|
+
"type": "object",
|
386
|
+
"title": "Status",
|
387
|
+
"description": "The Status type defines a logical error model that is suitable for different programming environments, including REST APIs and RPC APIs."
|
388
|
+
}
|
389
|
+
}
|
390
|
+
}
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../helper'
|
4
|
+
|
5
|
+
module Maze
|
6
|
+
module Schemas
|
7
|
+
|
8
|
+
# Contains a set of pre-defined validations for ensuring traces are correct
|
9
|
+
class TraceValidator
|
10
|
+
|
11
|
+
# Whether the trace passed the validation, one of true, false, or nil (not run)
|
12
|
+
# @returns [Boolean|nil] Whether the validation was successful
|
13
|
+
attr_reader :success
|
14
|
+
attr_reader :errors
|
15
|
+
|
16
|
+
# Creates the validator
|
17
|
+
#
|
18
|
+
# @param body [Hash] The body of the trace to validate
|
19
|
+
def initialize(body)
|
20
|
+
@body = body
|
21
|
+
@success = nil
|
22
|
+
@errors = []
|
23
|
+
end
|
24
|
+
|
25
|
+
# Runs the validation against the trace given
|
26
|
+
def validate
|
27
|
+
@success = true
|
28
|
+
# Shortcut the validation if the body is empty for initial P gathering reasons
|
29
|
+
return if @body.keys.eql?(['resourceSpans']) && @body['resourceSpans'].empty?
|
30
|
+
|
31
|
+
regex_comparison('resourceSpans.0.scopeSpans.0.spans.0.spanId', '^[A-Fa-f0-9]{16}$')
|
32
|
+
regex_comparison('resourceSpans.0.scopeSpans.0.spans.0.traceId', '^[A-Fa-f0-9]{32}$')
|
33
|
+
element_int_in_range('resourceSpans.0.scopeSpans.0.spans.0.kind', 0..5)
|
34
|
+
regex_comparison('resourceSpans.0.scopeSpans.0.spans.0.startTimeUnixNano', '^[0-9]+$')
|
35
|
+
regex_comparison('resourceSpans.0.scopeSpans.0.spans.0.endTimeUnixNano', '^[0-9]+$')
|
36
|
+
element_contains('resourceSpans.0.resource.attributes', 'deployment.environment')
|
37
|
+
element_contains('resourceSpans.0.resource.attributes', 'telemetry.sdk.name')
|
38
|
+
element_contains('resourceSpans.0.resource.attributes', 'telemetry.sdk.version')
|
39
|
+
element_a_greater_or_equal_element_b(
|
40
|
+
'resourceSpans.0.scopeSpans.0.spans.0.endTimeUnixNano',
|
41
|
+
'resourceSpans.0.scopeSpans.0.spans.0.startTimeUnixNano'
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def regex_comparison(path, regex)
|
46
|
+
element_value = Maze::Helper.read_key_path(@body, path)
|
47
|
+
expected = Regexp.new(regex)
|
48
|
+
unless expected.match(element_value)
|
49
|
+
@success = false
|
50
|
+
@errors << "Element '#{path}' was expected to match the regex '#{regex}', but was '#{element_value}'"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def element_int_in_range(path, range)
|
55
|
+
element_value = Maze::Helper.read_key_path(@body, path)
|
56
|
+
if element_value.nil? || !element_value.kind_of?(Integer)
|
57
|
+
@success = false
|
58
|
+
@errors << "Element '#{path}' was expected to be an integer, was '#{element_value}'"
|
59
|
+
return
|
60
|
+
end
|
61
|
+
unless range.include?(element_value)
|
62
|
+
@success = false
|
63
|
+
@errors << "Element '#{path}':'#{element_value}' was expected to be in the range '#{range}'"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def element_contains(path, key_value, value_type=nil, possible_values=nil)
|
68
|
+
container = Maze::Helper.read_key_path(@body, path)
|
69
|
+
if container.nil? || !container.kind_of?(Array)
|
70
|
+
@success = false
|
71
|
+
@errors << "Element '#{path}' was expected to be an array, was '#{container}'"
|
72
|
+
return
|
73
|
+
end
|
74
|
+
element = container.find { |value| value['key'].eql?(key_value) }
|
75
|
+
unless element
|
76
|
+
@success = false
|
77
|
+
@errors << "Element '#{path}' did not contain a value with the key '#{key_value}'"
|
78
|
+
return
|
79
|
+
end
|
80
|
+
if value_type && possible_values
|
81
|
+
unless element['value'] && element['value'][value_type] && possible_values.include?(element['value'][value_type])
|
82
|
+
@success = false
|
83
|
+
@errors << "Element '#{path}':'#{element}' did not contain a value of '#{value_type}' from '#{possible_values}'"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def element_a_greater_or_equal_element_b(path_a, path_b)
|
89
|
+
element_a = Maze::Helper.read_key_path(@body, path_a)
|
90
|
+
element_b = Maze::Helper.read_key_path(@body, path_b)
|
91
|
+
unless element_a && element_b && element_a >= element_b
|
92
|
+
@success = false
|
93
|
+
@errors << "Element '#{path_a}':'#{element_a}' was expected to be greater than or equal to '#{path_b}':'#{element_b}'"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|