diff --git a/changelogs/fragments/4623-opentelemetry_bug_fix_include_tasks.yml b/changelogs/fragments/4623-opentelemetry_bug_fix_include_tasks.yml new file mode 100644 index 0000000000..a18ba62ef5 --- /dev/null +++ b/changelogs/fragments/4623-opentelemetry_bug_fix_include_tasks.yml @@ -0,0 +1,2 @@ +bugfixes: + - opentelemetry callback plugin - fix warning for the include_tasks (https://github.com/ansible-collections/community.general/pull/4623). diff --git a/plugins/callback/opentelemetry.py b/plugins/callback/opentelemetry.py index 8ef2ae3f4d..9da5179399 100644 --- a/plugins/callback/opentelemetry.py +++ b/plugins/callback/opentelemetry.py @@ -197,7 +197,7 @@ class OpenTelemetrySource(object): task = tasks_data[task_uuid] - if self.ansible_version is None and result._task_fields['args'].get('_ansible_version'): + if self.ansible_version is None and hasattr(result, '_task_fields') and result._task_fields['args'].get('_ansible_version'): self.ansible_version = result._task_fields['args'].get('_ansible_version') task.add_host(HostData(host_uuid, host_name, status, result)) diff --git a/tests/unit/plugins/callback/test_opentelemetry.py b/tests/unit/plugins/callback/test_opentelemetry.py index 74d647252b..41700fbcb7 100644 --- a/tests/unit/plugins/callback/test_opentelemetry.py +++ b/tests/unit/plugins/callback/test_opentelemetry.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # (C) 2021, Victor Martinez # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) @@ -91,6 +92,21 @@ class TestOpentelemetry(unittest.TestCase): self.assertEqual(host_data.uuid, 'include') self.assertEqual(host_data.name, 'include') self.assertEqual(host_data.status, 'ok') + self.assertEqual(self.opentelemetry.ansible_version, None) + + def test_finish_task_include_with_ansible_version(self): + task_fields = {'args': {'_ansible_version': '1.2.3'}} + result = TaskResult(host=None, task=self.mock_task, return_data={}, task_fields=task_fields) + tasks_data = OrderedDict() + tasks_data['myuuid'] = self.my_task + + self.opentelemetry.finish_task( + tasks_data, + 'ok', + result + ) + + self.assertEqual(self.opentelemetry.ansible_version, '1.2.3') def test_get_error_message(self): test_cases = (