Skip to content

Commit

Permalink
[stable-7] fix(opentelemetry): avoid storing inmemory if logs are dis…
Browse files Browse the repository at this point in the history
…abled (#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 d87b9fe)

Co-authored-by: Victor Martinez <[email protected]>
  • Loading branch information
felixfontein and v1v authored May 19, 2024
1 parent f7b1393 commit fec312e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/8373-honour-disable-logs.yaml
Original file line number Diff line number Diff line change
@@ -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).

12 changes: 9 additions & 3 deletions plugins/callback/opentelemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,12 @@ def set_options(self, task_keys=None, var_options=None, direct=None):
# 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)

Expand Down Expand Up @@ -547,23 +553,23 @@ def v2_runner_on_failed(self, result, ignore_errors=False):
self.tasks_data,
status,
result,
self._dump_results(result._result)
self.dump_results(result)
)

def v2_runner_on_ok(self, result):
self.opentelemetry.finish_task(
self.tasks_data,
'ok',
result,
self._dump_results(result._result)
self.dump_results(result)
)

def v2_runner_on_skipped(self, result):
self.opentelemetry.finish_task(
self.tasks_data,
'skipped',
result,
self._dump_results(result._result)
self.dump_results(result)
)

def v2_playbook_on_include(self, included_file):
Expand Down

0 comments on commit fec312e

Please sign in to comment.