1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[opentelemetry][callback] support opentelemetry-api 1.13 (#5342) (#5378)

* [opentelemetry][callback] support opentelemetry-api 1.13

* [opentelemetry][callback] changelog fragment

* Update changelogs/fragments/5342-opentelemetry_bug_fix_opentelemetry-api-1.13.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* [opentelemetry-callback] refactor time_ns in a function

* fix linting

* change branch outside of the function

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>

* [opentelemetry]: remove options from suggestion

* Apply suggestions from code review

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
(cherry picked from commit 5732023aa2)

Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>
This commit is contained in:
patchback[bot] 2022-10-18 10:38:22 +02:00 committed by GitHub
parent cb26897b3e
commit eb066335f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 9 deletions

View file

@ -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).

View file

@ -94,13 +94,32 @@ try:
from opentelemetry.sdk.trace.export import ( from opentelemetry.sdk.trace.export import (
BatchSpanProcessor 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: except ImportError as imp_exc:
OTEL_LIBRARY_IMPORT_ERROR = imp_exc OTEL_LIBRARY_IMPORT_ERROR = imp_exc
OTEL_LIBRARY_TIME_NS_ERROR = imp_exc
else: else:
OTEL_LIBRARY_IMPORT_ERROR = None 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: class TaskData:
""" """
Data about an individual task. Data about an individual task.
@ -112,10 +131,7 @@ class TaskData:
self.path = path self.path = path
self.play = play self.play = play
self.host_data = OrderedDict() self.host_data = OrderedDict()
if sys.version_info >= (3, 7): self.start = time_ns()
self.start = time.time_ns()
else:
self.start = _time_ns()
self.action = action self.action = action
self.args = args self.args = args
@ -140,10 +156,7 @@ class HostData:
self.name = name self.name = name
self.status = status self.status = status
self.result = result self.result = result
if sys.version_info >= (3, 7): self.finish = time_ns()
self.finish = time.time_ns()
else:
self.finish = _time_ns()
class OpenTelemetrySource(object): class OpenTelemetrySource(object):