Skip to content

Commit 72470e6

Browse files
committed
nit: drop sys.orig_argv fallback and use PR number in changelog
Two review nits from MikeGoldsmith: - sys.orig_argv has been available since Python 3.10; the SDK now requires 3.10+ so the getattr fallback is dead code. Use sys.orig_argv directly and update the comment. - CHANGELOG entries should reference the PR number, not the issue number. Signed-off-by: Ali <alliasgher123@gmail.com>
1 parent abaf5b9 commit 72470e6

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,13 @@ def detect(self) -> "Resource":
380380
_process_pid = os.getpid()
381381
_process_executable_name = sys.executable
382382
_process_executable_path = os.path.dirname(_process_executable_name)
383-
# Prefer sys.orig_argv (Python 3.10+), which preserves the original
384-
# arguments received by the interpreter. This correctly captures
385-
# ``python -m <module>`` invocations where sys.argv is rewritten to
386-
# the resolved module path and the ``-m <module>`` information is
387-
# lost. sys.orig_argv also aligns with /proc/<pid>/cmdline, which
388-
# the OTel semantic conventions reference for these attributes.
389-
_process_argv = list(getattr(sys, "orig_argv", sys.argv))
383+
# Use sys.orig_argv, which preserves the original arguments received
384+
# by the interpreter. This correctly captures ``python -m <module>``
385+
# invocations where sys.argv is rewritten to the resolved module path
386+
# and the ``-m <module>`` information is lost. sys.orig_argv also
387+
# aligns with /proc/<pid>/cmdline, which the OTel semantic
388+
# conventions reference for these attributes.
389+
_process_argv = list(sys.orig_argv)
390390
_process_command = _process_argv[0] if _process_argv else ""
391391
_process_command_line = " ".join(_process_argv)
392392
_process_command_args = _process_argv

opentelemetry-sdk/tests/resources/test_resources.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,15 +611,15 @@ def test_process_detector(self):
611611
os.path.dirname(sys.executable),
612612
)
613613
self.assertEqual(
614-
aggregated_resource.attributes[PROCESS_COMMAND], sys.argv[0]
614+
aggregated_resource.attributes[PROCESS_COMMAND], sys.orig_argv[0]
615615
)
616616
self.assertEqual(
617617
aggregated_resource.attributes[PROCESS_COMMAND_LINE],
618-
" ".join(sys.argv),
618+
" ".join(sys.orig_argv),
619619
)
620620
self.assertEqual(
621621
aggregated_resource.attributes[PROCESS_COMMAND_ARGS],
622-
tuple(sys.argv),
622+
tuple(sys.orig_argv),
623623
)
624624

625625
@patch("sys.argv", ["/path/to/myapp/__main__.py"])

0 commit comments

Comments
 (0)