From ce6d0a749e28faf2e02271dc914dbaf884b046df Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Sat, 4 Dec 2021 18:00:07 +0000 Subject: [PATCH] opentelemetry: honour ignore errors (#3837) * opentelemetry: honour the ignore_errors * fix-encoding-pragma * Add changelog fragment * opentelemetry: ignore produces unset span status --- ...37-opentelemetry_plugin-honour_ignore_errors.yaml | 2 ++ plugins/callback/opentelemetry.py | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/3837-opentelemetry_plugin-honour_ignore_errors.yaml diff --git a/changelogs/fragments/3837-opentelemetry_plugin-honour_ignore_errors.yaml b/changelogs/fragments/3837-opentelemetry_plugin-honour_ignore_errors.yaml new file mode 100644 index 0000000000..2f33f45eec --- /dev/null +++ b/changelogs/fragments/3837-opentelemetry_plugin-honour_ignore_errors.yaml @@ -0,0 +1,2 @@ +bugfixes: + - opentelemetry_plugin - honour ``ignore_errors`` when a task has failed instead of reporting an error (https://github.com/ansible-collections/community.general/pull/3837). diff --git a/plugins/callback/opentelemetry.py b/plugins/callback/opentelemetry.py index c1856d9c01..444c09c423 100644 --- a/plugins/callback/opentelemetry.py +++ b/plugins/callback/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) @@ -267,6 +268,8 @@ class OpenTelemetrySource(object): elif host_data.status == 'skipped': message = res['skip_reason'] if 'skip_reason' in res else 'skipped' status = Status(status_code=StatusCode.UNSET) + elif host_data.status == 'ignored': + status = Status(status_code=StatusCode.UNSET) span.set_status(status) if isinstance(task_data.args, dict) and "gather_facts" not in task_data.action: @@ -462,10 +465,15 @@ class CallbackModule(CallbackBase): ) def v2_runner_on_failed(self, result, ignore_errors=False): - self.errors += 1 + if ignore_errors: + status = 'ignored' + else: + status = 'failed' + self.errors += 1 + self.opentelemetry.finish_task( self.tasks_data, - 'failed', + status, result )