SIGN IN SIGN UP

fix(sdk): use sys.orig_argv for process.command to handle python -m invocations (#5083)

* fix(sdk): use sys.orig_argv for process.command to handle python -m invocations

ProcessResourceDetector populated process.command, process.command_line,
and process.command_args from sys.argv. For applications launched via
`python -m <module>`, the interpreter rewrites sys.argv[0] to the
resolved module path, so the ``-m <module>`` portion of the original
invocation is lost and the detector emits misleading telemetry.

Python 3.10+ exposes sys.orig_argv which preserves the original
arguments received by the interpreter. Since the SDK already requires
Python >= 3.10, switch to sys.orig_argv (with a getattr fallback for
safety). This also aligns with the OTel semantic conventions that
reference /proc/<pid>/cmdline for these attributes.

Fixes #4518

Signed-off-by: Ali <alliasgher123@gmail.com>

* 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>

* test: remove redundant sys.argv patch from test_process_detector

Signed-off-by: Ali <alliasgher123@gmail.com>

* test: drop superfluous sys.argv mock in python-m test

The detector reads only sys.orig_argv, so patching sys.argv had no
effect on the test's outcome. Keep only the sys.orig_argv patch.

Signed-off-by: Ali <alliasgher123@gmail.com>

---------

Signed-off-by: Ali <alliasgher123@gmail.com>
Co-authored-by: Mike Goldsmith <goldsmith.mike@gmail.com>
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
A
Ali Asghar committed
44d891143a4609c39f1bb682018ab3e68d957ef7
Parent: 849cfac
Committed by GitHub <noreply@github.com> on 4/22/2026, 2:38:34 PM