|
15 | 15 | from unittest.mock import patch
|
16 | 16 |
|
17 | 17 | import pytest
|
18 |
| -from opentelemetry.sdk.metrics._internal.point import HistogramDataPoint, NumberDataPoint |
19 | 18 | from opentelemetry.test.test_base import TestBase
|
20 | 19 | from opentelemetry.trace import get_tracer
|
21 | 20 |
|
@@ -54,28 +53,39 @@ def tearDown(self):
|
54 | 53 | AsyncioInstrumentor().uninstrument()
|
55 | 54 |
|
56 | 55 | @pytest.mark.asyncio
|
57 |
| - async def test_asyncio_loop_ensure_future(self): |
| 56 | + def test_asyncio_loop_ensure_future(self): |
58 | 57 | """
|
59 | 58 | async_func is not traced because it is not set in the environment variable
|
60 | 59 | """
|
61 |
| - task = asyncio.ensure_future(async_func()) |
62 |
| - await task |
| 60 | + |
| 61 | + async def test(): |
| 62 | + task = asyncio.ensure_future(async_func()) |
| 63 | + await task |
| 64 | + |
| 65 | + asyncio.run(test()) |
63 | 66 |
|
64 | 67 | spans = self.memory_exporter.get_finished_spans()
|
65 | 68 | self.assertEqual(len(spans), 0)
|
66 | 69 |
|
67 | 70 | @pytest.mark.asyncio
|
68 |
| - async def test_asyncio_ensure_future_with_future(self): |
69 |
| - with self._tracer.start_as_current_span("root") as root: |
| 71 | + def test_asyncio_ensure_future_with_future(self): |
| 72 | + async def test(): |
| 73 | + with self._tracer.start_as_current_span("root") as root: |
| 74 | + future = asyncio.Future() |
| 75 | + future.set_result(1) |
| 76 | + task = asyncio.ensure_future(future) |
| 77 | + await task |
70 | 78 |
|
71 |
| - future = asyncio.Future() |
72 |
| - future.set_result(1) |
73 |
| - task = asyncio.ensure_future(future) |
74 |
| - await task |
| 79 | + asyncio.run(test()) |
75 | 80 |
|
76 | 81 | spans = self.memory_exporter.get_finished_spans()
|
77 | 82 | self.assertEqual(len(spans), 2)
|
78 |
| - self.assertEqual(spans[0].name, "asyncio.future") |
| 83 | + for span in spans: |
| 84 | + if span.name == "root": |
| 85 | + self.assertEqual(span.parent, None) |
| 86 | + if span.name == "asyncio.future": |
| 87 | + self.assertNotEquals(span.parent.trace_id, 0) |
| 88 | + |
79 | 89 | for metric in self.memory_metrics_reader.get_metrics_data().resource_metrics[0].scope_metrics[0].metrics:
|
80 | 90 | if metric.name == ASYNCIO_FUTURES_DURATION:
|
81 | 91 | self.assertEquals(metric.data.data_points[0].count, 1)
|
|
0 commit comments