bugsnag-maze-runner 7.22.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +7 -0
  2. data/bin/bugsnag-print-load-paths +6 -0
  3. data/bin/download-logs +74 -0
  4. data/bin/maze-runner +174 -0
  5. data/bin/upload-app +56 -0
  6. data/lib/features/scripts/await-android-emulator.sh +11 -0
  7. data/lib/features/scripts/clear-android-app-data.sh +8 -0
  8. data/lib/features/scripts/force-stop-android-app.sh +8 -0
  9. data/lib/features/scripts/install-android-app.sh +15 -0
  10. data/lib/features/scripts/launch-android-app.sh +38 -0
  11. data/lib/features/scripts/launch-android-emulator.sh +15 -0
  12. data/lib/features/steps/android_steps.rb +51 -0
  13. data/lib/features/steps/app_automator_steps.rb +228 -0
  14. data/lib/features/steps/aws_sam_steps.rb +212 -0
  15. data/lib/features/steps/breadcrumb_steps.rb +80 -0
  16. data/lib/features/steps/browser_steps.rb +93 -0
  17. data/lib/features/steps/build_api_steps.rb +25 -0
  18. data/lib/features/steps/document_server_steps.rb +7 -0
  19. data/lib/features/steps/error_reporting_steps.rb +358 -0
  20. data/lib/features/steps/feature_flag_steps.rb +190 -0
  21. data/lib/features/steps/header_steps.rb +72 -0
  22. data/lib/features/steps/log_steps.rb +29 -0
  23. data/lib/features/steps/multipart_request_steps.rb +142 -0
  24. data/lib/features/steps/network_steps.rb +135 -0
  25. data/lib/features/steps/payload_steps.rb +257 -0
  26. data/lib/features/steps/proxy_steps.rb +34 -0
  27. data/lib/features/steps/query_parameter_steps.rb +31 -0
  28. data/lib/features/steps/request_assertion_steps.rb +186 -0
  29. data/lib/features/steps/runner_steps.rb +428 -0
  30. data/lib/features/steps/session_tracking_steps.rb +116 -0
  31. data/lib/features/steps/trace_steps.rb +206 -0
  32. data/lib/features/steps/value_steps.rb +119 -0
  33. data/lib/features/support/env.rb +7 -0
  34. data/lib/features/support/internal_hooks.rb +207 -0
  35. data/lib/maze/api/appium/file_manager.rb +29 -0
  36. data/lib/maze/appium_server.rb +112 -0
  37. data/lib/maze/assertions/request_set_assertions.rb +97 -0
  38. data/lib/maze/aws/sam.rb +112 -0
  39. data/lib/maze/aws_public_ip.rb +53 -0
  40. data/lib/maze/bugsnag_config.rb +42 -0
  41. data/lib/maze/checks/assert_check.rb +69 -0
  42. data/lib/maze/checks/noop_check.rb +34 -0
  43. data/lib/maze/client/appium/base_client.rb +131 -0
  44. data/lib/maze/client/appium/bb_client.rb +102 -0
  45. data/lib/maze/client/appium/bb_devices.rb +127 -0
  46. data/lib/maze/client/appium/bs_client.rb +91 -0
  47. data/lib/maze/client/appium/bs_devices.rb +141 -0
  48. data/lib/maze/client/appium/bs_legacy_client.rb +31 -0
  49. data/lib/maze/client/appium/local_client.rb +67 -0
  50. data/lib/maze/client/appium.rb +23 -0
  51. data/lib/maze/client/bb_api_client.rb +102 -0
  52. data/lib/maze/client/bb_client_utils.rb +181 -0
  53. data/lib/maze/client/bs_client_utils.rb +168 -0
  54. data/lib/maze/client/selenium/base_client.rb +15 -0
  55. data/lib/maze/client/selenium/bb_browsers.yml +188 -0
  56. data/lib/maze/client/selenium/bb_client.rb +38 -0
  57. data/lib/maze/client/selenium/bs_browsers.yml +257 -0
  58. data/lib/maze/client/selenium/bs_client.rb +89 -0
  59. data/lib/maze/client/selenium/local_client.rb +16 -0
  60. data/lib/maze/client/selenium.rb +16 -0
  61. data/lib/maze/compare.rb +161 -0
  62. data/lib/maze/configuration.rb +182 -0
  63. data/lib/maze/docker.rb +147 -0
  64. data/lib/maze/document_server.rb +46 -0
  65. data/lib/maze/driver/appium.rb +198 -0
  66. data/lib/maze/driver/browser.rb +124 -0
  67. data/lib/maze/errors.rb +52 -0
  68. data/lib/maze/generator.rb +55 -0
  69. data/lib/maze/helper.rb +122 -0
  70. data/lib/maze/hooks/appium_hooks.rb +55 -0
  71. data/lib/maze/hooks/browser_hooks.rb +15 -0
  72. data/lib/maze/hooks/command_hooks.rb +9 -0
  73. data/lib/maze/hooks/error_code_hook.rb +49 -0
  74. data/lib/maze/hooks/hooks.rb +61 -0
  75. data/lib/maze/http_request.rb +21 -0
  76. data/lib/maze/interactive_cli.rb +173 -0
  77. data/lib/maze/logger.rb +86 -0
  78. data/lib/maze/macos_utils.rb +14 -0
  79. data/lib/maze/maze_output.rb +88 -0
  80. data/lib/maze/network.rb +49 -0
  81. data/lib/maze/option/parser.rb +240 -0
  82. data/lib/maze/option/processor.rb +130 -0
  83. data/lib/maze/option/validator.rb +155 -0
  84. data/lib/maze/option.rb +62 -0
  85. data/lib/maze/plugins/bugsnag_reporting_plugin.rb +49 -0
  86. data/lib/maze/plugins/cucumber_report_plugin.rb +101 -0
  87. data/lib/maze/plugins/error_code_plugin.rb +21 -0
  88. data/lib/maze/plugins/global_retry_plugin.rb +38 -0
  89. data/lib/maze/proxy.rb +114 -0
  90. data/lib/maze/request_list.rb +87 -0
  91. data/lib/maze/request_repeater.rb +49 -0
  92. data/lib/maze/retry_handler.rb +67 -0
  93. data/lib/maze/runner.rb +149 -0
  94. data/lib/maze/schemas/OtelTraceSchema.json +390 -0
  95. data/lib/maze/schemas/trace_schema.rb +7 -0
  96. data/lib/maze/schemas/trace_validator.rb +98 -0
  97. data/lib/maze/server.rb +251 -0
  98. data/lib/maze/servlets/base_servlet.rb +27 -0
  99. data/lib/maze/servlets/command_servlet.rb +47 -0
  100. data/lib/maze/servlets/log_servlet.rb +64 -0
  101. data/lib/maze/servlets/reflective_servlet.rb +70 -0
  102. data/lib/maze/servlets/servlet.rb +199 -0
  103. data/lib/maze/servlets/temp.rb +0 -0
  104. data/lib/maze/servlets/trace_servlet.rb +13 -0
  105. data/lib/maze/store.rb +15 -0
  106. data/lib/maze/terminating_server.rb +129 -0
  107. data/lib/maze/timers.rb +51 -0
  108. data/lib/maze/wait.rb +35 -0
  109. data/lib/maze.rb +27 -0
  110. data/lib/utils/deep_merge.rb +17 -0
  111. data/lib/utils/selenium_money_patch.rb +17 -0
  112. metadata +451 -0
