Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[opentelemetry][callback] support opentelemetry-api 1.13 #5342

Merged
@@ -0,0 +1,2 @@
bugfixes:
- opentelemetry callback plugin - support opentelemetry-api 1.13.0 that removed support for ``_time_ns`` (https://github.com/ansible-collections/community.general/pull/5342).
31 changes: 22 additions & 9 deletions plugins/callback/opentelemetry.py
Expand Up @@ -110,13 +110,32 @@
from opentelemetry.sdk.trace.export import (
BatchSpanProcessor
)
from opentelemetry.util._time import _time_ns

# 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
v1v marked this conversation as resolved.
Show resolved Hide resolved
OTEL_LIBRARY_TIME_NS_ERROR = imp_exc
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.
Expand All @@ -128,10 +147,7 @@ def __init__(self, uuid, name, path, play, action, args):
self.path = path
self.play = play
self.host_data = OrderedDict()
if sys.version_info >= (3, 7):
self.start = time.time_ns()
else:
self.start = _time_ns()
self.start = time_ns()
self.action = action
self.args = args

Expand All @@ -156,10 +172,7 @@ def __init__(self, uuid, name, status, result):
self.name = name
self.status = status
self.result = result
if sys.version_info >= (3, 7):
self.finish = time.time_ns()
else:
self.finish = _time_ns()
self.finish = time_ns()


class OpenTelemetrySource(object):
Expand Down