|
67 | 67 | ERRORS_SCHEMA = os.path.join(cur_dir, "upstream", "json-specs", "error.json") |
68 | 68 | TRANSACTIONS_SCHEMA = os.path.join(cur_dir, "upstream", "json-specs", "transaction.json") |
69 | 69 | SPAN_SCHEMA = os.path.join(cur_dir, "upstream", "json-specs", "span.json") |
| 70 | +METRICSET_SCHEMA = os.path.join(cur_dir, "upstream", "json-specs", "metricset.json") |
70 | 71 | METADATA_SCHEMA = os.path.join(cur_dir, "upstream", "json-specs", "metadata.json") |
71 | 72 |
|
72 | 73 |
|
73 | 74 | with codecs.open(ERRORS_SCHEMA, encoding="utf8") as errors_json, codecs.open( |
74 | 75 | TRANSACTIONS_SCHEMA, encoding="utf8" |
75 | 76 | ) as transactions_json, codecs.open(SPAN_SCHEMA, encoding="utf8") as span_json, codecs.open( |
| 77 | + METRICSET_SCHEMA, encoding="utf8" |
| 78 | +) as metricset_json, codecs.open( |
76 | 79 | METADATA_SCHEMA, encoding="utf8" |
77 | 80 | ) as metadata_json: |
78 | 81 | VALIDATORS = { |
|
95 | 98 | base_uri="file:" + pathname2url(SPAN_SCHEMA), referrer="file:" + pathname2url(SPAN_SCHEMA) |
96 | 99 | ), |
97 | 100 | ), |
| 101 | + "metricset": jsonschema.Draft4Validator( |
| 102 | + json.load(metricset_json), |
| 103 | + resolver=jsonschema.RefResolver( |
| 104 | + base_uri="file:" + pathname2url(METRICSET_SCHEMA), referrer="file:" + pathname2url(METRICSET_SCHEMA) |
| 105 | + ), |
| 106 | + ), |
98 | 107 | "metadata": jsonschema.Draft4Validator( |
99 | 108 | json.load(metadata_json), |
100 | 109 | resolver=jsonschema.RefResolver( |
@@ -187,6 +196,7 @@ def elasticapm_client(request): |
187 | 196 | sys.excepthook = original_exceptionhook |
188 | 197 | execution_context.set_transaction(None) |
189 | 198 | execution_context.set_span(None) |
| 199 | + assert not client._transport.validation_errors |
190 | 200 |
|
191 | 201 |
|
192 | 202 | @pytest.fixture() |
@@ -295,12 +305,19 @@ class DummyTransport(HTTPTransportBase): |
295 | 305 | def __init__(self, url, *args, **kwargs): |
296 | 306 | super(DummyTransport, self).__init__(url, *args, **kwargs) |
297 | 307 | self.events = defaultdict(list) |
| 308 | + self.validation_errors = defaultdict(list) |
298 | 309 |
|
299 | 310 | def queue(self, event_type, data, flush=False): |
300 | 311 | self._flushed.clear() |
301 | 312 | data = self._process_event(event_type, data) |
302 | 313 | self.events[event_type].append(data) |
303 | 314 | self._flushed.set() |
| 315 | + if data is not None: |
| 316 | + validator = VALIDATORS[event_type] |
| 317 | + try: |
| 318 | + validator.validate(data) |
| 319 | + except jsonschema.ValidationError as e: |
| 320 | + self.validation_errors[event_type].append(e.message) |
304 | 321 |
|
305 | 322 | def start_thread(self, pid=None): |
306 | 323 | # don't call the parent method, but the one from ThreadManager |
|
0 commit comments