@@ -0,0 +1,149 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
4
+ require_relative './interactive_cli'
5
+
6
+ module Maze
7
+ # Runs scripts and commands, applying relevant environment variables as necessary
8
+ class Runner
9
+ # Determines the default path to the `scripts` directory. Can be overwritten in the env.rb file.
10
+ SCRIPT_PATH ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'features', 'scripts')) unless defined? SCRIPT_PATH
11
+
12
+ class << self
13
+ # Runs a command, applying previously set environment variables.
14
+ # The output from the command is always printed in debug mode -
15
+ # just so the caller can verify something about the output.
16
+ #
17
+ # @param cmd [String] The command to run
18
+ # @param blocking [Boolean] Optional. Whether to wait for a return code before proceeding
19
+ # @param success_codes [Array] Optional. An array of integer codes which indicate the run was successful
20
+ #
21
+ # @return [Array, Thread] If blocking, the output and exit_status are returned
22
+ def run_command(cmd, blocking: true, success_codes: [0])
23
+ executor = lambda do
24
+ $logger.debug "Executing: #{cmd}"
25
+
26
+ Open3.popen2e(environment, cmd) do |_stdin, stdout_and_stderr, wait_thr|
27
+ # Add the pid to the list of pids to kill at the end
28
+ pids << wait_thr.pid unless blocking
29
+
30
+ output = []
31
+ stdout_and_stderr.each do |line|
32
+ output << line
33
+ $logger.debug line.chomp
34
+ end
35
+
36
+ exit_status = wait_thr.value.to_i
37
+ $logger.debug "Exit status: #{exit_status}"
38
+
39
+ # if the command fails we log the output at warn level too
40
+ if !success_codes.nil? && !success_codes.include?(exit_status) && $logger.level != Logger::DEBUG
41
+ output.each { |line| $logger.warn(cmd) { line.chomp } }
42
+ end
43
+
44
+ return [output, exit_status]
45
+ end
46
+ end
47
+
48
+ if blocking
49
+ executor.call
50
+ else
51
+ Thread.new(&executor)
52
+ end
53
+ end
54
+
55
+ # Runs a script in the script directory indicated by the SCRIPT_PATH environment variable.
56
+ #
57
+ # @param script_name [String] The name of the script to run
58
+ # @param blocking [Boolean] Optional. Whether to wait for a return code before proceeding
59
+ # @param success_codes [Array] Optional. An array of integer codes which indicate the run was successful
60
+ # @param command [String] Optional. Command to run the script with, e.g. 'ruby'.
61
+ #
62
+ # @return [Array] If blocking, the output and exit_status are returned
63
+ def run_script(script_name, blocking: false, success_codes: [0], command: nil)
64
+ script_path = File.join(SCRIPT_PATH, script_name)
65
+ script_path = File.join(Dir.pwd, script_name) unless File.exist? script_path
66
+ if command
67
+ script_path = "#{command} #{script_path}"
68
+ elsif Gem.win_platform?
69
+ # Windows does not support the shebang that we use in the scripts so it
70
+ # needs to know how to execute the script. Passing `cmd /c` tells windows
71
+ # to use its known file associations to execute this path. If Ruby is
72
+ # installed on Windows then it will know that `rb` files should be executed
73
+ # using Ruby etc.
74
+ script_path = "cmd /c #{script_path}"
75
+ end
76
+ run_command(script_path, blocking: blocking, success_codes: success_codes)
77
+ end
78
+
79
+ # Creates a new interactive session. Can only be called if no session already
80
+ # exists. Check with {interactive_session?} if necessary.
81
+ #
82
+ # @return [InteractiveCLI] The interactiveCLI instance
83
+ def start_interactive_session(*args)
84
+ raise 'An interactive session is already running!' if interactive_session?
85
+
86
+ wait = Maze::Wait.new(interval: 0.3, timeout: 3)
87
+
88
+ interactive_session = InteractiveCLI.new(*args)
89
+
90
+ success = wait.until { interactive_session.running? }
91
+ raise 'Shell session did not start in time!' unless success
92
+
93
+ @interactive_session = interactive_session
94
+ end
95
+
96
+ def interactive_session?
97
+ !@interactive_session.nil?
98
+ end
99
+
100
+ def interactive_session
101
+ raise 'No interactive session is running!' unless interactive_session?
102
+
103
+ @interactive_session
104
+ end
105
+
106
+ # Stops the interactive session, allowing a new one to be started
107
+ #
108
+ # @return [Boolean] True if the interactive session exited successfully
109
+ def stop_interactive_session
110
+ raise 'No interactive session is running!' unless interactive_session?
111
+
112
+ success = @interactive_session.stop
113
+
114
+ # Make sure the process is killed if it did not stop
115
+ pids << @interactive_session.pid if @interactive_session.running?
116
+
117
+ @interactive_session = nil
118
+
119
+ success
120
+ end
121
+
122
+ # Stops all script processes previously started by this class.
123
+ def kill_running_scripts
124
+ stop_interactive_session if interactive_session?
125
+
126
+ pids.each do |p|
127
+ Process.kill('KILL', p)
128
+ rescue Errno::ESRCH
129
+ # ignored
130
+ end
131
+ pids.clear
132
+ end
133
+
134
+ # Allows access to a hash of environment variables applied to command and script runs.
135
+ #
136
+ # @return [Hash] The hash of currently set environment variables and their values
137
+ def environment
138
+ @environment ||= {}
139
+ end
140
+
141
+ # Allows access to the process ids created by the runner.
142
+ #
143
+ # @return [Array] pids created by the runner
144
+ def pids
145
+ @pids ||= []
146
+ end
147
+ end
148
+ end
149
+ end
@@ -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,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Maze
4
+ module Schemas
5
+ TRACE_SCHEMA = JSON.parse(File.read(File.expand_path("OtelTraceSchema.json", File.dirname(__FILE__))))
6
+ end
7
+ end
@@ -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