1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-05-06 10:05:54 +00:00

Start opentelemetry spans on host start instead of task start

v2_playbook_on_task_start does not have the host information, so spans
would always start at the same time for every host in that task, even if
they started at different times, like when hosts > forks with strategy
host_pinned. This also hides the duration of the task for that host.

This change uses the newer v2_runner_on_start callback and adds the acutal
host start time to the span. The change is backwards compatible with ansible
versions that do not have v2_runner_on_start and makes no assumptions around
the ordering of v2_runner_on_start and v2_playbook_on_task_start.
This commit is contained in:
Alexander Freiherr von Buddenbrock 2026-01-16 22:14:44 +01:00
parent 4b67afc2b0
commit c473cc5a7d
No known key found for this signature in database
2 changed files with 44 additions and 4 deletions

View file

@ -50,6 +50,27 @@ class TestOpentelemetry(unittest.TestCase):
self.assertEqual(task_data.action, "myaction")
self.assertEqual(task_data.args, {})
def test_run_task_with_host(self):
tasks_data = OrderedDict()
self.opentelemetry.start_task(tasks_data, False, "myplay", self.mock_task, self.mock_host)
task_data = tasks_data["myuuid"]
self.assertEqual(task_data.uuid, "myuuid")
self.assertEqual(task_data.name, "mytask")
self.assertEqual(task_data.path, "/mypath")
self.assertEqual(task_data.play, "myplay")
self.assertEqual(task_data.action, "myaction")
self.assertEqual(task_data.args, {})
host_data = task_data.host_data["myhost_uuid"]
self.assertEqual(host_data.uuid, "myhost_uuid")
self.assertEqual(host_data.name, "myhost")
self.assertIsNotNone(host_data.start)
self.opentelemetry.finish_task(tasks_data, "ok", self.my_task_result, "")
self.assertEqual(host_data.status, "ok")
def test_finish_task_with_a_host_match(self):
tasks_data = OrderedDict()
tasks_data["myuuid"] = self.my_task