diff --git a/changelogs/fragments/9482-opentelemetry-python-37.yml b/changelogs/fragments/9482-opentelemetry-python-37.yml new file mode 100644 index 0000000000..3cc291265f --- /dev/null +++ b/changelogs/fragments/9482-opentelemetry-python-37.yml @@ -0,0 +1,2 @@ +minor_changes: + - opentelemetry callback plugin - remove code handling Python versions prior to 3.7 (https://github.com/ansible-collections/community.general/pull/9482). diff --git a/plugins/callback/opentelemetry.py b/plugins/callback/opentelemetry.py index 6a641f5c3c..b99b34933b 100644 --- a/plugins/callback/opentelemetry.py +++ b/plugins/callback/opentelemetry.py @@ -137,9 +137,8 @@ import getpass import json import os import socket -import sys -import time import uuid +from time import time_ns from collections import OrderedDict from os.path import basename @@ -165,14 +164,6 @@ try: from opentelemetry.sdk.trace.export.in_memory_span_exporter import ( InMemorySpanExporter ) - # Support for opentelemetry-api <= 1.12 - try: - from opentelemetry.util._time import _time_ns - except ImportError as imp_exc: - OTEL_LIBRARY_TIME_NS_ERROR = imp_exc - else: - OTEL_LIBRARY_TIME_NS_ERROR = None - except ImportError as imp_exc: OTEL_LIBRARY_IMPORT_ERROR = imp_exc OTEL_LIBRARY_TIME_NS_ERROR = imp_exc @@ -180,16 +171,6 @@ else: OTEL_LIBRARY_IMPORT_ERROR = None -if sys.version_info >= (3, 7): - time_ns = time.time_ns -elif not OTEL_LIBRARY_TIME_NS_ERROR: - time_ns = _time_ns -else: - def time_ns(): - # Support versions older than 3.7 with opentelemetry-api > 1.12 - return int(time.time() * 1e9) - - class TaskData: """ Data about an individual task.