Skip to content

Commit 39d0a53

Browse files
committed
modified lint results
1 parent 05e6a74 commit 39d0a53

13 files changed

+106
-98
lines changed

instrumentation/opentelemetry-instrumentation-asyncio/src/opentelemetry/instrumentation/asyncio/__init__.py

+37-27
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def func():
103103

104104
from wrapt import wrap_function_wrapper as _wrap
105105

106+
# pylint: disable=no-name-in-module
106107
from opentelemetry.instrumentation.asyncio.metrics import (
107108
ASYNCIO_COROUTINE_ACTIVE,
108109
ASYNCIO_COROUTINE_CANCELLED,
@@ -215,10 +216,10 @@ def _instrument(self, **kwargs):
215216

216217
def _uninstrument(self, **kwargs):
217218
for method in self.methods_with_coroutine:
218-
self.uninstrument_method_with_coroutine(method)
219-
self.uninstrument_gather()
220-
self.uninstrument_to_thread()
221-
self.uninstrument_taskgroup_create_task()
219+
uninstrument_method_with_coroutine(method)
220+
uninstrument_gather()
221+
uninstrument_to_thread()
222+
uninstrument_taskgroup_create_task()
222223

223224
def instrument_method_with_coroutine(self, method_name):
224225
"""
@@ -245,24 +246,16 @@ def wrap_coro_or_future(method, instance, args, kwargs):
245246

246247
_wrap(asyncio, method_name, wrap_coro_or_future)
247248

248-
def uninstrument_method_with_coroutine(self, method_name):
249-
"""
250-
Uninstrument specified asyncio method.
251-
"""
252-
unwrap(asyncio, method_name)
253-
254249
def instrument_gather(self):
255250
def wrap_coros_or_futures(method, instance, args, kwargs):
256251
if args and len(args) > 0:
257252
# Check if it's a coroutine or future and wrap it
258253
wrapped_args = tuple(self.trace_item(item) for item in args)
259254
return method(*wrapped_args, **kwargs)
255+
return method(*args, **kwargs)
260256

261257
_wrap(asyncio, "gather", wrap_coros_or_futures)
262258

263-
def uninstrument_gather(self):
264-
unwrap(asyncio, "gather")
265-
266259
def instrument_to_thread(self):
267260
# to_thread was added in Python 3.9
268261
if sys.version_info < (3, 9):
@@ -276,15 +269,10 @@ def wrap_to_thread(method, instance, args, kwargs):
276269
wrapped_args = (wrapped_first_arg,) + args[1:]
277270

278271
return method(*wrapped_args, **kwargs)
272+
return method(*args, **kwargs)
279273

280274
_wrap(asyncio, "to_thread", wrap_to_thread)
281275

282-
def uninstrument_to_thread(self):
283-
# to_thread was added in Python 3.9
284-
if sys.version_info < (3, 9):
285-
return
286-
unwrap(asyncio, "to_thread")
287-
288276
def instrument_taskgroup_create_task(self):
289277
# TaskGroup.create_task was added in Python 3.11
290278
if sys.version_info < (3, 11):
@@ -296,14 +284,11 @@ def wrap_taskgroup_create_task(method, instance, args, kwargs):
296284
wrapped_coro = self.trace_coroutine(coro)
297285
wrapped_args = (wrapped_coro,) + args[1:]
298286
return method(*wrapped_args, **kwargs)
287+
return method(*args, **kwargs)
299288

300-
_wrap(asyncio.TaskGroup, "create_task", wrap_taskgroup_create_task)
301-
302-
def uninstrument_taskgroup_create_task(self):
303-
# TaskGroup.create_task was added in Python 3.11
304-
if sys.version_info < (3, 11):
305-
return
306-
unwrap(asyncio.TaskGroup, "create_task")
289+
_wrap(
290+
asyncio.TaskGroup, "create_task", wrap_taskgroup_create_task # pylint: disable=no-member
291+
)
307292

308293
def trace_to_thread(self, func):
309294
"""Trace a function."""
@@ -343,7 +328,7 @@ def trace_item(self, coro_or_future):
343328
return coro_or_future
344329
if asyncio.iscoroutine(coro_or_future):
345330
return self.trace_coroutine(coro_or_future)
346-
elif futures.isfuture(coro_or_future):
331+
if futures.isfuture(coro_or_future):
347332
return self.trace_future(coro_or_future)
348333
return coro_or_future
349334

@@ -527,3 +512,28 @@ def create_to_thread_metric(self):
527512
description="Number of asyncio function finished",
528513
unit="1",
529514
)
515+
516+
517+
def uninstrument_taskgroup_create_task():
518+
# TaskGroup.create_task was added in Python 3.11
519+
if sys.version_info < (3, 11):
520+
return
521+
unwrap(asyncio.TaskGroup, "create_task") # pylint: disable=no-member
522+
523+
524+
def uninstrument_to_thread():
525+
# to_thread was added in Python 3.9
526+
if sys.version_info < (3, 9):
527+
return
528+
unwrap(asyncio, "to_thread")
529+
530+
531+
def uninstrument_gather():
532+
unwrap(asyncio, "gather")
533+
534+
535+
def uninstrument_method_with_coroutine(method_name):
536+
"""
537+
Uninstrument specified asyncio method.
538+
"""
539+
unwrap(asyncio, method_name)

instrumentation/opentelemetry-instrumentation-asyncio/src/opentelemetry/instrumentation/asyncio/utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
import os
1515

16+
# pylint: disable=no-name-in-module
1617
from opentelemetry.instrumentation.asyncio.environment_variables import (
1718
OTEL_PYTHON_ASYNCIO_COROUTINE_NAMES_TO_TRACE,
1819
OTEL_PYTHON_ASYNCIO_FUTURE_TRACE_ENABLED,

instrumentation/opentelemetry-instrumentation-asyncio/tests/test_asyncio_cancellation.py

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import asyncio
1515
from unittest.mock import patch
1616

17+
# pylint: disable=no-name-in-module
1718
from opentelemetry.instrumentation.asyncio import (
1819
ASYNCIO_COROUTINE_ACTIVE,
1920
ASYNCIO_COROUTINE_CANCELLED,

instrumentation/opentelemetry-instrumentation-asyncio/tests/test_asyncio_create_task.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import asyncio
1515
from unittest.mock import patch
1616

17+
# pylint: disable=no-name-in-module
1718
from opentelemetry.instrumentation.asyncio import AsyncioInstrumentor
1819
from opentelemetry.instrumentation.asyncio.environment_variables import (
1920
OTEL_PYTHON_ASYNCIO_COROUTINE_NAMES_TO_TRACE,
@@ -46,8 +47,6 @@ async def async_func():
4647

4748
asyncio.run(async_func())
4849
spans = self.memory_exporter.get_finished_spans()
49-
"""
50-
OTEL_PYTHON_ASYNCIO_COROUTINE_NAMES_TO_TRACE: "sleep"
51-
"""
50+
5251
self.assertEqual(len(spans), 1)
5352
self.assertEqual(spans[0].name, "asyncio.coro-sleep")

instrumentation/opentelemetry-instrumentation-asyncio/tests/test_asyncio_ensure_future.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import pytest
1818

19+
# pylint: disable=no-name-in-module
1920
from opentelemetry.instrumentation.asyncio import (
2021
ASYNCIO_FUTURES_ACTIVE,
2122
ASYNCIO_FUTURES_CANCELLED,
@@ -92,7 +93,7 @@ async def test():
9293
if span.name == "root":
9394
self.assertEqual(span.parent, None)
9495
if span.name == "asyncio.future":
95-
self.assertNotEquals(span.parent.trace_id, 0)
96+
self.assertNotEqual(span.parent.trace_id, 0)
9697

9798
for metric in (
9899
self.memory_metrics_reader.get_metrics_data()
@@ -101,7 +102,7 @@ async def test():
101102
.metrics
102103
):
103104
if metric.name == ASYNCIO_FUTURES_DURATION:
104-
self.assertEquals(metric.data.data_points[0].count, 1)
105+
self.assertEqual(metric.data.data_points[0].count, 1)
105106
elif metric.name == ASYNCIO_FUTURES_ACTIVE:
106107
self.assertEqual(metric.data.data_points[0].value, 0)
107108
elif metric.name == ASYNCIO_FUTURES_CREATED:

instrumentation/opentelemetry-instrumentation-asyncio/tests/test_asyncio_gather.py

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import asyncio
1515
from unittest.mock import patch
1616

17+
# pylint: disable=no-name-in-module
1718
from opentelemetry.instrumentation.asyncio import AsyncioInstrumentor
1819
from opentelemetry.instrumentation.asyncio.environment_variables import (
1920
OTEL_PYTHON_ASYNCIO_COROUTINE_NAMES_TO_TRACE,

instrumentation/opentelemetry-instrumentation-asyncio/tests/test_asyncio_integration.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import asyncio
1515
from unittest.mock import patch
1616

17+
# pylint: disable=no-name-in-module
1718
from opentelemetry.instrumentation.asyncio import AsyncioInstrumentor
1819
from opentelemetry.instrumentation.asyncio.environment_variables import (
1920
OTEL_PYTHON_ASYNCIO_COROUTINE_NAMES_TO_TRACE,
@@ -31,9 +32,6 @@ def setUp(self):
3132
__name__,
3233
)
3334

34-
def tearDown(self):
35-
super().tearDown()
36-
3735
@patch.dict(
3836
"os.environ", {OTEL_PYTHON_ASYNCIO_COROUTINE_NAMES_TO_TRACE: "sleep"}
3937
)

instrumentation/opentelemetry-instrumentation-asyncio/tests/test_asyncio_run_coroutine_threadsafe.py

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from concurrent.futures import ThreadPoolExecutor
1717
from unittest.mock import patch
1818

19+
# pylint: disable=no-name-in-module
1920
from opentelemetry.instrumentation.asyncio import AsyncioInstrumentor
2021
from opentelemetry.instrumentation.asyncio.environment_variables import (
2122
OTEL_PYTHON_ASYNCIO_COROUTINE_NAMES_TO_TRACE,

instrumentation/opentelemetry-instrumentation-asyncio/tests/test_asyncio_taskgroup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616
from unittest.mock import patch
1717

18+
# pylint: disable=no-name-in-module
1819
from opentelemetry.instrumentation.asyncio import AsyncioInstrumentor
1920
from opentelemetry.instrumentation.asyncio.environment_variables import (
2021
OTEL_PYTHON_ASYNCIO_COROUTINE_NAMES_TO_TRACE,
@@ -51,7 +52,7 @@ def test_task_group_create_task(self):
5152
return
5253

5354
async def main():
54-
async with asyncio.TaskGroup() as tg:
55+
async with asyncio.TaskGroup() as tg: # pylint: disable=no-member
5556
for _ in range(10):
5657
tg.create_task(async_func())
5758

instrumentation/opentelemetry-instrumentation-asyncio/tests/test_asyncio_to_thread.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616
from unittest.mock import patch
1717

18+
# pylint: disable=no-name-in-module
1819
from opentelemetry.instrumentation.asyncio import AsyncioInstrumentor
1920
from opentelemetry.instrumentation.asyncio.environment_variables import (
2021
OTEL_PYTHON_ASYNCIO_TO_THREAD_FUNCTION_NAMES_TO_TRACE,
@@ -63,7 +64,7 @@ async def to_thread():
6364
.metrics
6465
):
6566
if metric.name == "asyncio.to_thread.duration":
66-
self.assertEquals(metric.data.data_points[0].count, 1)
67+
self.assertEqual(metric.data.data_points[0].count, 1)
6768
elif metric.name == "asyncio.to_thread.active":
6869
self.assertEqual(metric.data.data_points[0].value, 0)
6970
elif metric.name == "asyncio.to_thread.created":

instrumentation/opentelemetry-instrumentation-asyncio/tests/test_asyncio_utils.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@
1414
from unittest import TestCase
1515
from unittest.mock import patch
1616

17+
# pylint: disable=no-name-in-module
1718
from opentelemetry.instrumentation.asyncio.environment_variables import (
1819
OTEL_PYTHON_ASYNCIO_COROUTINE_NAMES_TO_TRACE,
1920
OTEL_PYTHON_ASYNCIO_FUTURE_TRACE_ENABLED,
2021
)
22+
from opentelemetry.instrumentation.asyncio.utils import (
23+
get_coros_to_trace,
24+
get_future_trace_enabled,
25+
)
2126

2227

2328
class TestAsyncioToThread(TestCase):
@@ -28,10 +33,6 @@ class TestAsyncioToThread(TestCase):
2833
},
2934
)
3035
def test_separator(self):
31-
from opentelemetry.instrumentation.asyncio.utils import (
32-
get_coros_to_trace,
33-
)
34-
3536
self.assertEqual(
3637
get_coros_to_trace(), {"test1", "test2", "test3", "test4"}
3738
)
@@ -40,8 +41,4 @@ def test_separator(self):
4041
"os.environ", {OTEL_PYTHON_ASYNCIO_FUTURE_TRACE_ENABLED: "true"}
4142
)
4243
def test_future_trace_enabled(self):
43-
from opentelemetry.instrumentation.asyncio.utils import (
44-
get_future_trace_enabled,
45-
)
46-
4744
self.assertEqual(get_future_trace_enabled(), True)

instrumentation/opentelemetry-instrumentation-asyncio/tests/test_asyncio_wait.py

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616
from unittest.mock import patch
1717

18+
# pylint: disable=no-name-in-module
1819
from opentelemetry.instrumentation.asyncio import AsyncioInstrumentor
1920
from opentelemetry.instrumentation.asyncio.environment_variables import (
2021
OTEL_PYTHON_ASYNCIO_COROUTINE_NAMES_TO_TRACE,

0 commit comments

Comments
 (0)