|
42 | 42 |
|
43 | 43 | event_samples = "tests/event_samples/" |
44 | 44 |
|
| 45 | +span_to_finish = None |
| 46 | + |
| 47 | + |
| 48 | +def _clean_up_span(): |
| 49 | + global span_to_finish |
| 50 | + if span_to_finish is not None: |
| 51 | + span_to_finish.finish() |
| 52 | + span_to_finish = None |
| 53 | + |
| 54 | + |
| 55 | +def register_span(span): |
| 56 | + global span_to_finish |
| 57 | + _clean_up_span() |
| 58 | + span_to_finish = span |
| 59 | + return span |
| 60 | + |
| 61 | + |
| 62 | +def wrapped_span_creator(span_creator_func): |
| 63 | + def result_func(*args, **kwargs): |
| 64 | + return register_span(span_creator_func(*args, **kwargs)) |
| 65 | + |
| 66 | + return result_func |
| 67 | + |
| 68 | + |
| 69 | +create_inferred_span = wrapped_span_creator(create_inferred_span) |
| 70 | + |
45 | 71 |
|
46 | 72 | class ClientContext(object): |
47 | 73 | def __init__(self, custom=None): |
@@ -482,6 +508,7 @@ def test_set_correlation_ids(self): |
482 | 508 | span = tracer.current_span() |
483 | 509 | self.assertEqual(span.trace_id, 123) |
484 | 510 | self.assertEqual(span.span_id, 456) |
| 511 | + span.finish() |
485 | 512 |
|
486 | 513 | def test_set_correlation_ids_handle_empty_trace_context(self): |
487 | 514 | # neither x-ray or ddtrace is use. no tracing at all. |
@@ -595,6 +622,9 @@ def setUp(self): |
595 | 622 | self.mock_span_stop = patcher.start() |
596 | 623 | self.addCleanup(patcher.stop) |
597 | 624 |
|
| 625 | + def tearDown(self): |
| 626 | + _clean_up_span() |
| 627 | + |
598 | 628 | def test_create_inferred_span_from_authorizer_request_api_gateway_v1_event(self): |
599 | 629 | event_sample_source = "authorizer-request-api-gateway-v1" |
600 | 630 | finish_time = ( |
@@ -741,6 +771,9 @@ def _basic_common_checks( |
741 | 771 |
|
742 | 772 |
|
743 | 773 | class TestInferredSpans(unittest.TestCase): |
| 774 | + def tearDown(self): |
| 775 | + _clean_up_span() |
| 776 | + |
744 | 777 | def test_create_inferred_span_from_api_gateway_event(self): |
745 | 778 | event_sample_source = "api-gateway" |
746 | 779 | test_file = event_samples + event_sample_source + ".json" |
|
0 commit comments