Skip to content

Commit cea3d98

Browse files
authored
[feat] add top-level CLI spans to pull request dashboard scripts (#506)
Follow the OpenTelemetry semantic conventions for CLI programs so each script run and each spawned command shows in the workflow trace. - Wrap each entry point in an INTERNAL span named by the script file, with process.executable.name, process.pid, process.exit.code and error.type; any non-zero exit code sets the status to ERROR - Add CLIENT spans around the commands process_queue_batch starts; the child gets this span as its TRACEPARENT parent - Run drain_queue jobs in a copy of the current context - Record no command arguments, exception messages or stack traces - Keep export off by default; spans are no-ops without the SDK - Document span names and attributes in the README
1 parent 280c06f commit cea3d98

14 files changed

Lines changed: 394 additions & 35 deletions

‎.github/scripts/pull-request-dashboard/dashboard.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,5 +1053,5 @@ def main() -> int:
10531053

10541054

10551055
if __name__ == "__main__":
1056-
with telemetry_session():
1056+
with telemetry_session(name="dashboard.py"):
10571057
sys.exit(main())

‎.github/scripts/pull-request-dashboard/delivery.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,5 +382,5 @@ def main() -> int:
382382

383383

384384
if __name__ == "__main__":
385-
with telemetry_session():
385+
with telemetry_session(name="delivery.py"):
386386
sys.exit(main())

‎.github/scripts/pull-request-dashboard/drain_queue.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import argparse
44
import concurrent.futures
5+
import contextvars
6+
import functools
57
import json
68
import os
79
import subprocess
@@ -166,7 +168,10 @@ def return_claims(claims: list[Claim]) -> None:
166168
])
167169
break
168170
jobs += 1
169-
future = executor.submit(process_job, repository_claims, jobs)
171+
# Run each job in a copy of this thread's context, so spans and
172+
# propagation in process_job keep the run's parent context.
173+
in_context = functools.partial(contextvars.copy_context().run, process_job)
174+
future = executor.submit(in_context, repository_claims, jobs)
170175
active[future] = repository
171176

172177
if not active:
@@ -522,5 +527,5 @@ def main() -> int:
522527

523528

524529
if __name__ == "__main__":
525-
with telemetry_session():
530+
with telemetry_session(name="drain_queue.py"):
526531
raise SystemExit(main())

‎.github/scripts/pull-request-dashboard/enqueue_dashboard.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,5 @@ def main() -> None:
106106

107107

108108
if __name__ == "__main__":
109-
with telemetry_session():
109+
with telemetry_session(name="enqueue_dashboard.py"):
110110
main()

‎.github/scripts/pull-request-dashboard/process_queue_batch.py‎

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from execution_process import run_monitored, subprocess_options
2222
from queue_worker_client import QueueWorkerClient, acknowledge_results
2323
import state_branch as state_branch_git
24-
from telemetry import child_environment
24+
from telemetry import child_environment, child_process_span
2525
from telemetry import session as telemetry_session
2626

2727
SCRIPT_DIR = Path(__file__).resolve().parent
@@ -705,19 +705,23 @@ def _run(
705705
env: dict[str, str],
706706
print_stdout: bool = True,
707707
) -> subprocess.CompletedProcess[str]:
708-
env = child_environment(env)
709-
if self.lease_check is None:
710-
result = self.run(
711-
command,
712-
cwd=self.repository_root,
713-
env=env,
714-
text=True,
715-
encoding="utf-8",
716-
capture_output=True,
717-
**subprocess_options(),
718-
)
719-
else:
720-
result = run_monitored(command, self.lease_check, cwd=self.repository_root, env=env)
708+
with child_process_span(command) as record_exit:
709+
env = child_environment(env)
710+
if self.lease_check is None:
711+
result = self.run(
712+
command,
713+
cwd=self.repository_root,
714+
env=env,
715+
text=True,
716+
encoding="utf-8",
717+
capture_output=True,
718+
**subprocess_options(),
719+
)
720+
else:
721+
result = run_monitored(
722+
command, self.lease_check, cwd=self.repository_root, env=env
723+
)
724+
record_exit(result.returncode)
721725
if result.stdout and print_stdout:
722726
print(result.stdout, end="")
723727
if result.stderr:
@@ -833,5 +837,5 @@ def main() -> int:
833837

834838

835839
if __name__ == "__main__":
836-
with telemetry_session():
840+
with telemetry_session(name="process_queue_batch.py"):
837841
sys.exit(main())

‎.github/scripts/pull-request-dashboard/promote_rollout.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,5 @@ def main() -> None:
7575

7676

7777
if __name__ == "__main__":
78-
with telemetry_session():
78+
with telemetry_session(name="promote_rollout.py"):
7979
main()

‎.github/scripts/pull-request-dashboard/publish_dashboard.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,5 +322,5 @@ def main() -> int:
322322

323323

324324
if __name__ == "__main__":
325-
with telemetry_session():
325+
with telemetry_session(name="publish_dashboard.py"):
326326
sys.exit(main())

‎.github/scripts/pull-request-dashboard/refresh_author_nudges.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,5 +306,5 @@ def main() -> int:
306306

307307

308308
if __name__ == "__main__":
309-
with telemetry_session():
309+
with telemetry_session(name="refresh_author_nudges.py"):
310310
raise SystemExit(main())

‎.github/scripts/pull-request-dashboard/report_rate_limits.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@ def main() -> None:
6161

6262

6363
if __name__ == "__main__":
64-
with telemetry_session():
64+
with telemetry_session(name="report_rate_limits.py"):
6565
main()

‎.github/scripts/pull-request-dashboard/state.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1454,5 +1454,5 @@ def main() -> int:
14541454

14551455

14561456
if __name__ == "__main__":
1457-
with telemetry_session():
1457+
with telemetry_session(name="state.py"):
14581458
sys.exit(main())

0 commit comments

Comments
 (0)