From fec312eb5433fb44e0bda0a241b3bf9ca3b3e6f0 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 19 May 2024 21:57:30 +0200 Subject: [PATCH] [stable-7] fix(opentelemetry): avoid storing inmemory if logs are disabled (#8373) (#8391) fix(opentelemetry): avoid storing inmemory if logs are disabled (#8373) * fix(opentelemetry): avoid storing inmemory if logs are disabled * changelog * fix syntax * refactor * chore * chore * chore * fix (cherry picked from commit d87b9fe0dce577aad2e58f56626a5df50839a884) Co-authored-by: Victor Martinez --- changelogs/fragments/8373-honour-disable-logs.yaml | 3 +++ plugins/callback/opentelemetry.py | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/8373-honour-disable-logs.yaml diff --git a/changelogs/fragments/8373-honour-disable-logs.yaml b/changelogs/fragments/8373-honour-disable-logs.yaml new file mode 100644 index 0000000000..112b10a9f4 --- /dev/null +++ b/changelogs/fragments/8373-honour-disable-logs.yaml @@ -0,0 +1,3 @@ +bugfixes: + - opentelemetry callback plugin - honour the ``disable_logs`` option to avoid storing task results since they are not used regardless (https://github.com/ansible-collections/community.general/pull/8373). + diff --git a/plugins/callback/opentelemetry.py b/plugins/callback/opentelemetry.py index bd34a364c1..47db3d809b 100644 --- a/plugins/callback/opentelemetry.py +++ b/plugins/callback/opentelemetry.py @@ -498,6 +498,12 @@ class CallbackModule(CallbackBase): # See https://github.com/open-telemetry/opentelemetry-specification/issues/740 self.traceparent = self.get_option('traceparent') + def dump_results(self, result): + """ dump the results if disable_logs is not enabled """ + if self.disable_logs: + return "" + return self._dump_results(result._result) + def v2_playbook_on_start(self, playbook): self.ansible_playbook = basename(playbook._file_name) @@ -547,7 +553,7 @@ class CallbackModule(CallbackBase): self.tasks_data, status, result, - self._dump_results(result._result) + self.dump_results(result) ) def v2_runner_on_ok(self, result): @@ -555,7 +561,7 @@ class CallbackModule(CallbackBase): self.tasks_data, 'ok', result, - self._dump_results(result._result) + self.dump_results(result) ) def v2_runner_on_skipped(self, result): @@ -563,7 +569,7 @@ class CallbackModule(CallbackBase): self.tasks_data, 'skipped', result, - self._dump_results(result._result) + self.dump_results(result) ) def v2_playbook_on_include(self, included_file):